Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about general use in any case #15

Open
Petros626 opened this issue Apr 20, 2023 · 4 comments
Open

Question about general use in any case #15

Petros626 opened this issue Apr 20, 2023 · 4 comments

Comments

@Petros626
Copy link

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

@shanearthur
Copy link

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.

@Petros626
Copy link
Author

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:

Distance= -593.97*average**(3) + 1506.8*average**(2) - 1373.1*average + 522.06

@shanearthur
Copy link

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:

average += disp[y+u,x+v]

@Vujas-Eteph
Copy link

Yes, as @shanearthur said. Those values (polynomial coefficients) are estimated based on a custom dataset.
(Similar to issue #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants