Hi everybody,
so the solution is to take the extract_images file from the package image_view, and to modify it :
just modify the
bgr8
and
mono8
to
sensor_msgs::image_encodings::TYPE_32FC1
Don't forget to add at the top :
#include <sensor_msgs/image_encodings.h>
Last but not least add in your manifest
<depend package="cv_bridge"/>
The results will be, as in the original file, jpg files. However, don't be frightened if they look black, because values are given in meter (for depth_registered/image).
Here is the whole code :
// modified version for depth extraction
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
#include <opencv2/highgui/highgui.hpp>
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <boost/thread.hpp>
#include <boost/format.hpp>
class ExtractImages
{
private:
image_transport::Subscriber sub_;
sensor_msgs::ImageConstPtr last_msg_;
boost::mutex image_mutex_;
std::string window_name_;
boost::format filename_format_;
int count_;
double _time;
double sec_per_frame_;
#if defined(_VIDEO)
CvVideoWriter* video_writer;
#endif //_VIDEO
public:
ExtractImages(const ros::NodeHandle& nh, const std::string& transport)
: filename_format_(""), count_(0), _time(ros::Time::now().toSec())
{
std::string topic = nh.resolveName("image");
ros::NodeHandle local_nh("~");
std::string format_string;
local_nh.param("filename_format", format_string, std::string("frame%04i.jpg"));
filename_format_.parse(format_string);
local_nh.param("sec_per_frame", sec_per_frame_, 0.1);
image_transport::ImageTransport it(nh);
sub_ = it.subscribe(topic, 1, &ExtractImages::image_cb, this, transport);
#if defined(_VIDEO)
video_writer = 0;
#endif
ROS_INFO("Initialized sec per frame to %f", sec_per_frame_);
}
~ExtractImages()
{
}
void image_cb(const sensor_msgs::ImageConstPtr& msg)
{
boost::lock_guard<boost::mutex> guard(image_mutex_);
// Hang on to message pointer for sake of mouse_cb
last_msg_ = msg;
// May want to view raw bayer data
// NB: This is hacky, but should be OK since we have ...
(more)