예제 #1
0
        private double computeReprojectionErrors(List <Mat> objectPoints,
                                                 List <Mat> rvecs, List <Mat> tvecs, Mat perViewErrors)
        {
            MatOfPoint2f cornersProjected = new MatOfPoint2f();
            double       totalError       = 0;
            double       error;

            float[] viewErrors = new float[objectPoints.Count];

            MatOfDouble distortionCoefficients = new MatOfDouble(mDistortionCoefficients);
            int         totalPoints            = 0;

            for (int i = 0; i < objectPoints.Count; i++)
            {
                MatOfPoint3f points = new MatOfPoint3f(objectPoints[i]);
                Calib3d.ProjectPoints(points, rvecs[i], tvecs[i],
                                      mCameraMatrix, distortionCoefficients, cornersProjected);
                error = Core.Norm(mCornersBuffer[i], cornersProjected, Core.NormL2);

                int n = objectPoints[i].Rows();
                viewErrors[i] = (float)Math.Sqrt(error * error / n);
                totalError   += error * error;
                totalPoints  += n;
            }
            perViewErrors.Create(objectPoints.Count, 1, CvType.Cv32fc1);
            perViewErrors.Put(0, 0, viewErrors);

            return(Math.Sqrt(totalError / totalPoints));
        }