Stereo-Vision icon indicating copy to clipboard operation
Stereo-Vision copied to clipboard

Question about general use in any case

Open Petros626 opened this issue 2 years ago • 4 comments

Hello,

I would like to know, if this script can measure the distance of any object shown in a stream, no matter where it's located? If not, what adjustments in the code are necessary?

I plan to use a stereo camera and a pretrained CNN, which detects objects, additionally I want to measure the distance to the detected objects.

Thanks in advance

Petros626 avatar Apr 20 '23 09:04 Petros626

Hey Petros626,

The script will produce a two dimensional array of values which represent the depth of each pixel in the scene, however due to the nature of this traditional method, not all pixels will have values attributed to them. Some ill-posed regions (areas where the algorithm has a hard time determining depth) will be left empty.

basicblockmatching1

As long as the object is within the image/frame from your stream and a value which represents the pixels of your object is within the depth map, you will be able to determine the estimated depth. I'd recommend doing some averaging of small kernels depending on what kind of object it is.

Note: the resulting values will be disparity values, which you will use to calculate metric depth with depth = baseline * focal_length / disparity. For more see here.

shanearthur avatar Aug 15 '23 19:08 shanearthur

Thank you for your detailed answer. The most algorithms I saw was with a known object size, but this wasn't which I was searching for. So if with the mentioned formula you can calculate the distance why in your code specific values are made here:

https://github.com/LearnTechWithUs/Stereo-Vision/blob/597d9e5d4fdeb96583339365f41bf9488ea5c9fd/Main_Stereo_Vision_Prog.py#L37

Petros626 avatar Aug 15 '23 20:08 Petros626

why in [the] code specific values are made here

Those are likely the specific parameters provided by datasets which the author was using to test this code. They may also be customized to compensate for the averaging being done two lines above your referenced line, where the author is getting the average disparity value of a small kernel of pixels around the pixel in question: https://github.com/LearnTechWithUs/Stereo-Vision/blob/597d9e5d4fdeb96583339365f41bf9488ea5c9fd/Main_Stereo_Vision_Prog.py#L35

shanearthur avatar Aug 15 '23 21:08 shanearthur

Yes, as @shanearthur said. Those values (polynomial coefficients) are estimated based on a custom dataset. (Similar to issue https://github.com/LearnTechWithUs/Stereo-Vision/issues/5). When and how we estimated those parameters is shown in this section of the YouTube video. We plotted a curve in which we had the distance on the x-axis and the disparity values on the y_axis (if I remember correctly). Afterward, we did a polynomial regression of degree 3 (known from the literature) via Excel - but you can do that with Python libraries to optimize the value.

Vujas-Eteph avatar Dec 18 '23 07:12 Vujas-Eteph