opencv错误:当我校准相机时,convert.cpp(opencv)中的断言失败

时间:2012-08-31 14:42:03

标签: c++ visual-studio-2010 opencv windows-7 camera-calibration

我尝试校准相机(opencv 2.3.1,VS 2010和Windows 7),但是当我编译我的程序时,有一个opencv错误是“断言失败:dst.channels<>>未知function,file .... modules \ core \ src \ convert.cpp,line 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);

我试图多次解决这个问题,请我帮忙。

2 个答案:

答案 0 :(得分:0)

(我打开我的评论作为答案,因为Nabiha可能无法用1代回复评论。)

您似乎正在将错误类型的图像(错误的通道数)传递给其中一个cv函数。根据你的描述很难说,但我猜它发生在cvCalibrateCamera2或cvFindHomograpy。

断言也听起来像是运行时错误而不是编译时错误。

如果是运行时错误,则必须检查传递给这些功能的图像是否具有正确的设置(通道,相同大小等)。这是编译器无法检查的内容,因为这些参数是动态的。

您可以有条不紊地评论某些功能(调试代码)并查看您的程序是否仍然有效,以防您在查找代码中断调试器的位置时遇到问题。隔离呼叫后,请查看文档中有关图像参数的信息,您应该在正确的轨道上解决此问题。

校准是一个多步骤的过程(抓取图像,提取特征,计算单应性,计算instrinic和extrinisic相机参数)。理解(数学方面)也很棘手,所以不要放弃。 OpenCV校准功能通常可以很好地工作。

答案 1 :(得分:0)

调试按钮未激活且解决方案项目的重新扫描按钮未激活,因此我无法编译或调试程序示例\ cpp \ calibration.cpp