Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <ros/ros.h>
00023 #include <cv_bridge/CvBridge.h>
00024 #include <image_transport/image_transport.h>
00025
00026
00027 #include <sensor_msgs/Image.h>
00028
00029
00030 #include <opencv/cv.h>
00031 #include <opencv/highgui.h>
00032
00033 #include <cob_vision_utils/VisionUtils.h>
00034 #include <sstream>
00035
00036
00037
00038 class CobTofCameraViewerNode
00039 {
00040 private:
00041 ros::NodeHandle m_NodeHandle;
00042
00043 image_transport::ImageTransport image_transport_;
00044 image_transport::Subscriber xyz_image_subscriber_;
00045 image_transport::Subscriber grey_image_subscriber_;
00046
00047 sensor_msgs::CvBridge cv_bridge_0_;
00048 sensor_msgs::CvBridge cv_bridge_1_;
00049
00050 IplImage* xyz_image_32F3_;
00051 cv::Mat xyz_mat_8U3_;
00052 IplImage* grey_image_32F1_;
00053 cv::Mat grey_mat_8U3_;
00054
00055 int grey_image_counter_;
00056
00057 public:
00060 CobTofCameraViewerNode(const ros::NodeHandle& node_handle)
00061 : m_NodeHandle(node_handle),
00062 image_transport_(node_handle),
00063 xyz_image_32F3_(0),
00064 xyz_mat_8U3_(cv::Mat()),
00065 grey_image_32F1_(0),
00066 grey_mat_8U3_(cv::Mat()),
00067 grey_image_counter_(0)
00068 {
00070 }
00071
00073 ~CobTofCameraViewerNode()
00074 {
00078
00079 if(cvGetWindowHandle("z data"))cvDestroyWindow("z data");
00080 if(cvGetWindowHandle("grey data"))cvDestroyWindow("grey data");
00081 }
00082
00085 bool init()
00086 {
00088 cvStartWindowThread();
00089 cv::namedWindow("z data");
00090 cv::namedWindow("grey data");
00091
00092 xyz_image_subscriber_ = image_transport_.subscribe("image_xyz", 1, &CobTofCameraViewerNode::xyzImageCallback, this);
00093 grey_image_subscriber_ = image_transport_.subscribe("image_grey", 1, &CobTofCameraViewerNode::greyImageCallback, this);
00094
00095 return true;
00096 }
00097
00101 void greyImageCallback(const sensor_msgs::ImageConstPtr& grey_image_msg)
00102 {
00105 ROS_INFO("Grey Image Callback");
00106
00107 try
00108 {
00109 grey_image_32F1_ = cv_bridge_0_.imgMsgToCv(grey_image_msg, "passthrough");
00110
00111 cv::Mat grey_mat_32F1 = grey_image_32F1_;
00112 ipa_Utils::ConvertToShowImage(grey_mat_32F1, grey_mat_8U3_, 1, 0, 800);
00113 cv::imshow("grey data", grey_mat_8U3_);
00114 int c = cvWaitKey(500);
00115 std::cout << c << std::endl;
00116 if (c=='s' || c==536871027)
00117 {
00118 std::stringstream ss;
00119 char counterBuffer [50];
00120 sprintf(counterBuffer, "%04d", grey_image_counter_);
00121 ss << "greyImage8U3_";
00122 ss << counterBuffer;
00123 ss << ".bmp";
00124 cv::imwrite(ss.str().c_str(),grey_mat_8U3_);
00125 std::cout << "[tof_camera_viewer] Image " << grey_image_counter_ << " saved." << std::endl;
00126 grey_image_counter_++;
00127 }
00128 }
00129 catch (sensor_msgs::CvBridgeException& e)
00130 {
00131 ROS_ERROR("[tof_camera_viewer] Could not convert from '%s' to '32FC1'.", grey_image_msg->encoding.c_str());
00132 }
00133 ROS_INFO("Image Processed");
00134 }
00135
00139 void xyzImageCallback(const sensor_msgs::ImageConstPtr& xyz_image_msg)
00140 {
00143
00144 try
00145 {
00146 xyz_image_32F3_ = cv_bridge_1_.imgMsgToCv(xyz_image_msg, "passthrough");
00147
00148 cv::Mat xyz_mat_32F3 = xyz_image_32F3_;
00149 ipa_Utils::ConvertToShowImage(xyz_mat_32F3, xyz_mat_8U3_, 3);
00150 cv::imshow("z data", xyz_mat_8U3_);
00151 }
00152 catch (sensor_msgs::CvBridgeException& e)
00153 {
00154 ROS_ERROR("[tof_camera_viewer] Could not convert from '%s' to '32FC1'.", xyz_image_msg->encoding.c_str());
00155 }
00156
00157 }
00158 };
00159
00160
00161
00162 int main(int argc, char** argv)
00163 {
00165 ros::init(argc, argv, "tof_camera_viewer");
00166
00168 ros::NodeHandle nh;
00169
00171 CobTofCameraViewerNode camera_viewer_node(nh);
00172
00173
00175 if (!camera_viewer_node.init()) return 0;
00176
00177 ros::spin();
00178
00179 return 0;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207