bool Calibration::calibrate() { if(size() < 1) { ofLog(OF_LOG_ERROR, "Calibration::calibrate() doesn't have any image data to calibrate from."); if(ready) { ofLog(OF_LOG_ERROR, "Calibration::calibrate() doesn't need to be called after Calibration::load()."); } return ready; } Mat cameraMatrix = Mat::eye(3, 3, CV_64F); distCoeffs = Mat::zeros(8, 1, CV_64F); updateObjectPoints(); int calibFlags = 0; float rms = calibrateCamera(objectPoints, imagePoints, addedImageSize, cameraMatrix, distCoeffs, boardRotations, boardTranslations, calibFlags); ofLog(OF_LOG_VERBOSE, "calibrateCamera() reports RMS error of " + ofToString(rms)); ready = checkRange(cameraMatrix) && checkRange(distCoeffs); if(!ready) { ofLog(OF_LOG_ERROR, "Calibration::calibrate() failed to calibrate the camera"); } distortedIntrinsics.setup(cameraMatrix, addedImageSize); updateReprojectionError(); updateUndistortion(); return ready; }
bool Calibration::load(string filename, bool absolute) { imagePoints.clear(); //FileStorage fs(ofToDataPath(filename, absolute), FileStorage::READ); FileStorage fs(filename, FileStorage::READ); if (!fs.isOpened()) return false; cv::Size imageSize, sensorSize; Mat cameraMatrix; fs["cameraMatrix"] >> cameraMatrix; fs["imageSize_width"] >> imageSize.width; fs["imageSize_height"] >> imageSize.height; fs["sensorSize_width"] >> sensorSize.width; fs["sensorSize_height"] >> sensorSize.height; fs["distCoeffs"] >> distCoeffs; fs["reprojectionError"] >> reprojectionError; FileNode features = fs["features"]; for(FileNodeIterator it = features.begin(); it != features.end(); it++) { vector<Point2f> cur; (*it) >> cur; imagePoints.push_back(cur); } addedImageSize = imageSize; distortedIntrinsics.setup(cameraMatrix, imageSize, sensorSize); updateUndistortion(); ready = true; return true; }
void Calibration::setIntrinsics(Intrinsics& distortedIntrinsics, Mat& distortionCoefficients){ this->distortedIntrinsics = distortedIntrinsics; this->distCoeffs = distortionCoefficients; this->addedImageSize = distortedIntrinsics.getImageSize(); updateUndistortion(); this->ready = true; }
void Calibration::load(string filename, bool absolute) { FileStorage fs(ofToDataPath(filename, absolute), FileStorage::READ); cv::Size imageSize, sensorSize; Mat cameraMatrix; fs["cameraMatrix"] >> cameraMatrix; fs["imageSize_width"] >> imageSize.width; fs["imageSize_height"] >> imageSize.height; fs["sensorSize_width"] >> sensorSize.width; fs["sensorSize_height"] >> sensorSize.height; fs["distCoeffs"] >> distCoeffs; fs["reprojectionError"] >> reprojectionError; distortedIntrinsics.setup(cameraMatrix, imageSize, sensorSize); updateUndistortion(); _isReady = true; }