为什么我的值总是NaN,焦距小?

时间:2012-11-26 13:15:10

标签: c++ opencv nan

每当我在openCv Posit函数中使用我的相机焦距时,我得到所有值的NaN,但是当我使用更高的值时,我没有这个错误(但数字不是真的)。我有一个金字塔作为模型。 3个点位于1个平面内,1个位于中间位置。谁知道如何处理这个?还是一些好的链接?

int depth = -18; 

//create the model points 
std::vector<CvPoint3D32f> modelPoints; 
modelPoints.push_back(cvPoint3D32f(  0.0f,   0.0f, 0.0f));  //(the first must be 0,0,0) middle center diod 
modelPoints.push_back(cvPoint3D32f(-18.0f, -30.0f, depth)); //bottom left diode
modelPoints.push_back(cvPoint3D32f( 18.0f, -30.0f, depth)); //bottom right diode
modelPoints.push_back(cvPoint3D32f( 0.0f,  30.0f, depth)); //top center diode


system("cls");
//create the image points
std::vector<CvPoint2D32f> srcImagePoints;
cout << "Source Image Points:" << endl;
for( size_t i = 0; i < circles.size(); i++ )
{
    cout << "x: " << cvRound(circles[i][0]) << " y: " << cvRound(circles[i][1]) << endl;
    //228, 278
    //291, 346 (Pixel coordinates of the points on the image)
    //371, 346
    //228, 206
    srcImagePoints.push_back( cvPoint2D32f(cvRound(circles[i][0]), cvRound(circles[i][1])) );
}

cout << endl;

//create the POSIT object with the model points 
CvPOSITObject* positObject = cvCreatePOSITObject( &modelPoints[0], (int)modelPoints.size() ); 

//calculate the orientation 
float* rotation_matrix = new float[9]; 
float* translation_vector = new float[3]; 

CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 100, 1.0e-4f); 
double FOCAL_LENGTH = 16; //16.0; //760.0; 
cvPOSIT( positObject, &srcImagePoints[0], FOCAL_LENGTH, criteria, rotation_matrix, translation_vector ); 

//calculate rotation angles 
double beta  = atan2((double)(-rotation_matrix[2]), (double)(sqrt(pow(rotation_matrix[0], 2) + pow(rotation_matrix[3], 2)))); 
double alpha = atan2((rotation_matrix[3]/cos(beta)),(rotation_matrix[0]/cos(beta))); 
double gamma = atan2((rotation_matrix[7]/cos(beta)),(rotation_matrix[8]/cos(beta))); 

0 个答案:

没有答案