How to change the attributes of cv2.StereoBM_create for depth map in OpenCV Python
Asked Answered
L

1

6

I was implementing the depth map construction, code of which (in Python) is available here OpenCv Docs - depthMap I was successful in getting the depth map as they showed in the doc for their given images-pair (left and right stereo images) tsukuba_l.png and tsukuba_2.png. I considered testing my own image pairs, so I took from my mobile a pair of images, as shown below:

enter image description here

enter image description here

When I run the code, I'm getting the depth map something like this

enter image description here

I tried playing with numDisparities and blocksize, but it didn't help in getting the best map.

I thought of checking the script of cv2.StereoBM_create in its master folder in Github, but couldn't get that online. Can you help me with a way to implement depth maps for custom images taken by me? is there a way that we can play with the parameters or at least get me the link to GitHub master module that has all Stereo related modules. Thank you.

Leicestershire answered 11/3, 2017 at 16:35 Comment(0)
L
4

I guess you did not rectify the images which is fundamental for stereo matching. You should first calibrate your stereo system (if you took them with mobile phone every image pair you take will have a different transform, the two cameras need to have always the same transformation between each other) and then rectify the images, in that way they are projected onto the same plane, then the stereo match algorithm looks for correspondences in the other image on the same rows.

Check in the docs for stereoRectify(), you will see some images as example of the rectification process.

By the way there is another python example based on SemiGlboal Block Matching algorithm in opencv/samples/python/stereo_match.py.

Lusty answered 16/5, 2017 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.