| 239 | } |
| 240 | |
| 241 | double IPLCameraCalibration::computeReprojectionErrors( |
| 242 | const std::vector<std::vector<cv::Point3f> >& objectPoints, |
| 243 | const std::vector<std::vector<cv::Point2f> >& imagePoints, |
| 244 | const std::vector<cv::Mat>& rvecs, const std::vector<cv::Mat>& tvecs, |
| 245 | const cv::Mat& cameraMatrix, const cv::Mat& distCoeffs, |
| 246 | std::vector<float>& perViewErrors ) |
| 247 | { |
| 248 | std::vector<cv::Point2f> imagePoints2; |
| 249 | int i, totalPoints = 0; |
| 250 | double totalErr = 0, err; |
| 251 | perViewErrors.resize(objectPoints.size()); |
| 252 | |
| 253 | for( i = 0; i < (int)objectPoints.size(); i++ ) |
| 254 | { |
| 255 | projectPoints(cv::Mat(objectPoints[i]), rvecs[i], tvecs[i], |
| 256 | cameraMatrix, distCoeffs, imagePoints2); |
| 257 | err = cv::norm(cv::Mat(imagePoints[i]), cv::Mat(imagePoints2), cv::NORM_L2); |
| 258 | int n = (int)objectPoints[i].size(); |
| 259 | perViewErrors[i] = (float)std::sqrt(err*err/n); |
| 260 | totalErr += err*err; |
| 261 | totalPoints += n; |
| 262 | } |
| 263 | |
| 264 | return std::sqrt(totalErr/totalPoints); |
| 265 | } |
| 266 | /* |
| 267 | static void IPLCameraCalibration::saveCameraParams( const string& filename, |
| 268 | Size imageSize, Size boardSize, |
no test coverage detected