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

stereo rectification for camera pair with diffrent x, y, z #5

Closed williamhyin closed 2 years ago

williamhyin commented 2 years ago

Hi

I have a question about the stereo rectification with different x,y,z. As i know, opencv.stereorectify only support the stereo rectification which only have x_difference or y_difference. Can i realize stereo rectification for camera pair with diffrent x, y, z with your code? For example, the cameras are staggered in a specified position. One camera is high and the other is low. If not, can you give me some suggestion about code modification?

Thanks

decadenza commented 2 years ago

Hello @williamhyin

You are right, OpenCV, without loss of generality, moves the world origin into the first camera, so that you are dealing with only one rotation matrix (R) and translation vector (T).

Our rectification example here, instead, does not follow this convention. You can have two generic cameras placed anywhere in the space. In fact, in https://github.com/decadenza/DirectStereoRectification/blob/master/example.py you can find RT1 and RT2 representing the extrinsic parameters of the two cameras. There is no need to move the origin to the first camera. So, to answer your question: yes, you can rectify with "different x, y, z" (position and rotation) with this code.

It's not that OpenCV is wrong, actually moving the world origin to the first camera is convenient. If desired, you can transform two generic cameras into the OpenCV convention by using simplestereo.utils.moveExtrinsicOriginToFirstCamera

Happy coding. Cheers.

williamhyin commented 2 years ago

Thanks for your great work! if i use the each camera parameter RT1 and RT2, where is the world center for the stereo rectification? Is it the center of their connected line between two camera?

decadenza commented 2 years ago

Well, the world center will always be in (0,0,0). First camera C1 will be placed in -R1.T1. Second camera C2 will be placed in -R2.T2.

No, the baseline is the line C1C2. Its length will always be the same, independently from where you place your world origin. See, your issue is not related with stereo vision itself, these are general reference system considerations, like in basic Physics.

Hope this helps.

Cheers