ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to extract depth data from rosbags(contains depth and RGB data) as picture frames

asked 2014-12-13 14:32:22 -0600

shravan gravatar image

updated 2014-12-16 12:08:04 -0600

I have a Bagfile containing Raw depth and RGB data. I converted the RGB data into images using the tutorial http://wiki.ros.org/rosbag/Tutorials/... But when I used the same for converting raw depth to images, I get an error stating " cannot convert 32FC1 to RGB8". This is my launch file:

<launch>
 <node pkg="rosbag" type="play" name="rosbag" args="-d 2 $(find image_view)/test.bag"/>
 <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
   <remap from="image" to="/camera/depth_registered/image_rect"/>
 </node>

</launch>

I went through Google for various suggestions given to do the same but I being a beginner find most of the solution vague or misleading and I end up confusing myself.

I need to know whether my approach was right or should I do something else? If so what should I do exactly.Please help me through this

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2016-03-10 15:35:19 -0600

aguadopd gravatar image

updated 2016-05-09 18:26:40 -0600

Probably late, but for the record:

The topic that you are subscribing to has 32 bit depth - which can not be visualized by image_viewer. Try one of the other depth topics - I cannot recall right now which one could be seen. Try rostopic list | grep depth , rostopic list lists all of the published topics, while grep depth filters the output so that you only see the ones that have the word "depth" in them.

Despite not being able to see the that topic you are subscribing to, you can use it in any of your nodes. Or maybe in RVIZ if you want to see the 3d points.

Here is one example node that subscribes to /camera/depth_registered/hw_registered/image_rect_raw and /camera/rgb/image_color from a Turtlebot 1. It then saves the depth images as 16 bit png and tiff :

Source and more

/* Este es un nodo de ROS Indigo para guardar imagenes de /camera/depth_registered/image_rect_raw
 * y de /camera/rgb/color/image_rect_raw de un Turtlebot1 para luego procesarlas con otro programa. 
 * Las de profundidad se guardan como unsigned int de 16 bits 
 * y 1 canal, las de color se guardan como unsigned int de 8 bits en 3 canales.
 * Se utiliza un suscriptor sincronizado para guardar el par de imagenes que estén más
 * cercanas en el tiempo.
 * LAS IMAGENES SE GUARDAN ADONDE SE EJECUTE EL NODO.
 * ---------------------------------------------------------
 * Creado por Fabricio Emder y Pablo Aguado en el 2016 */


/* This is a ROS Indigo node for saving Turtlebot images from the /camera/depth_registered/image_rect_raw
 * and /camera/rgb/color/image_rect_raw topics, for further processing outside of the program. 
 * Depth images are saved as 1 channel 16 bit unsigned int PNGs (CV_16UC1), and 
 * RGB images are saved as 3 channel 8 bit unsigned int PNGs (CV_8UC3).
 * A synchronized subscriber is used, for saving the pair of images that are most closer in time.
 * THE IMAGES ARE SAVED WHEREVER THE NODE IS RUN.
 * Created by Fabricio Emder and Pablo Aguado - 2016
 * */

#include <ros/ros.h>
#include <cv_bridge/cv_bridge.h>    // OpenCV
#include <sensor_msgs/Image.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>


/* La política de sincronización exacta NO FUNCIONA para los topics seleccionados, ya 
 * que la Kinect o sus drivers no los están publicando con la misma marca temporal.
 * Ver más en http://wiki.ros.org/message_filters 
 * 
 * Exact sychronization policy IS NOT WORKING for the topics used, because the kinect
 * is not publishing them with the same timestamp. 
 * See more in http://wiki.ros.org/message_filters  */

//#define EXACT
#define APPROXIMATE


#ifdef EXACT
#include <message_filters/sync_policies/exact_time.h>
#endif
#ifdef APPROXIMATE
#include <message_filters/sync_policies/approximate_time.h>
#endif



using namespace std;
//using namespace sensor_msgs;
using namespace message_filters;


// Contador para la numeración de los archivos.
// Counter for filenames.
unsigned int cnt = 1;



// Handler / callback
void callback( const sensor_msgs::ImageConstPtr& msg_rgb , const sensor_msgs::ImageConstPtr& msg_depth )
{
        //ROS_INFO_STREAM("Adentro del callback\n");
      cv_bridge::CvImagePtr img_ptr_rgb;
        cv_bridge::CvImagePtr img_ptr_depth;
    try{
        img_ptr_depth = cv_bridge::toCvCopy(*msg_depth, sensor_msgs::image_encodings::TYPE_16UC1);
    }
    catch ...
(more)
edit flag offensive delete link more
2

answered 2016-06-27 04:19:23 -0600

ROSkinect gravatar image

You can use my package to extract depth information from bagfile without losing precision:

https://github.com/JaouadROS/bagtodepth

edit flag offensive delete link more
0

answered 2018-09-25 01:38:56 -0600

nihalsoans91 gravatar image

Also if you need a python version of this , It will save each frame as an image https://github.com/nihalsoans91/Bag_t...

edit flag offensive delete link more

Comments

I had to make a small change to save 16 bit depth images into files. See here

Avner gravatar image Avner  ( 2019-01-21 16:23:07 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2014-12-13 14:32:22 -0600

Seen: 5,867 times

Last updated: Jun 27 '16