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

segmentation fault (core dumped) while converting sensor_msgs to cvImage

asked 2019-03-03 21:41:47 -0500

七小丘人 gravatar image

updated 2019-03-04 06:03:05 -0500

I am trying to subscribe the topic /camera/aligned_depth_to_color/image_raw of realsense SR300. Here is the node:

#include "ros/ros.h"
#include <opencv2/dnn.hpp>
#include <librealsense2/rs.hpp>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

void depthCallback(const sensor_msgs::ImageConstPtr& depth_msg)
  cv_bridge::CvImagePtr depth_ptr;
    cv::imshow("depth_view", cv_bridge::toCvShare(depth_msg, sensor_msgs::image_encodings::TYPE_16UC1)->image);
    depth_ptr = cv_bridge::toCvCopy(depth_msg, sensor_msgs::image_encodings::TYPE_16UC1); 
    //  cv::imshow("depth_view", cv_bridge::toCvShare(depth_msg, sensor_msgs::image_encodings::TYPE_32FC1)->image);
    //  depth_ptr = cv_bridge::toCvCopy(depth_msg, sensor_msgs::image_encodings::TYPE_32FC1); 

  catch (cv_bridge::Exception& e)
    ROS_ERROR("Could not convert from '%s' to '32fc1'.", depth_msg->encoding.c_str());

    int main(int argc, char **argv)
        ros::NodeHandle nh;
        image_transport::ImageTransport it(nh);
        image_transport::Subscriber sub1 = it.subscribe("/camera/aligned_depth_to_color/image_raw", 1, depthCallback);
        return 0;

But when I ran the node , I met the fault:

rosrun cood_tran depth_distance                    
[1]    24671 segmentation fault (core dumped)  rosrun cood_tran depth_distance

I don't know why. I ran it in gdb and I got this.

(gdb) r
Starting program: /home/qiuyilin/catkin_ws/devel/lib/cood_tran/depth_distance __name:=depth_distance __log:=/home/qiuyilin/.ros/log/ee00c938-3e6d-11e9-a98e-0028f8fda2a0/depth_distance-1.log
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/".
[New Thread 0x7fffe3356700 (LWP 15807)]
[New Thread 0x7fffe2b55700 (LWP 15808)]
[New Thread 0x7fffe2354700 (LWP 15809)]
[New Thread 0x7fffe1b53700 (LWP 15814)]

Thread 2 "depth_distance" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe3356700 (LWP 15807)]
0x00007ffff578d230 in ros::Time::now ()
    at /home/qiuyilin/librealsense-2.16.3/third-party/realsense-file/rosbag/rostime/src/time.cpp:261
261         return t;
edit retag flag offensive close merge delete


It's most likely either a pointer dereference issue or some other simple cause, so I'd recommend running your node in GDB (or some other debugger if you prefer). Refer to this page for info on how to do that.

gvdhoorn gravatar image gvdhoorn  ( 2019-03-04 02:17:32 -0500 )edit

but the program always goes into time.h and can't work when I use gdb

七小丘人 gravatar image 七小丘人  ( 2019-03-04 07:50:03 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-03-04 20:50:56 -0500

七小丘人 gravatar image

I found that I had added realsense2_camera to cmakelist.txt and deleted it. Now it works. I think I have to understand how to decide dependencies.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-03-03 21:41:47 -0500

Seen: 1,075 times

Last updated: Mar 04 '19