0
$\begingroup$

Rosanswers logo

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;
  try
  {
    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); 

    cv::waitKey(1000);
  }
  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::init(argc,argv,"depth_distance");
        ros::NodeHandle nh;
        image_transport::ImageTransport it(nh);
        image_transport::Subscriber sub1 = it.subscribe("/camera/aligned_depth_to_color/image_raw", 1, depthCallback);
        ros::spin();
        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/libthread_db.so.1".
[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;

Originally posted by 七小丘人 on ROS Answers with karma: 56 on 2019-03-03

Post score: 0


Original comments

Comment by gvdhoorn on 2019-03-04:
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.

Comment by 七小丘人 on 2019-03-04:
but the program always goes into time.h and can't work when I use gdb

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by 七小丘人 with karma: 56 on 2019-03-04

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.