Go to the documentation of this file.00001 #include <iostream>
00002 #include <getopt.h>
00003 #include <linux/input.h>
00004
00005 #include <ros/ros.h>
00006 #include <sensor_msgs/Image.h>
00007
00008 #include <cv_bridge/cv_bridge.h>
00009 #include <sensor_msgs/image_encodings.h>
00010
00011 #include <message_filters/subscriber.h>
00012 #include <message_filters/time_synchronizer.h>
00013
00014 #include <cv_bridge/cv_bridge.h>
00015 #include <sensor_msgs/image_encodings.h>
00016 #include <opencv2/imgproc/imgproc.hpp>
00017 #include <opencv2/highgui/highgui.hpp>
00018
00019 #include <orsens/Obstacles.h>
00020 #include <orsens/Way.h>
00021
00022 using namespace cv;
00023 using namespace sensor_msgs;
00024
00025 Mat disp, left, right;
00026 orsens::Obstacles obs;
00027 orsens::Way way;
00028
00029 Mat colorize_disp(Mat disp_mono)
00030 {
00031 Mat disp_color(disp_mono.rows, disp_mono.cols, CV_8UC3);
00032 Mat hsv(disp_mono.rows, disp_mono.cols, CV_32FC3);
00033
00034 disp_color = Scalar::all(0);
00035 hsv = Scalar::all(0);
00036
00037 for (int y=0; y<disp_mono.rows; y++)
00038 for (int x=0; x<disp_mono.cols; x++)
00039 {
00040 uchar d = disp_mono.at<uchar>(y,x);
00041 if (d==0)
00042 continue;
00043
00044 hsv.at<Vec3f>(y,x) = Vec3f(255-d, 1.0,1.0);
00045 }
00046
00047 cvtColor(hsv, disp_color, CV_HSV2BGR);
00048
00049 return disp_color;
00050 }
00051
00052 void disp_cb(sensor_msgs::Image disp_img)
00053 {
00054 cv_bridge::CvImagePtr disp_ptr;
00055 try
00056 {
00057 disp_ptr = cv_bridge::toCvCopy(disp_img, sensor_msgs::image_encodings::TYPE_8UC1);
00058 }
00059 catch (cv_bridge::Exception& e)
00060 {
00061 ROS_ERROR("cv_bridge exception: %s", e.what());
00062 return;
00063 }
00064
00065 disp = disp_ptr->image.clone();
00066
00067 Mat disp_color = colorize_disp(disp);
00068
00069 imshow("disp", disp);
00070 imshow("disp colored", disp_color);
00071
00072 waitKey(5);
00073 }
00074
00075 void disp_filtered_cb(sensor_msgs::Image disp_filtered_img)
00076 {
00077 cv_bridge::CvImagePtr disp_ptr;
00078 try
00079 {
00080 disp_ptr = cv_bridge::toCvCopy(disp_filtered_img, sensor_msgs::image_encodings::TYPE_8UC1);
00081 }
00082 catch (cv_bridge::Exception& e)
00083 {
00084 ROS_ERROR("cv_bridge exception: %s", e.what());
00085 return;
00086 }
00087
00088 disp = disp_ptr->image.clone();
00089
00090 Mat disp_color = colorize_disp(disp);
00091
00092 imshow("disp_filtered", disp);
00093 imshow("disp_filtered colored", disp_color);
00094
00095 waitKey(5);
00096 }
00097
00098 void left_cb(sensor_msgs::Image left_img)
00099 {
00100 cv_bridge::CvImagePtr left_ptr;
00101 try
00102 {
00103 left_ptr = cv_bridge::toCvCopy(left_img, sensor_msgs::image_encodings::TYPE_8UC3);
00104 }
00105 catch (cv_bridge::Exception& e)
00106 {
00107 ROS_ERROR("cv_bridge exception: %s", e.what());
00108 return;
00109 }
00110
00111 left = left_ptr->image.clone();
00112
00113 imshow("left", left);
00114
00115 waitKey(5);
00116 }
00117
00118 int main(int argc, char *argv[])
00119 {
00120
00121 ros::init (argc, argv, "orview");
00122 ros::NodeHandle nh;
00123
00124 ros::Subscriber sub_disp = nh.subscribe("/orsens/disparity", 1, disp_cb);
00125 ros::Subscriber sub_disp_filtered = nh.subscribe("/orsens/disparity_filtered", 1, disp_filtered_cb);
00126 ros::Subscriber sub_left = nh.subscribe("/orsens/left", 1, left_cb);
00127
00128 namedWindow("disp", 1);
00129 namedWindow("left", 1);
00130
00131
00132 ros::spin ();
00133
00134 return 0;
00135 }
00136