Ask Your Question
1

cv::undistort returns corrupt image

asked 2012-11-07 11:57:08 -0500

_dit gravatar image

Hi

original image:

image description

image after undistort: image description

my code:

double * matrix_rgb = new double[9];
matrix_rgb[0] = fx_rgb;     matrix_rgb[1] = 0;          matrix_rgb[2] = cx_rgb;
matrix_rgb[3] = 0;          matrix_rgb[4] = fy_rgb;     matrix_rgb[5] = cy_rgb;
matrix_rgb[6] = 0;          matrix_rgb[7] = 0;          matrix_rgb[8] = 1;

double * vector_distorsion_rgb = new double[5];
vector_distorsion_rgb[0] = k1_rgb;
vector_distorsion_rgb[1] = k2_rgb;
vector_distorsion_rgb[2] = p1_rgb;
vector_distorsion_rgb[3] = p2_rgb;
vector_distorsion_rgb[4] = k3_rgb;

mCameraMatrixRGB     = new cv::Mat(3, 3, CV_64FC1, matrix_rgb);
mDistortionCoeffsRGB = new cv::Mat(1, 5, CV_64FC1, vector_distorsion_rgb);
cv::Mat srcMat_rgb(cv::Size(image_RGB->dimX, image_RGB->dimY), CV_8UC3, image_RGB->data, cv::Mat::AUTO_STEP);
cv::Mat undistorted;

cv::undistort(srcMat_rgb, undistorted, *mCameraMatrixRGB, *mDistortionCoeffsRGB);

for(int i = 0; i <image_RGB->dimX*image_RGB->dimY*image_RGB->planes; i++){
    ((uchar*)image_RGB->data)[i] = undistorted.data[i];
}

i hope some one can tell me what im doing wrong :(

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-11-09 02:42:06 -0500

SR gravatar image

I don't know what your image_RGB structure looks like. But the output seems like you mix the image types CV_8UC1 and CV_8UC3 when accessing the individual elements. Try your code with gray-scale images first, then use color images.

edit flag offensive delete link more

Comments

hi thx for your reply! image_RGB is just a struct with "uchar * data" R-channel (640x480) then G-channel (640x480) and then B-channel (640x480).

_dit gravatar image_dit ( 2012-11-09 03:39:12 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2012-11-07 11:57:08 -0500

Seen: 842 times

Last updated: Nov 09 '12