Ask Your Question
2

How can I get original coordinates after stereo rectification?

asked 2016-08-17 06:54:38 -0600

AirCheese gravatar image

Hello, everyone. I'm a newbie here.

I'm working on stereo rectification and reverse mapping. I need to get original coordinates(in the source image) after stereo rectification( cvStereoRectify(), cvInitUndistortRectifyMap() ). Rectified Image coordinates is different original Image coordinates. right? I searched it for a long time. But, I could't find the exact way to get original coordinates after stereo rectification yet. It might be easy for you guys. Please help me.

Best regards, AirCheese

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-05-10 16:26:29 -0600

ksenobojca gravatar image

I'm not sure what "stereo" part does, but for cvInitUndistortRectifyMap you can try following (Python code):

To remove distortion (transform points like cvInitUndistortRectifyMap transforms image)

pts_rectified = cv2.undistortPoints(src=pts_org, cameraMatrix=cameraMatrix, distCoeffs=distCoeffs, R=cameraMatrix)

It uses iterative algorithm with only 5 (hardcoded) iterations - error is subpixel, but it's not perfect.

To apply distortion

This direction is precise (no need for iterations). Maybe there is simpler way to call it.

Convert rectified 2D points to 3D points like:

(x-cx, y-cy, f)

In Python it could be:

pts_tmp = cv2.convertPointsToHomogeneous(pts_rectified)  # add column z=1
pts_tmp[:, :, 2] *= cameraMatrix[0, 0]  # z=1 -> z='f'
pts_tmp[:, :, 0] -= cameraMatrix[0, 2]  # substract cx and cy
pts_tmp[:, :, 1] -= cameraMatrix[1, 2]

then:

pts_org_back = cv2.projectPoints(pts_tmp, rvec=(0, 0, 0), tvec=(0, 0, 0), cameraMatrix=cameraMatrix, distCoeffs=distCoeffs)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-08-17 06:54:38 -0600

Seen: 558 times

Last updated: May 10 '20