cvUndistort2 () and cvRemap () crash

后端 未结 2 1564
情书的邮戳
情书的邮戳 2021-01-15 23:46

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

2条回答
  •  逝去的感伤
    2021-01-16 00:33

    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
    

提交回复
热议问题