Stereo Vision (Python) - How can I improve my Stereo Rectification results?

asked 2017-03-26 10:17:01 -0500

Lexus09 gravatar image

updated 2017-03-26 10:22:30 -0500

Hi all,

I am carrying out an undergraduate where I need to find out the depth of a stereo image, thus it is crucial to get a good disparity map for the calculations to be accurate. My rectification results are pretty mediocre at best and I have carried out the calibration countless times with no success, only minimal variations between results. I would highly appreciate experts' guidance on this issue. Like, can I try changing some parameters of my stereoRectify method? I already tried to tinker with the stereocalibrate parameters with minimal success.

I cannot post my results on this question as I have insufficient karma, but the rectified images look as if they were warped in a spiral manner and overriding the original video capture. Copy this in the URL if you wish to see a sample of my results:

This is my code for the calibration:

import cv,time,sys
import cv2
from itertools import izip
# python board_w,board_h and boards_n should be given by the user
n_boards=0  #no of boards
board_w=int(sys.argv[1])    # number of horizontal corners
board_h=int(sys.argv[2])    # number of vertical corners
n_boards=int(sys.argv[3])   # no. of views passed as pictures
board_n=board_w*board_h     # no of total corners
board_sz=(board_w,board_h)  # size of board

#   creation of memory storages for left camera

#   creation of memory storages for right camera

#capture frames of specified properties and modification of matrix values
z=0     # to print number of frames

#   capturing required number of views

with open('Left.txt','rb') as f:
    imgl= [line.strip() for line in f]
    with open('Right.txt','rb') as f1:
         imgr=[line.strip() for line in f1]
         for (image0,image1) in izip(imgl,imgr):
        if image0 =='' or image1== '' :

                Image0 = cv.LoadImage(image0)
                Image1 = cv.LoadImage(image1)

            (found0,corners0)=cv.FindChessboardCorners(gray_image0,board_sz,cv.CV_CALIB_CB_ADAPTIVE_THRESH| cv.CV_CALIB_CB_FILTER_QUADS)
            (found1,corners1)=cv.FindChessboardCorners(gray_image1,board_sz,cv.CV_CALIB_CB_ADAPTIVE_THRESH| cv.CV_CALIB_CB_FILTER_QUADS)
            # if got a good ...
edit retag flag offensive close merge delete


Intrinsic parameters seems wrong. Don't you use calibrateCamera to have a good guess of intrinsic parameters?

LBerger gravatar imageLBerger ( 2017-03-26 10:48:42 -0500 )edit

Thank you for your comment, the thing is I am using the stereoCalibrate method, isn't that the same thing just for stereo cameras?

Lexus09 gravatar imageLexus09 ( 2017-03-26 10:57:17 -0500 )edit

No StereoCalibrate is a method to estimate E, F R and T and find a better estimation of intrinsic parameter. When you use StereoCalibrate as you do 11 parameters (R,T) and 4 parameters (intrinsic) and 5 parameters for distortion must be estimated. It is difficult.

It is better to first estimate intrinsic and distortion parameters for each camera and then call StereoCalibrate using INTRINSIC_GUESS parameters.

Do you really need K4, K5, K6 parameters? If distortion is not visible you can set these parameters to 0

LBerger gravatar imageLBerger ( 2017-03-26 12:14:51 -0500 )edit

Can you guide me on how to do this? As I am pretty new to OpenCV/stereo vision in general. If not, thanks a million for your time and help, I really appreciate anyways :)

Lexus09 gravatar imageLexus09 ( 2017-03-26 12:20:56 -0500 )edit

Sorry I don't know python but you can use this tutorial to calibrate left and right camera. Try it and give results to StereoCalibrate.

LBerger gravatar imageLBerger ( 2017-03-26 13:35:38 -0500 )edit

Ok thank you! :)

Lexus09 gravatar imageLexus09 ( 2017-03-26 14:05:57 -0500 )edit

please use cv2, the arcane cv api got removed with opencv3 !

(this is all horribly outdated, and should NEVER be used)

berak gravatar imageberak ( 2017-03-27 00:35:18 -0500 )edit

Do you think it might affect the results obtained??

Lexus09 gravatar imageLexus09 ( 2017-03-27 13:06:10 -0500 )edit

^^ not really, but you won't be able to run that code on current opencv (they removed that api entirely)

please do not write more DEAD code, please do not fool noobs seing this into thinking, it would be a valid idea. (stackoverflow has done a lot of harm there already ..)

berak gravatar imageberak ( 2017-03-27 13:21:07 -0500 )edit