Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 452
Bhanu Chander Avatar asked Mar 11 '17 16:03

Bhanu Chander


1 Answers

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.

like image 95
CabaIT Avatar answered Oct 28 '22 15:10

CabaIT