| 69 | } |
| 70 | |
| 71 | bool IPLCameraCalibration::processInputData(IPLData* data , int index, bool useOpenCV) |
| 72 | { |
| 73 | _image = data->toImage(); |
| 74 | |
| 75 | // get properties |
| 76 | std::string fileName = getProcessPropertyString("fileName"); |
| 77 | int targetType = getProcessPropertyInt("targetType"); |
| 78 | int targetCols = getProcessPropertyInt("targetCols"); |
| 79 | int targetRows = getProcessPropertyInt("targetRows"); |
| 80 | int skipFrames = getProcessPropertyUnsignedInt("skipFrames"); |
| 81 | |
| 82 | std::stringstream s3; |
| 83 | s3 << "MODE: " << _mode; |
| 84 | addSuccess(s3.str()); |
| 85 | |
| 86 | |
| 87 | |
| 88 | notifyProgressEventHandler(-1); |
| 89 | cv::Mat input; |
| 90 | cv::Mat output = _image->toCvMat(); |
| 91 | cv::cvtColor(_image->toCvMat(), input, CV_BGR2GRAY); |
| 92 | |
| 93 | std::vector<cv::Point2f> pointBuf; |
| 94 | cv::Size boardSize(targetCols, targetRows); |
| 95 | cv::Size imageSize(_image->width(), _image->height()); |
| 96 | std::vector<std::vector<cv::Point3f>> objectPoints(1); |
| 97 | cv::Mat cameraMatrix = cv::Mat::eye(3, 3, CV_64F); |
| 98 | cv::Mat distCoeffs = cv::Mat::zeros(8, 1, CV_64F); |
| 99 | std::vector<cv::Mat> rvecs, tvecs; |
| 100 | std::vector<float> reprojErrs; |
| 101 | double totalAvgErr = 0; |
| 102 | |
| 103 | |
| 104 | if(_mode == CALIBRATED) |
| 105 | { |
| 106 | std::stringstream s2; |
| 107 | s2 << "totalAvgErr: "; |
| 108 | s2 << totalAvgErr; |
| 109 | addInformation(s2.str()); |
| 110 | |
| 111 | addSuccess("Calibration successful."); |
| 112 | } |
| 113 | |
| 114 | // skip a few frames when using a camera |
| 115 | if(_frameCounter < skipFrames) |
| 116 | { |
| 117 | delete _preview; |
| 118 | _preview = new IPLImage(*_image); |
| 119 | _frameCounter++; |
| 120 | return true; |
| 121 | } |
| 122 | _frameCounter = 0; |
| 123 | |
| 124 | if(_mode == DETECTION) |
| 125 | { |
| 126 | bool found; |
| 127 | switch(targetType) // Find feature points on the input format |
| 128 | { |