26 #include <cv_bridge/CvBridge.h> 30 #include <sensor_msgs/Image.h> 31 #include <sensor_msgs/CameraInfo.h> 33 #include <sensor_msgs/SetCameraInfo.h> 89 : node_handle_(node_handle),
93 left_color_image_8U3_(cv::Mat()),
94 right_color_image_8U3_(cv::Mat()),
95 xyz_tof_image_32F3_(cv::Mat()),
96 grey_tof_image_32F1_(cv::Mat()),
97 image_transport_(node_handle)
104 ROS_INFO(
"[all_cameras] Shutting down cameras");
105 if (left_color_camera_)
107 ROS_INFO(
"[all_cameras] Shutting down left color camera (1)");
108 left_color_camera_->Close();
110 if (right_color_camera_)
112 ROS_INFO(
"[all_cameras] Shutting down right color camera (0)");
113 right_color_camera_->Close();
117 ROS_INFO(
"[all_cameras] Shutting down tof camera (0)");
118 tof_camera_->Close();
125 if (loadParameters() ==
false)
127 ROS_ERROR(
"[all_cameras] Could not read parameters from launch file");
133 ROS_WARN(
"[all_cameras] Initialization of left camera (1) failed");
139 ROS_WARN(
"[all_cameras] Opening left color camera (1) failed");
142 if (left_color_camera_)
145 int camera_index = 1;
148 left_color_camera_->GetProperty(&cameraProperty);
151 cv::Size color_image_size(color_sensor_width, color_sensor_height);
155 color_sensor_toolbox->Init(config_directory_, left_color_camera_->GetCameraType(), camera_index, color_image_size);
157 cv::Mat
d = color_sensor_toolbox->GetDistortionParameters(left_color_camera_intrinsic_type_, left_color_camera_intrinsic_id_);
159 left_color_camera_info_msg_.header.frame_id =
"head_color_camera_l_link";
160 left_color_camera_info_msg_.D[0] = d.at<
double>(0, 0);
161 left_color_camera_info_msg_.D[1] = d.at<
double>(0, 1);
162 left_color_camera_info_msg_.D[2] = d.at<
double>(0, 2);
163 left_color_camera_info_msg_.D[3] = d.at<
double>(0, 3);
164 left_color_camera_info_msg_.D[4] = 0;
166 cv::Mat k = color_sensor_toolbox->GetIntrinsicMatrix(left_color_camera_intrinsic_type_, left_color_camera_intrinsic_id_);
167 left_color_camera_info_msg_.K[0] = k.at<
double>(0, 0);
168 left_color_camera_info_msg_.K[1] = k.at<
double>(0, 1);
169 left_color_camera_info_msg_.K[2] = k.at<
double>(0, 2);
170 left_color_camera_info_msg_.K[3] = k.at<
double>(1, 0);
171 left_color_camera_info_msg_.K[4] = k.at<
double>(1, 1);
172 left_color_camera_info_msg_.K[5] = k.at<
double>(1, 2);
173 left_color_camera_info_msg_.K[6] = k.at<
double>(2, 0);
174 left_color_camera_info_msg_.K[7] = k.at<
double>(2, 1);
175 left_color_camera_info_msg_.K[8] = k.at<
double>(2, 2);
177 left_color_camera_info_msg_.width = color_sensor_width;
178 left_color_camera_info_msg_.height = color_sensor_height;
183 ROS_WARN(
"[all_cameras] Initialization of right camera (0) failed");
189 ROS_WARN(
"[all_cameras] Opening right color camera (0) failed");
192 if (right_color_camera_)
194 int camera_index = 0;
198 right_color_camera_->GetProperty(&cameraProperty);
201 cv::Size color_image_size(color_sensor_width, color_sensor_height);
205 color_sensor_toolbox->Init(config_directory_, left_color_camera_->GetCameraType(), camera_index, color_image_size);
207 cv::Mat
d = color_sensor_toolbox->GetDistortionParameters(right_color_camera_intrinsic_type_, right_color_camera_intrinsic_id_);
209 right_color_camera_info_msg_.header.frame_id =
"head_color_camera_r_link";
210 right_color_camera_info_msg_.D[0] = d.at<
double>(0, 0);
211 right_color_camera_info_msg_.D[1] = d.at<
double>(0, 1);
212 right_color_camera_info_msg_.D[2] = d.at<
double>(0, 2);
213 right_color_camera_info_msg_.D[3] = d.at<
double>(0, 3);
214 right_color_camera_info_msg_.D[4] = 0;
216 cv::Mat k = color_sensor_toolbox->GetIntrinsicMatrix(right_color_camera_intrinsic_type_, right_color_camera_intrinsic_id_);
217 right_color_camera_info_msg_.K[0] = k.at<
double>(0, 0);
218 right_color_camera_info_msg_.K[1] = k.at<
double>(0, 1);
219 right_color_camera_info_msg_.K[2] = k.at<
double>(0, 2);
220 right_color_camera_info_msg_.K[3] = k.at<
double>(1, 0);
221 right_color_camera_info_msg_.K[4] = k.at<
double>(1, 1);
222 right_color_camera_info_msg_.K[5] = k.at<
double>(1, 2);
223 right_color_camera_info_msg_.K[6] = k.at<
double>(2, 0);
224 right_color_camera_info_msg_.K[7] = k.at<
double>(2, 1);
225 right_color_camera_info_msg_.K[8] = k.at<
double>(2, 2);
227 right_color_camera_info_msg_.width = color_sensor_width;
228 right_color_camera_info_msg_.height = color_sensor_height;
233 ROS_WARN(
"[all_cameras] Initialization of tof camera (0) failed");
239 ROS_WARN(
"[all_cameras] Opening tof camera (0) failed");
244 int camera_index = 0;
248 tof_camera_->GetProperty(&cameraProperty);
251 cv::Size rangeImageSize(range_sensor_width, range_sensor_height);
255 tof_sensor_toolbox->Init(config_directory_, tof_camera_->GetCameraType(), camera_index, rangeImageSize);
257 cv::Mat intrinsic_mat = tof_sensor_toolbox->GetIntrinsicMatrix(tof_camera_intrinsic_type_, tof_camera_intrinsic_id_);
258 cv::Mat distortion_map_X = tof_sensor_toolbox->GetDistortionMapX(tof_camera_intrinsic_type_, tof_camera_intrinsic_id_);
259 cv::Mat distortion_map_Y = tof_sensor_toolbox->GetDistortionMapY(tof_camera_intrinsic_type_, tof_camera_intrinsic_id_);
260 tof_camera_->SetIntrinsics(intrinsic_mat, distortion_map_X, distortion_map_Y);
262 cv::Mat
d = tof_sensor_toolbox->GetDistortionParameters(tof_camera_intrinsic_type_, tof_camera_intrinsic_id_);
264 tof_camera_info_msg_.header.frame_id =
"head_tof_link";
265 tof_camera_info_msg_.D[0] = d.at<
double>(0, 0);
266 tof_camera_info_msg_.D[1] = d.at<
double>(0, 1);
267 tof_camera_info_msg_.D[2] = d.at<
double>(0, 2);
268 tof_camera_info_msg_.D[3] = d.at<
double>(0, 3);
269 tof_camera_info_msg_.D[4] = 0;
271 cv::Mat k = tof_sensor_toolbox->GetIntrinsicMatrix(tof_camera_intrinsic_type_, tof_camera_intrinsic_id_);
272 tof_camera_info_msg_.K[0] = k.at<
double>(0, 0);
273 tof_camera_info_msg_.K[1] = k.at<
double>(0, 1);
274 tof_camera_info_msg_.K[2] = k.at<
double>(0, 2);
275 tof_camera_info_msg_.K[3] = k.at<
double>(1, 0);
276 tof_camera_info_msg_.K[4] = k.at<
double>(1, 1);
277 tof_camera_info_msg_.K[5] = k.at<
double>(1, 2);
278 tof_camera_info_msg_.K[6] = k.at<
double>(2, 0);
279 tof_camera_info_msg_.K[7] = k.at<
double>(2, 1);
280 tof_camera_info_msg_.K[8] = k.at<
double>(2, 2);
282 tof_camera_info_msg_.width = range_sensor_width;
283 tof_camera_info_msg_.height = range_sensor_height;
287 if (left_color_camera_)
290 left_color_image_publisher_ = image_transport_.
advertiseCamera(left_color_camera_ns_ +
"/left/image_color", 1);
293 if (right_color_camera_)
296 right_color_image_publisher_ = image_transport_.
advertiseCamera(right_color_camera_ns_ +
"/right/image_color", 1);
301 grey_tof_image_publisher_ = image_transport_.
advertiseCamera(tof_camera_ns_ +
"/image_grey", 1);
302 xyz_tof_image_publisher_ = image_transport_.
advertiseCamera(tof_camera_ns_ +
"/image_xyz", 1);
314 sensor_msgs::SetCameraInfo::Response& rsp)
320 rsp.status_message =
"[all_cameras] Setting camera parameters through ROS not implemented";
330 while(node_handle_.
ok())
333 sensor_msgs::Image right_color_image_msg;
334 sensor_msgs::Image left_color_image_msg;
335 sensor_msgs::Image xyz_tof_image_msg;
336 sensor_msgs::Image grey_tof_image_msg;
339 sensor_msgs::CameraInfo right_color_image_info;
340 sensor_msgs::CameraInfo left_color_image_info;
341 sensor_msgs::CameraInfo tof_image_info;
346 if (right_color_camera_)
352 ROS_ERROR(
"[all_cameras] Right color image acquisition failed");
358 IplImage img = right_color_image_8U3_;
359 right_color_image_msg = *(sensor_msgs::CvBridge::cvToImgMsg(&img,
"bgr8"));
361 catch (sensor_msgs::CvBridgeException error)
363 ROS_ERROR(
"[all_cameras] Could not convert right IplImage to ROS message");
366 right_color_image_msg.header.stamp = now;
367 right_color_image_msg.encoding =
"bgr8";
368 right_color_image_msg.header.frame_id =
"head_color_camera_r_link";
370 right_color_image_info = right_color_camera_info_msg_;
371 right_color_image_info.width = right_color_image_8U3_.cols;
372 right_color_image_info.height = right_color_image_8U3_.rows;
373 right_color_image_info.header.stamp = now;
374 right_color_image_info.header.frame_id =
"head_color_camera_r_link";
376 right_color_image_publisher_.
publish(right_color_image_msg, right_color_image_info);
380 if (left_color_camera_)
387 ROS_ERROR(
"[all_cameras] Left color image acquisition failed");
393 IplImage img = left_color_image_8U3_;
394 left_color_image_msg = *(sensor_msgs::CvBridge::cvToImgMsg(&img,
"bgr8"));
396 catch (sensor_msgs::CvBridgeException error)
398 ROS_ERROR(
"[all_cameras] Could not convert left IplImage to ROS message");
401 left_color_image_msg.header.stamp = now;
402 left_color_image_msg.encoding =
"bgr8";
403 left_color_image_msg.header.frame_id =
"head_color_camera_l_link";
405 left_color_image_info = left_color_camera_info_msg_;
406 left_color_image_info.width = left_color_image_8U3_.cols;
407 left_color_image_info.height = left_color_image_8U3_.rows;
408 left_color_image_info.header.stamp = now;
409 left_color_image_info.header.frame_id =
"head_color_camera_l_link";
411 left_color_image_publisher_.
publish(left_color_image_msg, left_color_image_info);
418 if(tof_camera_->AcquireImages(0, &grey_tof_image_32F1_, &xyz_tof_image_32F3_,
false,
false, ipa_CameraSensors::INTENSITY_32F1) &
ipa_Utils::RET_FAILED)
420 ROS_ERROR(
"[all_cameras] Tof image acquisition failed");
421 tof_camera_->Close();
428 IplImage grey_img = grey_tof_image_32F1_;
429 IplImage xyz_img = xyz_tof_image_32F3_;
430 xyz_tof_image_msg = *(sensor_msgs::CvBridge::cvToImgMsg(&xyz_img,
"passthrough"));
431 grey_tof_image_msg = *(sensor_msgs::CvBridge::cvToImgMsg(&grey_img,
"passthrough"));
433 catch (sensor_msgs::CvBridgeException error)
435 ROS_ERROR(
"[all_cameras] Could not convert tof IplImage to ROS message");
439 xyz_tof_image_msg.header.stamp = now;
440 xyz_tof_image_msg.header.frame_id =
"head_tof_link";
441 grey_tof_image_msg.header.stamp = now;
442 grey_tof_image_msg.header.frame_id =
"head_tof_link";
444 tof_image_info = tof_camera_info_msg_;
445 tof_image_info.width = grey_tof_image_32F1_.cols;
446 tof_image_info.height = grey_tof_image_32F1_.rows;
447 tof_image_info.header.stamp = now;
448 tof_image_info.header.frame_id =
"head_tof_link";
450 grey_tof_image_publisher_.
publish(grey_tof_image_msg, tof_image_info);
451 xyz_tof_image_publisher_.
publish(xyz_tof_image_msg, tof_image_info);
462 std::string tmp_string =
"NULL";
465 if (node_handle_.
getParam(
"all_cameras/configuration_files", config_directory_) ==
false)
467 ROS_ERROR(
"Path to xml configuration file not specified");
471 ROS_INFO(
"Configuration directory: %s", config_directory_.c_str());
474 if (node_handle_.
getParam(
"all_cameras/color_camera_type", tmp_string) ==
false)
476 ROS_ERROR(
"[all_cameras] Color camera type not specified");
479 if (tmp_string ==
"CAM_AVTPIKE")
484 left_color_camera_ns_ =
"pike_145C";
485 right_color_camera_ns_ =
"pike_145C";
487 else if (tmp_string ==
"CAM_VIRTUAL")
491 left_color_camera_ns_ =
"pike_145C";
492 right_color_camera_ns_ =
"pike_145C";
494 else if (tmp_string ==
"CAM_PROSILICA")
ROS_ERROR(
"[all_cameras] Color camera type not CAM_PROSILICA not yet implemented");
497 std::string str =
"[all_cameras] Camera type '" + tmp_string +
"' unknown, try 'CAM_AVTPIKE' or 'CAM_PROSILICA'";
502 ROS_INFO(
"Color camera type: %s", tmp_string.c_str());
505 if (node_handle_.
getParam(
"all_cameras/tof_camera_type", tmp_string) ==
false)
507 ROS_ERROR(
"[all_cameras] tof camera type not specified");
510 if (tmp_string ==
"CAM_SWISSRANGER")
513 tof_camera_ns_ =
"sr4000";
515 else if (tmp_string ==
"CAM_VIRTUAL")
518 tof_camera_ns_ =
"sr4000";
522 std::string str =
"[all_cameras] Camera type '" + tmp_string +
"' unknown, try 'CAM_SWISSRANGER'";
526 ROS_INFO(
"Tof camera type: %s", tmp_string.c_str());
530 if (node_handle_.
getParam(
"all_cameras/left_color_camera_intrinsic_type", tmp_string) ==
false)
532 ROS_ERROR(
"[all_cameras] Intrinsic camera type for left color camera not specified");
535 if (tmp_string ==
"CAM_AVTPIKE")
539 else if (tmp_string ==
"CAM_PROSILICA")
543 else if (tmp_string ==
"CAM_SWISSRANGER")
547 else if (tmp_string ==
"CAM_VIRTUALRANGE")
551 else if (tmp_string ==
"CAM_VIRTUALCOLOR")
557 std::string str =
"[all_cameras] Camera type '" + tmp_string +
"' for intrinsics of left camera unknown, try 'CAM_AVTPIKE','CAM_PROSILICA' or 'CAM_SWISSRANGER'";
561 if (node_handle_.
getParam(
"all_cameras/left_color_camera_intrinsic_id", left_color_camera_intrinsic_id_) ==
false)
563 ROS_ERROR(
"[all_cameras] Intrinsic camera id for left color camera not specified");
568 ROS_INFO(
"Intrinsic for left color camera: %s_%d", tmp_string.c_str(), left_color_camera_intrinsic_id_);
572 if (node_handle_.
getParam(
"all_cameras/right_color_camera_intrinsic_type", tmp_string) ==
false)
574 ROS_ERROR(
"[all_cameras] Intrinsic camera type for right color camera not specified");
577 if (tmp_string ==
"CAM_AVTPIKE")
581 else if (tmp_string ==
"CAM_PROSILICA")
585 else if (tmp_string ==
"CAM_SWISSRANGER")
589 else if (tmp_string ==
"CAM_VIRTUALRANGE")
593 else if (tmp_string ==
"CAM_VIRTUALCOLOR")
599 std::string str =
"[all_cameras] Camera type '" + tmp_string +
"' for intrinsics of right camera unknown, try 'CAM_AVTPIKE','CAM_PROSILICA' or 'CAM_SWISSRANGER'";
603 if (node_handle_.
getParam(
"all_cameras/right_color_camera_intrinsic_id", right_color_camera_intrinsic_id_) ==
false)
605 ROS_ERROR(
"[all_cameras] Intrinsic camera id for right color camera not specified");
609 ROS_INFO(
"Intrinsic for right color camera: %s_%d", tmp_string.c_str(), right_color_camera_intrinsic_id_);
613 if (node_handle_.
getParam(
"all_cameras/tof_camera_intrinsic_type", tmp_string) ==
false)
615 ROS_ERROR(
"[all_cameras] Intrinsic camera type for tof camera not specified");
618 if (tmp_string ==
"CAM_AVTPIKE")
622 else if (tmp_string ==
"CAM_PROSILICA")
626 else if (tmp_string ==
"CAM_SWISSRANGER")
630 else if (tmp_string ==
"CAM_VIRTUALRANGE")
634 else if (tmp_string ==
"CAM_VIRTUALCOLOR")
640 std::string str =
"[all_cameras] Camera type '" + tmp_string +
"' for intrinsics unknown, try 'CAM_AVTPIKE','CAM_PROSILICA' or 'CAM_SWISSRANGER'";
644 if (node_handle_.
getParam(
"all_cameras/tof_camera_intrinsic_id", tof_camera_intrinsic_id_) ==
false)
646 ROS_ERROR(
"[all_cameras] Intrinsic camera id for tof camera not specified");
650 ROS_INFO(
"Intrinsic for tof camera: %s_%d", tmp_string.c_str(), tof_camera_intrinsic_id_);
658 int main(
int argc,
char** argv)
670 if (camera_node.
init() ==
false)
672 ROS_ERROR(
"[all_cameras] Node initialization FAILED. Terminating");
677 ROS_INFO(
"[all_cameras] Node initialization OK. Enter spinning");
cv::Mat xyz_tof_image_32F3_
image_transport::ImageTransport image_transport_
OpenCV image holding the amplitude values of the point cloud.
ros::NodeHandle node_handle_
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
void spin()
Callback function for image requests on topic 'request_image'.
t_cameraResolution cameraResolution
image_transport::CameraPublisher right_color_image_publisher_
Publishes grey image data.
std::string tof_camera_ns_
Namespace name of left color camera.
boost::shared_ptr< AbstractColorCamera > AbstractColorCameraPtr
bool setCameraInfo(sensor_msgs::SetCameraInfo::Request &req, sensor_msgs::SetCameraInfo::Response &rsp)
ros::ServiceServer tof_camera_info_service_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::string right_color_camera_ns_
Namespace name of left color camera.
AbstractRangeImagingSensorPtr tof_camera_
Time-of-flight camera instance.
__DLL_LIBCAMERASENSORS__ AbstractRangeImagingSensorPtr CreateRangeImagingSensor_VirtualCam()
ipa_CameraSensors::t_cameraType tof_camera_intrinsic_type_
Instrinsic matrix type of tof camera.
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
__DLL_LIBCAMERASENSORS__ CameraSensorToolboxPtr CreateCameraSensorToolbox()
int tof_camera_intrinsic_id_
Instrinsic matrix id of tof camera.
ros::ServiceServer left_color_camera_info_service_
image_transport::CameraPublisher left_color_image_publisher_
Publishes grey image data.
sensor_msgs::CameraInfo right_color_camera_info_msg_
ROS camera information message (e.g. holding intrinsic parameters)
CameraPublisher advertiseCamera(const std::string &base_topic, uint32_t queue_size, bool latch=false)
ipa_CameraSensors::t_cameraType right_color_camera_intrinsic_type_
Instrinsic matrix type of right color camera.
cv::Mat right_color_image_8U3_
color image of right camera
AbstractColorCameraPtr right_color_camera_
Color camera instance.
std::string left_color_camera_ns_
Namespace name of left color camera.
cv::Mat grey_tof_image_32F1_
OpenCV image holding the point cloud from tof sensor.
int left_color_camera_intrinsic_id_
Instrinsic matrix id of left color camera.
__DLL_LIBCAMERASENSORS__ AbstractColorCameraPtr CreateColorCamera_VirtualCam()
boost::shared_ptr< AbstractRangeImagingSensor > AbstractRangeImagingSensorPtr
std::string config_directory_
Directory of the configuration files.
sensor_msgs::CameraInfo tof_camera_info_msg_
ROS camera information message (e.g. holding intrinsic parameters)
cv::Mat left_color_image_8U3_
color image of left camera
image_transport::CameraPublisher grey_tof_image_publisher_
Publishes grey image data.
bool init()
Opens the camera sensor.
image_transport::CameraPublisher xyz_tof_image_publisher_
Publishes xyz image data.
int right_color_camera_intrinsic_id_
Instrinsic matrix id of right color camera.
t_cameraPropertyID propertyID
bool getParam(const std::string &key, std::string &s) const
ipa_CameraSensors::t_cameraType left_color_camera_intrinsic_type_
Instrinsic matrix type of left color camera.
AbstractColorCameraPtr left_color_camera_
Color camera instance.
__DLL_LIBCAMERASENSORS__ AbstractRangeImagingSensorPtr CreateRangeImagingSensor_Swissranger()
int main(int argc, char **argv)
ros::ServiceServer right_color_camera_info_service_
ROSCPP_DECL void spinOnce()
CobAllCamerasNode(const ros::NodeHandle &node_handle)
__DLL_LIBCAMERASENSORS__ AbstractColorCameraPtr CreateColorCamera_AVTPikeCam()
sensor_msgs::CameraInfo left_color_camera_info_msg_
ROS camera information message (e.g. holding intrinsic parameters)