2013-03-12 2 views
2

opencv로 작업 해 왔고 undistortPoints가 작동하지 않는 것 같습니다. 반환하는 행렬에는 NaN 값만 있습니다.opencv undistortPoints NaN ios를 반환합니다.

//newKeyPoints is std::vector<cv::KeyPoint>, and it's values are valid 
    cv::Mat src = cv::Mat(1,newKeyPoints.size(),CV_32FC2); 
    int i = 0; 
    for (std::vector<cv::KeyPoint>::iterator it = newKeyPoints.begin(); it != newKeyPoints.end(); it++){ 
     src.at<cv::Vec2f>(0,i)[0] = (*it).pt.x; 
     src.at<cv::Vec2f>(0,i)[1] = (*it).pt.y; 
     i++; 
    } 

    cv::Mat norm = cv::Mat(1,newKeyPoints.size(),CV_32FC2); 

    //Note: fx, fy, cx, cy... k3 are all global constants declared when initialized 
    cv::Mat cameraMatrix = cv::Mat(3, 3, CV_32F); 
    cameraMatrix.at<double>(0,0) = fx; //double fx = 354.65 
    cameraMatrix.at<double>(1,0) = 0; 
    cameraMatrix.at<double>(2,0) = 0; 
    cameraMatrix.at<double>(0,1) = 0; 
    cameraMatrix.at<double>(1,1) = fy; //double fy = 355.66 
    cameraMatrix.at<double>(2,1) = 0; 
    cameraMatrix.at<double>(0,2) = cx; //double cx = 143.2 
    cameraMatrix.at<double>(1,2) = cy; //double cy = 173.6 
    cameraMatrix.at<double>(2,2) = 1; 

    cv::Mat distCo = cv::Mat(1, 5, CV_32F); 
    distCo.at<double>(0,0) = k1; //double k1 = .005 
    distCo.at<double>(0,1) = k2; //double k2 = .002 
    distCo.at<double>(0,2) = p1; //double p1 = -.009 
    distCo.at<double>(0,3) = p2; //double p2 = -.008 
    distCo.at<double>(0,4) = k3; //double k3 = -.03 

    cv::undistortPoints(src, norm, cameraMatrix, distCo); 

    for (int p = 0; p<newKeyPoints.size(); p++){ 
     printf("%f, %f \n",norm.at<Vec2f>(0,p)[0], norm.at<Vec2f>(0,p)[1]); 
    } 

인쇄 된 값은 항상 "nan, nan"입니다. 나 또한 std :: vector와 같은 norm을 사용하려고 시도했지만, 같은 것을 리턴했다. src, cameraMatrix 및 distCo의 값은 메서드가 호출 된 후에도 변경되지 않으므로 (정확한 값을 출력하여 테스트 한 결과) undistortPoints에 올바른 정보를 모두 제공한다고 확신합니다. 잘못된 형식을 사용하여 cv :: Mat를 잘못 사용하고 있습니까? 아니면 opencv의 버그입니다. 여기에서해야 할 일에 대한 통찰력은 크게 감사하겠습니다. 이삭

답변

2

당신이 당신의 매트릭스는 당신이 cameraMatrix 및 distCo 행렬 모두이 작업을 수행하지 않은

cv::Mat your_matrix(rows,cols,CV_64FC1); 

그것을 선언 할 필요가 배정 밀도 값을 저장하려면

. 현재 64 비트 접근 자로 이러한 배열의 32 비트 요소에 액세스하려고합니다.

+0

정말 고마워요, 당신은 남자입니다 !!!!! – Isaac

관련 문제