2
我一直在使用opencv,並且我似乎無法使unistortPoints工作。它返回的矩陣只有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」。我也嘗試使用norm作爲std :: vector,但是返回的結果是一樣的。在調用方法(我通過打印出它們的值進行測試)後,src,cameraMatrix和distCo的值也保持不變,所以我確信我正給予unistortPoints所有正確的信息。我是否使用cv :: Mat錯誤地使用了差的表單,或者這是opencv的錯誤。任何有關在這裏做什麼的洞察力將不勝感激。
艾薩克
非常感謝你,你是男人!!!!! – Isaac 2013-03-13 14:57:21