- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I installed librealsense 2.8.1 and the ROS wrapper 2.0.1. When i'm using the realsense-viewer I can view the depth and color streams. I am also able to measure the distance in the viewer.
How can I measure the distance with a ROS node?
I tried the sample code posted here : https://github.com/IntelRealSense/librealsense/tree/development# quick-start GitHub - IntelRealSense/librealsense at development but it dosen't work.
The sample code uses the rs_pipeline. Is it possible to subscribe to the depth topic and calculate the distance from it? If I rostopic echo the depth stream the resulting values range between 0 and 255 (not the distance in m).
Thank you
- Tags:
- Intel® RealSense
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2017 Intel Corporation. All Rights Reserved.
# include
# include
# include
# include
# include
void chatterCallback(const sensor_msgs::Image::ConstPtr& msg)
{
cv_bridge::CvImagePtr Dest = cv_bridge::toCvCopy(msg);
ROS_INFO("Width: %i", msg->width);
ROS_INFO("Height: %i", msg->height);
ROS_INFO("Value: %f", Dest->image.at(msg->width/2,msg->height/2));
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "distance");
ros::NodeHandle n;
ros::AsyncSpinner spinner(1);
spinner.start();
ros::Subscriber sub = n.subscribe("camera/depth/image_raw", 100, chatterCallback);
ros::Duration(100).sleep(
return 0;
}
I wrote this node. I subscribe to the depth stream and the output of width and height of the depth stream are correct.
The distance value still doesn't work. It always returns 0.00.
Is my conversion from ROS to OpenCV correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello FelixAl,
We escalated your question to RealSense developers. We'll let you know as soon as we have an answer.
Regards,
Jesus
Intel Customer Support
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello FelixAl, we received this code snippet from the dev team that will do as you asked.
Hi,
The following code snippet can do what he asked. I added a ROS conversion from raw depth pixel to a distance in meters.
# include <</span>ros/ros.h>
# include <</span>image_transport/image_transport.h>
# include <</span>cv_bridge/cv_bridge.h>
# include <</span>sensor_msgs/image_encodings.h>
# include <</span>iostream>
# include <</span>depth_image_proc/depth_conversions.h>
# include <</span>depth_image_proc/depth_traits.h>
void chatterCallback(const sensor_msgs::Image::ConstPtr& msg)
{
cv_bridge::CvImagePtr Dest = cv_bridge::toCvCopy(msg);
ROS_INFO("Width: %i", msg->width);
ROS_INFO("Height: %i",<span style="color: ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page