cvCalibrateCamera2返回带有NaN元素的矩阵

时间:2013-03-28 19:14:13

标签: opencv matrix nan camera-calibration

我正在尝试使用cvCalibrateCamera2()进行相机校准,但遇到了一个问题:返回的intrinsic_matrix和distortion_coeffs包含无效的浮点数(= NaN)。

这就是我正在做的事情(休息是负责完全离开的):

image_points     =cvCreateMat(board_total,2,CV_32FC1); if (!image_points) break;
object_points    =cvCreateMat(board_total,3,CV_32FC1); if (!object_points) break;
point_counts     =cvCreateMat(1,1,CV_32SC1);           if (!point_counts) break;
intrinsic_matrix =cvCreateMat(3,3,CV_32FC1);           if (!intrinsic_matrix) break;
corners          =new CvPoint2D32f[board_total];       if (!corners) break;
distortion_coeffs=cvCreateMat(4,1,CV_32FC1);           if (!distortion_coeffs) break;

int found = cvFindChessboardCorners(gray_image, board_sz, corners,corner_count,CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS );
if (found==0) break;

直到这里才好,“gray_image”是我的输入图像,“corner”包含正确的棋盘角坐标

cvFindCornerSubPix(gray_image, corners,*corner_count, cvSize(11,11),cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));
for (j=0; j<board_total; j++)
{
    CV_MAT_ELEM(*image_points, float,0,0) = corners[j].x;
    CV_MAT_ELEM(*image_points, float,0,1) = corners[j].y;
    CV_MAT_ELEM(*object_points,float,0,0) = (float) j/board_w;
    CV_MAT_ELEM(*object_points,float,0,1) = (float) (j%board_w);
    CV_MAT_ELEM(*object_points,float,0,2) = 0.0f;
}
CV_MAT_ELEM(*point_counts, int,0,0) = board_total;

CV_MAT_ELEM( *intrinsic_matrix, float, 0, 0 ) = 1.0f;
CV_MAT_ELEM( *intrinsic_matrix, float, 1, 1 ) = 1.0f;
cvCalibrateCamera2(object_points,image_points,point_counts,cvGetSize( gray_image ),intrinsic_matrix,distortion_coeffs,NULL,NULL,0);

这里cvCalibrateCamera2()似乎工作并且没有异常但是当我尝试从中获取结果时,所有浮点数“d”都无效:

float d;
for (i=0; i<3; i++)
 for (j=0; j<3; j++)
{
   d=CV_MAT_ELEM(*intrinsic_matrix,float,i,j);
   calib_data->intrinsic[i][j]=(int)OAPC_ROUND(d*1000000,0);
}
for (i=0; i<4; i++)
{
   d=CV_MAT_ELEM(*distortion_coeffs,float,i,0);
   calib_data->distortion[i]=(int)OAPC_ROUND(d*100000000,0);
}

那么这里有什么问题?

0 个答案:

没有答案