00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <cstdio>
00033 #include <vector>
00034 #include <opencv/cv.h>
00035 #include <opencv/highgui.h>
00036 #include <ros/node_handle.h>
00037 #include <deprecated_msgs/ImageArray.h>
00038
00039
00040
00041 extern "C" {
00046 typedef struct AVPicture {
00047 uint8_t *data[4];
00048 int linesize[4];
00049 } AVPicture;
00050
00051
00052
00053
00054 int img_convert(AVPicture *dst, int dst_pix_fmt,
00055 const AVPicture *src, int src_pix_fmt,
00056 int src_width, int src_height){
00057 return(0);
00058
00059 }
00060 }
00061
00062
00063 using namespace std;
00064 using namespace deprecated_msgs;
00065
00066 class SwissRangerViewer
00067 {
00068 public:
00069 ros::NodeHandle node_;
00070 ros::Subscriber sr_sub_ ;
00071
00072
00073 char key;
00074 int imgnum;
00075 IplImage *sr_img1, *sr_img2, *sr_img3;
00076
00077
00078 SwissRangerViewer ()
00079 {
00080 cvNamedWindow ("sr4k - distance", CV_WINDOW_AUTOSIZE);
00081 cvNamedWindow ("sr4k - amplitude", CV_WINDOW_AUTOSIZE);
00082 cvNamedWindow ("sr4k - confidence", CV_WINDOW_AUTOSIZE);
00083 sr_sub_ = node_.subscribe<deprecated_msgs::ImageArray>
00084 ("/swissranger_test/images_sr", 10, &SwissRangerViewer::image_sr_cb, this);
00085 sr_img1 = cvCreateImage (cvSize (1, 1), IPL_DEPTH_16U, 1);
00086 sr_img2 = cvCreateImage (cvSize (1, 1), IPL_DEPTH_16U, 1);
00087 sr_img3 = cvCreateImage (cvSize (1, 1), IPL_DEPTH_16U, 1);
00088 imgnum = 0;
00089 }
00090
00091 void image_sr_cb(const deprecated_msgs::ImageArray::ConstPtr &images_sr)
00092 {
00093 cvReleaseImage (&sr_img1);
00094 cvReleaseImage (&sr_img2);
00095 cvReleaseImage (&sr_img3);
00096
00097 fprintf (stderr, "Received %d images of size:", images_sr->get_images_size ());
00098 for (unsigned int j = 0; j < images_sr->get_images_size (); j++)
00099 {
00100 fprintf (stderr, " %dx%d and type %s,", images_sr->images[j].width, images_sr->images[j].height, images_sr->images[j].colorspace.c_str ());
00101 if (images_sr->images[j].width == 0 || images_sr->images[j].height == 0)
00102 return;
00103 }
00104 fprintf (stderr, "\n");
00105
00106 sr_img1 = cvCreateImage (cvSize (images_sr->images[0].width, images_sr->images[0].height), IPL_DEPTH_16U, 1);
00107 sr_img2 = cvCreateImage (cvSize (images_sr->images[1].width, images_sr->images[1].height), IPL_DEPTH_16U, 1);
00109 sr_img3 = cvCreateImage (cvSize (images_sr->images[2].width, images_sr->images[2].height), IPL_DEPTH_16U, 1);
00110
00111 memcpy (sr_img1->imageData, &(images_sr->images[0].data[0]), sr_img1->imageSize);
00112 memcpy (sr_img2->imageData, &(images_sr->images[1].data[0]), sr_img2->imageSize);
00113 memcpy (sr_img3->imageData, &(images_sr->images[2].data[0]), sr_img3->imageSize);
00114
00115 cvShowImage ("sr4k - distance", sr_img1);
00116
00117 IplImage* sr_img2_rot = cvCloneImage (sr_img2);
00118 sr_img2 = cvCreateImage (cvGetSize (sr_img2_rot), IPL_DEPTH_8U, 3);
00119 if (sr_img2_rot->depth == IPL_DEPTH_16U)
00120 cvConvertImage (sr_img2_rot, sr_img2, CV_CVTIMG_SWAP_RB);
00121
00122 IplImage *sr_img2_a = cvCreateImage (cvGetSize (sr_img2_rot), IPL_DEPTH_8U, 1);
00123 cvCvtColor (sr_img2, sr_img2_a, CV_RGB2GRAY);
00124
00125 IplImage *sr_img2_rot_hist = cvCloneImage (sr_img2_a);
00126 cvEqualizeHist (sr_img2_a, sr_img2_rot_hist);
00127
00128 cvReleaseImage (&sr_img2);
00129
00130 sr_img2 = cvCreateImage (cvSize (sr_img2_rot_hist->width << 1, sr_img2_rot_hist->height << 1), IPL_DEPTH_8U, 1);
00131 cvResize (sr_img2_rot_hist, sr_img2, CV_INTER_NN);
00132 cvShowImage ("sr4k - amplitude", sr_img2);
00133
00134 cvReleaseImage (&sr_img2_rot_hist);
00135 cvReleaseImage (&sr_img2_rot);
00136
00137 cvShowImage ("sr4k - confidence", sr_img3);
00138 cvWaitKey (20);
00139 }
00140
00141 };
00142
00143 int
00144 main (int argc, char **argv)
00145 {
00146 ros::init (argc, argv, "swissranger_viewer");
00147
00148 SwissRangerViewer n;
00149 ros::spin ();
00150
00151 return (0);
00152 }