// Taken from http://docs.opencv.org/3.0-beta/doc/tutorials/calib3d/camera_calibration/camera_calibration.html float computeReprojectionErrors(List <Mat> objectPoints, List <Mat> imagePoints, List <Mat> rvecs, List <Mat> tvecs, Mat cameraMatrix, Mat distCoeffs, List <float> perViewErrors) { MatOfPoint2f imagePoints2 = new MatOfPoint2f(); int i, totalPoints = 0; float totalErr = 0, err; int numItems = objectPoints.Count; for (i = 0; i < numItems; ++i) { MatOfPoint3f objectPointsi = new MatOfPoint3f(objectPoints[i]); MatOfPoint2f imagePointsi = new MatOfPoint2f(imagePoints[i]); MatOfDouble distCoeffsv2 = new MatOfDouble(distCoeffs); Calib3d.projectPoints(objectPointsi, rvecs[i], tvecs[i], cameraMatrix, distCoeffsv2, imagePoints2); err = norml2(imagePointsi, imagePoints2); // difference Size temp = objectPoints[i].size(); int n = (int)temp.height; perViewErrors.Add(Mathf.Sqrt(err * err / (n))); // save for this view totalErr += err * err; // sum it up totalPoints += (int)n; } return(Mathf.Sqrt(totalErr / totalPoints)); // calculate the arithmetical mean }