OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 09 Jul 2014 13:16:26 -0500Calculating distance from the pixel value of a disparity maphttp://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/Hi,
I have been looking for a simple solution for a while, but haven't come across anything so..
I have generated a disparity map using the OpenCV StereoBM and StereoSGBM functions and a pair of cameras. I have all of the camera parameters generated by stereo_calib. Is there a fairly straightforward way to calculate the distance using all of this information given the grayscale value of the pixel?
ThanksWed, 09 Jan 2013 08:44:10 -0600http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/Answer by Mathias for <p>Hi,</p>
<p>I have been looking for a simple solution for a while, but haven't come across anything so..</p>
<p>I have generated a disparity map using the OpenCV StereoBM and StereoSGBM functions and a pair of cameras. I have all of the camera parameters generated by stereo_calib. Is there a fairly straightforward way to calculate the distance using all of this information given the grayscale value of the pixel?</p>
<p>Thanks</p>
http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?answer=8080#post-id-8080Hey Lassan,
the last line of the documentation for reprojectImageTo3D states "To reproject a sparse set of points {(x,y,d),...} to 3D space, use perspectiveTransform()"
perspectiveTransform takes a 3D Point as src, in your case (x,y,disparity(x,y)) which will then be transformed using the Q matrix obtained with stereoRectify() and the result written into dst.
I haven't tested it myself but something like
1) Push all the points you want to transform into a cv::Mat array
2) cv::perspectiveTransform(your_point_array, output_point_array, Qmat)
should do the trick for you.
Hope that helped
Greetings
MathiasTue, 26 Feb 2013 03:38:07 -0600http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?answer=8080#post-id-8080Comment by berak for <p>Hey Lassan,</p>
<p>the last line of the documentation for reprojectImageTo3D states "To reproject a sparse set of points {(x,y,d),...} to 3D space, use perspectiveTransform()"
perspectiveTransform takes a 3D Point as src, in your case (x,y,disparity(x,y)) which will then be transformed using the Q matrix obtained with stereoRectify() and the result written into dst.</p>
<p>I haven't tested it myself but something like
1) Push all the points you want to transform into a cv::Mat array
2) cv::perspectiveTransform(your_point_array, output_point_array, Qmat)
should do the trick for you.</p>
<p>Hope that helped</p>
<p>Greetings
Mathias</p>
http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?comment=8081#post-id-8081actually, just `Scalar transformed = Q * Scalar(x,y,disparity,1);` does the same trick for 1 point as reprojectImageTo3DTue, 26 Feb 2013 03:51:34 -0600http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?comment=8081#post-id-8081Comment by Katri for <p>Hey Lassan,</p>
<p>the last line of the documentation for reprojectImageTo3D states "To reproject a sparse set of points {(x,y,d),...} to 3D space, use perspectiveTransform()"
perspectiveTransform takes a 3D Point as src, in your case (x,y,disparity(x,y)) which will then be transformed using the Q matrix obtained with stereoRectify() and the result written into dst.</p>
<p>I haven't tested it myself but something like
1) Push all the points you want to transform into a cv::Mat array
2) cv::perspectiveTransform(your_point_array, output_point_array, Qmat)
should do the trick for you.</p>
<p>Hope that helped</p>
<p>Greetings
Mathias</p>
http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?comment=24735#post-id-24735this seems to return the same matrix for every image. a 4x4 matrix. how to get depth from that?Fri, 29 Nov 2013 04:37:16 -0600http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?comment=24735#post-id-24735Answer by Victor1234 for <p>Hi,</p>
<p>I have been looking for a simple solution for a while, but haven't come across anything so..</p>
<p>I have generated a disparity map using the OpenCV StereoBM and StereoSGBM functions and a pair of cameras. I have all of the camera parameters generated by stereo_calib. Is there a fairly straightforward way to calculate the distance using all of this information given the grayscale value of the pixel?</p>
<p>Thanks</p>
http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?answer=5848#post-id-5848Why [reprojectImageTo3D](http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#reprojectimageto3d) is not suitable?Wed, 09 Jan 2013 09:25:18 -0600http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?answer=5848#post-id-5848Comment by Lassan for <p>Why <a href="http://docs.opencv.org/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#reprojectimageto3d">reprojectImageTo3D</a> is not suitable?</p>
http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?comment=5849#post-id-5849I suppose that is possible, but I only need to find the distance of, say, a single pixel, and can ignore the rest of the image. It would be a bit inefficient to calculate the 3D position of all of the image..Wed, 09 Jan 2013 10:39:03 -0600http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?comment=5849#post-id-5849Answer by bennygato for <p>Hi,</p>
<p>I have been looking for a simple solution for a while, but haven't come across anything so..</p>
<p>I have generated a disparity map using the OpenCV StereoBM and StereoSGBM functions and a pair of cameras. I have all of the camera parameters generated by stereo_calib. Is there a fairly straightforward way to calculate the distance using all of this information given the grayscale value of the pixel?</p>
<p>Thanks</p>
http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?answer=36721#post-id-36721There is a good piece of code from: [http://stackoverflow.com/questions/22418846/reprojectimageto3d-in-opencv]
The second piece of code in the question, is the code you need to just get one point's XYZ.Wed, 09 Jul 2014 13:16:26 -0500http://answers.opencv.org/question/5846/calculating-distance-from-the-pixel-value-of-a-disparity-map/?answer=36721#post-id-36721