0
$\begingroup$

Rosanswers logo

I am using this code

topic is: /camera/depth/image
type: /sensor_msgs/Image

According to the code, (msg->data[0]) is providing the value of Top-Left Corner.

I wanted to ask:

  1. How can I get the value of the Top-Right Corner, Centre, etc.
  2. How can I get the normal depth value that can tell me the distance from the object? Do I need to do some mathematical work or is there a method?

Originally posted by Safeer on ROS Answers with karma: 66 on 2014-02-01

Post score: 1


Original comments

Comment by askkvn on 2021-06-24:
Your reference code helped, thanks

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

In the code the message is already converted to a cv::Mat ( cv_ptr->image ). Use this Matrix if you want to do some processing of the data.

E.g. you can use

float dist_val = cv_ptr->image.at<float>( 10, 10 );

to get the value at 10, 10. (There are much faster methods if you not just want to access one pixel, though).

See, http://docs.opencv.org for infos on how to handle your data with OpenCV.


Originally posted by Wolf with karma: 7555 on 2014-02-07

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by Safeer on 2014-02-10:
Thanks for your help. I visited the link you gave. Please guide me which topics/tutorials should I follow?

Comment by Wolf on 2014-02-10:
That very much depends on what you actually want to do. Probably some of the core and improc tutorials. If you want to do object detection: "Creating Bounding boxes and circles for contours"(particularly cv::findContours() usage). Threshold works also for dist imgs. Likely you need some normalizing.

Comment by Safeer on 2014-02-17:
Thanks for your reply.

Comment by askkvn on 2021-06-24:
Thanks, @Wolf, this solution worked for me. I have used /camera/depth/image_raw as an input rostopic.

My answer with complete code (c++): https://answers.ros.org/question/141741/calculate-depth-from-point-cloud-xyz/?answer=381085#post-id-381085

Extra:

  • To get image dimension: std::cout << "Image dimension (Row x Col): " << cv_ptr->image.rows << " x " << cv_ptr->image.cols << endl;

  • To get image global max and min depth values:

double max = 0.0;
cv::minMaxLoc(cv_ptr->image, &min, &max, 0, 0);
std::cout << "Min value: " << min << " " << "Max value: " << max << endl;```
$\endgroup$

Your Answer

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