неправильный результат в коэффициенте искажения

76
5

y код:

CV_MAT_ELEM(*distortion_coeffs, float,0,0)= -0.20;   CV_MAT_ELEM(*distortion_coeffs, float,1,0)=0.20;
CV_MAT_ELEM(*distortion_coeffs, float,2,0)= -0.09; CV_MAT_ELEM(*distortion_coeffs, float,3,0)=0.30;

int found = cvFindChessboardCorners(image, board_sz, corners, &corner_count,CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS );
cvFindCornerSubPix(gray_image, corners, corner_count, cvSize(11,11),cvSize(-1,-1), cvTermCriteria( CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, 30, 0.1 ));
cvDrawChessboardCorners(image, board_sz, corners, corner_count, found); //Draw it
step= ig*board_total;
for( int i=step,j=0 ; j<board_total; ++j, ++i)
{

CV_MAT_ELEM(*image_points, float,i,0) = corners[j].x;
CV_MAT_ELEM(*image_points, float,i,1) = corners[j].y;
CV_MAT_ELEM(*object_points,float,i,0) = (float) j/board_w;
CV_MAT_ELEM(*object_points,float,i,1) = (float) (j%board_w);
CV_MAT_ELEM(*object_points,float,i,2)=0.0f;
}

CV_MAT_ELEM (*point_counts, int,ig,0) = board_total; } } }

CvMat* object_points2 = cvCreateMat(n_boards*board_total,3,CV_32FC1);
CvMat* image_points2 = cvCreateMat(n_boards*board_total,2,CV_32FC1);
CvMat* point_counts2 = cvCreateMat(n_boards,1,CV_32SC1);

for(int i = 0; i<n_boards*board_total; ++i)
{
CV_MAT_ELEM( *image_points2, float, i, 0) = CV_MAT_ELEM( *image_points, float, i, 0);
CV_MAT_ELEM( *image_points2, float,i,1) = CV_MAT_ELEM( *image_points, float, i, 1);
CV_MAT_ELEM(*object_points2, float, i, 0) = CV_MAT_ELEM( *object_points, float, i, 0) ;
CV_MAT_ELEM( *object_points2, float, i, 1) = CV_MAT_ELEM( *object_points, float, i, 1) ;
CV_MAT_ELEM( *object_points2, float, i, 2) = CV_MAT_ELEM( *object_points, float, i, 2) ;
}

CV_MAT_ELEM( *intrinsic_matrix, float, 0, 0 ) = 1.0f;
CV_MAT_ELEM( *intrinsic_matrix, float, 1, 1 ) = 1.0f;

cvCalibrateCamera2(object_points2, image_points2, point_counts2, cvSize( image->width, image->height ), intrinsic_matrix, distortion_coeffs, NULL, NULL,(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON) );
cvFindExtrinsicCameraParams2(object_points2, image_points2, intrinsic_matrix, distortion_coeffs,rvec,tvec,0);

CvMat *intrinsic = (CvMat*)cvLoad("intrinsic.xml"); //matrix 3 by 3
CvMat *distortion = (CvMat*)cvLoad("distortion.xml"); //matrix 4 by 1

//// Build the undistort map used for all subsequent frames.
IplImage* image1 = cvLoadImage("distoredimage.jpg");
IplImage* mapx = cvCreateImage( cvSize( image1->width, image1->height ), IPL_DEPTH_32F, 1);//IPL_DEPTH_32F
IplImage* mapy = cvCreateImage( cvSize( image1->width, image1->height ), IPL_DEPTH_32F, 1 );

//mapy = cvLoadImage("distoredimage.jpg");
cvInitUndistortMap(intrinsic,distortion_coeffs,mapx,mapy);
//Run the camera to the screen, showing the raw and the undistorted image.
cvNamedWindow( "distoredimage");
cvNamedWindow( "Undistort" );
IplImage *t = cvCloneImage(image1); // create a copy from the image
cvShowImage( "distoredimage", image1); // Show corrected image
cvRemap( image1,t, mapx, mapy,CV_WARP_FILL_OUTLIERS, cvScalarAll(0) ); // Undistort image +CV_INTER_LINEAR
cvSaveImage("undistort.jpg",t);
cvShowImage("Undistort", t);// Show corrected image

Я получил внутренние и внешние параметры.

Искажениями являются [-1.25201664e+001 8.19589920e+001 4.27083164e-001 2.12188810e-001 ]. Исходное изображение не будет исправлено, потому что эти параметры неверны.

Я видел cvUndistort2() и cvRemap(), но я не понимаю, что это ошибка?

заблаговременно за помощь

спросил(а) 2012-09-28T13:56:00+04:00 7 лет, 2 месяца назад
0
Ваш ответ
Введите минимум 50 символов
Чтобы , пожалуйста,
Выберите тему жалобы:

Другая проблема