I was doing example 11-1 of \"Learning OpenCV\" by Bradski. Unfortunately the given example doesn\'t work on my computer.
The program is supposed to calibrate camera
The problem is that cvUndistort2 and cvRemap receive 8bit images only. Hence, in order to process color images, one must use cvSplit and cvMerge:
IplImage *r = cvCreateImage(cvGetSize(image),8,1);//subpixel
IplImage *g = cvCreateImage(cvGetSize(image),8,1);//subpixel
IplImage *b = cvCreateImage(cvGetSize(image),8,1);//subpixel
while(image) {
cvShowImage( "Calibration", image ); // Show raw image
//cvCvtColor(image, gray_image, CV_BGR2GRAY);
cvSplit(image, r,g,b, NULL);
cvRemap( r, r, mapx, mapy ); // Undistort image
cvRemap( g, g, mapx, mapy ); // Undistort image
cvRemap( b, b, mapx, mapy ); // Undistort image
cvMerge(r,g,b, NULL, image);
cvShowImage( "Undistort", image); // Show corrected image
try
cvRemap( t, image, mapx, mapy );
cvUndistort2(t ,image , intrinsic, distortion);
instead of
cvRemap( image, t, mapx, mapy ); // Undistort image
cvUndistort2(image, t, intrinsic, distortion);