decadenza / DirectStereoRectification

"Rectifying Homographies for Stereo Vision: Analytical Solution for Minimal Distortion": algorithm to compute the optimal rectifying homographies that minimise perspective distortion.
GNU General Public License v3.0
27 stars 5 forks source link

Deriving stereo extrinsic parameters #2

Closed KevinCain closed 2 years ago

KevinCain commented 2 years ago

Thanks for your intriguing work, continuing in the footsteps of Loop & Zhang.

Could you provide a suitable conversion for calibrated stereo camera data to the left+right extrinsic matrices you require as input to example.py -- for example, using OpenCV's cv2.stereoCalibrate output?

decadenza commented 2 years ago

Hi, and thanks for your interest.

OpenCV, for convetion, sets the world origin in the first camera and then you only have the extrinsic matrices (a rotation R and a translation T) that lead you from the 1st to the second camera (see StereoCalibrate documentation).

To solve your problem, for the first camera, you simply have to use: R1 = 3x3 identity matrix t1 = zero array which joined together become:

RT1 = np.array([[ 1, 0, 0,  0],   # Left extrinsic parameters
                    [0, 1, 0, 0],
                    [0, 0, 1, 0]])

And for the second camera, you can use the stereo calibrate output values of R and T, again, joined together in the 3x4 matrix:

RT2 = np.hstack((R, T.reshape(3,1) ))

The opposite can be done too, moving the world origin in the first camera. I'll be soon releasing a stereo vision library containing several tools for these operations and more.

Hope this helps.

decadenza commented 2 years ago

Obviously intrinsic matrices (called cameraMatrix1 and cameraMatrix2 in OpenCV) and distortion coefficients (distCoeffs1 and distCoeffs2) are unaffected by the transformation and remain exactly the same ones!

decadenza commented 2 years ago

I'm going to close this. Feel free to reopen for any issue.

decadenza commented 2 years ago

@KevinCain I published the full library with many examples. For general stereo vision operations, please refer to it SimpleStereo. Examples of calibration are provided too.

Hope this helps many other people working with this stuff.

Cheers