| 187 | } |
| 188 | |
| 189 | bool IPLCameraCalibration::runCalibration(std::vector<std::vector<cv::Point2f> > imagePoints, |
| 190 | cv::Size imageSize, cv::Size boardSize, Pattern patternType, |
| 191 | float squareSize, float aspectRatio, |
| 192 | int flags, cv::Mat& cameraMatrix, cv::Mat& distCoeffs, |
| 193 | std::vector<cv::Mat>& rvecs, std::vector<cv::Mat>& tvecs, |
| 194 | std::vector<float>& reprojErrs, |
| 195 | double& totalAvgErr) |
| 196 | { |
| 197 | cameraMatrix = cv::Mat::eye(3, 3, CV_64F); |
| 198 | if( flags & cv::CALIB_FIX_ASPECT_RATIO ) |
| 199 | cameraMatrix.at<double>(0,0) = aspectRatio; |
| 200 | |
| 201 | distCoeffs = cv::Mat::zeros(8, 1, CV_64F); |
| 202 | |
| 203 | std::vector<std::vector<cv::Point3f> > objectPoints(1); |
| 204 | this->calcChessboardCorners(boardSize, squareSize, objectPoints[0], patternType); |
| 205 | |
| 206 | objectPoints.resize(imagePoints.size(),objectPoints[0]); |
| 207 | |
| 208 | double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, |
| 209 | distCoeffs, rvecs, tvecs, flags|cv::CALIB_FIX_K4|cv::CALIB_FIX_K5); |
| 210 | ///*|CALIB_FIX_K3*/|CALIB_FIX_K4|CALIB_FIX_K5); |
| 211 | |
| 212 | bool ok = checkRange(cameraMatrix) && checkRange(distCoeffs); |
| 213 | |
| 214 | totalAvgErr = this->computeReprojectionErrors(objectPoints, imagePoints, |
| 215 | rvecs, tvecs, cameraMatrix, distCoeffs, reprojErrs); |
| 216 | |
| 217 | return ok; |
| 218 | } |
| 219 | |
| 220 | void IPLCameraCalibration::calcChessboardCorners(cv::Size boardSize, float squareSize, std::vector<cv::Point3f>& corners, Pattern patternType) |
| 221 | { |
no test coverage detected