depth_view.cpp
Go to the documentation of this file.
00001 /*
00002   A viewer for Kinect Depth images
00003   Copyright (c) 2011 Michael Ferguson.  All right reserved.
00004 
00005   Redistribution and use in source and binary forms, with or without
00006   modification, are permitted provided that the following conditions are met:
00007  * Redistributions of source code must retain the above copyright
00008         notice, this list of conditions and the following disclaimer.
00009  * Redistributions in binary form must reproduce the above copyright
00010         notice, this list of conditions and the following disclaimer in the
00011         documentation and/or other materials provided with the distribution.
00012  * Neither the name of the copyright holders nor the names of its
00013         contributors may be used to endorse or promote products derived
00014         from this software without specific prior written permission.
00015 
00016   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019   DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00020   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00021   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00022   OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00023   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00024   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00025   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00036 #include <ros/ros.h>
00037 #include <cv_bridge/cv_bridge.h>
00038 #include <opencv/cv.h>
00039 #include <opencv/highgui.h>
00040 #include <sensor_msgs/Image.h>
00041 
00042 namespace {
00043 const std::string WINDOW_NAME = "Depth View";
00044 double min_range_;
00045 double max_range_;
00046 
00047 void depthCb(const sensor_msgs::ImageConstPtr& image) {
00048   // convert to cv image
00049   cv_bridge::CvImagePtr bridge;
00050   try
00051   {
00052     bridge = cv_bridge::toCvCopy(image, "32FC1");
00053   }
00054   catch (cv_bridge::Exception& e)
00055   {
00056     ROS_ERROR("Failed to transform depth image.");
00057     return;
00058   }
00059 
00060   // convert to something visible
00061   cv::Mat img(bridge->image.rows, bridge->image.cols, CV_8UC1);
00062   for(int i = 0; i < bridge->image.rows; i++)
00063   {
00064     float* Di = bridge->image.ptr<float>(i);
00065     char* Ii = img.ptr<char>(i);
00066     for(int j = 0; j < bridge->image.cols; j++)
00067     {
00068       Ii[j] = (char) (255*((Di[j]-min_range_)/(max_range_-min_range_)));
00069     }
00070   }
00071 
00072   // display
00073   cv::imshow(WINDOW_NAME, img);
00074 }
00075 }
00076 
00077 int main(int argc, char* argv[]) {
00078   ros::init( argc, argv, "depth_viewer" );
00079   ros::NodeHandle n;
00080 
00081   ros::NodeHandle nh("~");
00082   nh.param("min_range", min_range_, 0.5);
00083   nh.param("max_range", max_range_, 10.0);
00084 
00085   cv::namedWindow(WINDOW_NAME);
00086   cv::startWindowThread();
00087 
00088   ros::Subscriber sub = n.subscribe("/camera/depth/image", 3, &depthCb);
00089   ros::spin();
00090 }
 All Classes Namespaces Files Functions Variables Typedefs Defines


omnicamera
Author(s): Tomas Petricek / petrito1@cmp.felk.cvut.cz
autogenerated on Tue Dec 10 2013 14:26:53