Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to correct/remap a perspective effect after an undistort from camera calibration ?

Good evening,

I would like to remap a trapezoid ROI to a rectangular ROI after correcting a barrel distortion on a frame.

Here is my frame :

camera frame

From this frame (and many others), I calculated the camera matrix and the distortion coefficients using the function cv::calibrateCamera.

I managed to "draw" the radial distortions which gives me this :

image description

From what I understand, everything in the green area will be remapped into a rectangle with the size of my frame. Everything outside the green area will be considered "cropped".

To undistort the image, I am using cv::initUndistortRectifyMap with matrix R set as identity matrix, as well as cv::remap. The result of this operation is the following :

image description

Now, I would like to remap the trapezoid chessboard into a rectangular chessboard of frame size. I could use cv::getPerspectiveTransform and cv::warpPerspective to remap from trapezoid to rectangle but it would only stretch the image and this is not the result I would expect.

In fact, I would like to know if we could find a much better warp or process knowing the translations and rotations matrices from the camera calibration. The purpose of this is to keep a certain aspect of "depth" from the image but processing a rectangular ROI (to find contours, get their real positions, etc ...)

Thanks in advance for your help !

How to correct/remap a perspective effect after an undistort from camera calibration ?

Good evening,

I would like to remap a trapezoid ROI to a rectangular ROI after correcting a barrel distortion on a frame.

Here is my frame :

camera frame

From this frame (and many others), I calculated the camera matrix and the distortion coefficients using the function cv::calibrateCamera.

I managed to "draw" the radial distortions which gives me this :

image description

From what I understand, everything in the green area will be remapped into a rectangle with the size of my frame. Everything outside the green area will be considered "cropped".

To undistort the image, I am using cv::initUndistortRectifyMap with matrix R set as identity matrix, as well as cv::remap. The result of this operation is the following :

image description

Now, I would like to remap the trapezoid chessboard into a rectangular chessboard of frame size. I could use cv::getPerspectiveTransform and cv::warpPerspective to remap from trapezoid to rectangle but it would only stretch the image and this is not the result I would expect.

In fact, I would like to know if we could find a much better warp or process knowing the translations and rotations matrices from the camera calibration. The purpose of this is to keep a certain aspect of "depth" and "position" from the image but processing a rectangular ROI (to find contours, get their real positions, etc ...)

Thanks in advance for your help !

How to correct/remap a perspective effect after an undistort from camera calibration ?

Good evening,

I would like to remap a trapezoid ROI to a rectangular ROI after correcting a barrel distortion on a frame.

Here is my frame :

camera frame

From this frame (and many others), I calculated the camera matrix and the distortion coefficients using the function cv::calibrateCamera.

I managed to "draw" the radial distortions which gives me this :

image description

From what I understand, everything in the green area will be remapped into a rectangle with the size of my frame. Everything outside the green area will be considered "cropped".

To undistort the image, I am using cv::initUndistortRectifyMap with matrix R set as identity matrix, as well as cv::remap. The result of this operation is the following :

image description

Now, I would like to remap the trapezoid chessboard into a rectangular chessboard of frame size. I could use cv::getPerspectiveTransform and cv::warpPerspective to remap from trapezoid to rectangle but it would only stretch the image and this is not the result I would expect.

In fact, I would like to know if we could find a much better warp or process knowing the translations and rotations matrices from the camera calibration. The purpose of this is to keep a certain aspect of "depth" and "position" from the image but processing a rectangular ROI (to find contours, get their real positions, etc ...)

Thanks in advance for your help !

EDIT (17/11/17) (see Der Luftmensch comment below) :

I provided two drawings (with my best Paint.NET skills) to express my needs.

I would like to track coins inside a region of interest. The main parameters I would like to track are their sizes and their positions (it is not about object detection here).

Drawing of coins and ROI

Representing the camera and the ROI

To get very good results, I need to calibrate my camera correctly because it has an awful barrel distortion and it distorts the region of interest and the coins shapes in consequence. So once I calibrated my camera, the ROI is still seen as a trapezoid but I would need to remap this ROI into a rectangle of the size of a frame (let's say 640x480).

As I mentionned above, I don't think that using warpPerspective would be a good idea because it would also distort the coins shapes and "fake" their real positions. I don't really know if it is about according ratios correctly or using specific matrices calculations to get the best result. I've heard about translation matrices and rotation matrices but I don't understand how can I get them.

The parameters that I know are the corners of the ROI (because my region doesn't move at all), the rotation angle of the camera (see the second link above), the distance between my camera and the center of the ROI, the world size of the ROI (in centimeters), etc. Coins have different sizes because of the depth field and this is a thing I would care about.

I would like to use cv::findContours to get the shapes of the coins but I think that - as I said - they are distorted by the perspective effect and the depth effect.