我尝试校准相机(opencv 2.3.1、VS 2010 和 Windows 7),但是当我编译我的程序时,出现一个 opencv 错误
“断言失败:<src.size==dst.size && src.channels<>dst.channels<>> 在未知函数中,文件 ....modules \core\src\convert.cpp,第 1277 行”。
这里是代码的一部分,
CvMat* image_points = cvCreateMat(n_boards*board_total,2,CV_32FC1);
CvMat* object_points = cvCreateMat(n_boards*board_total,3,CV_32FC1);
CvMat* point_counts = cvCreateMat(n_boards,1,CV_32SC1);
CvMat* intrinsic_matrix = cvCreateMat(3,3,CV_32FC1);
CvMat* distortion_coeffs = cvCreateMat(4,1,CV_32FC1);
for ( int ig = 0; ig< n_boards; ig++ )
{
image= cvLoadImage(names[ig],CV_LOAD_IMAGE_COLOR); // load image
cvNamedWindow("imageessai", 1);
cvShowImage("imageessai", image);
cvWaitKey(0);
cvDestroyWindow("imageessai");
for (int ik=0; ik<n_boards; ik++)
{
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);
if( corner_count == board_total )
{
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;
printf("\n %d successful Snapshots out of %d collected.\n",ig+1,n_boards);
}
}
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) ;
}
for(int i=0; i<n_boards; ++i)
{
CV_MAT_ELEM( *point_counts2, int, i, 0)=CV_MAT_ELEM(*point_counts,int,i,0);
}
cvReleaseMat(&object_points);
cvReleaseMat(&image_points);
cvReleaseMat(&point_counts);
CV_MAT_ELEM( *intrinsic_matrix, float, 0, 0 ) = 1.0f;
CV_MAT_ELEM( *intrinsic_matrix, float, 1, 1 ) = 1.0f;
CvMat* rvec = cvCreateMat(n_boards,3,CV_32F);//matrice de rotation
CvMat* tvec = cvCreateMat(n_boards,3,CV_32F);//matrice de translation
CvMat* H = cvCreateMat(1,3,CV_32FC1);
cvCalibrateCamera2(object_points2, image_points2, point_counts2, sizeim, intrinsic_matrix, distortion_coeffs, rvec, tvec,0 );
cvFindHomography(object_points2,image_points2,H,0,3,NULL);
我试图解决这个问题很多次,请我需要帮助。