0

I am trying to use openCV.NET to read scanned forms. The problem is that sometimes the positions of the relevant regions of interest and the alignment may differ depending on the printer it was printed form and the way the user scanned the form.

So I thought I could use an ArUco marker as a reference point as there are libraries (ArUco.NET) already built to recognize them. I was hoping to find out how much the ArUco code is rotated and then rotate the form backwards by that amount to make sure the text is straight. Then I can use the center of the ArUco code as a reference point to use OCR on specific regions on the form.

I am using the following code to get the OpenGL modelViewMatrix. However, it always seems to be the same numbers no matter which angle the ArUco code is rotated. I only just started with all of these libraries but I thought that the modelViewMatrix would give me different values depending on the rotation of the marker. Why would it always be the same?

 Mat cameraMatrix = new Mat(3, 3, Depth.F32, 1);
            Mat distortion = new Mat(1, 4, Depth.F32, 1);
            using (Mat image2 = OpenCV.Net.CV.LoadImageM("./image.tif", LoadImageFlags.Grayscale))
            {
                using (var detector = new MarkerDetector())
                {
                    detector.ThresholdMethod = ThresholdMethod.AdaptiveThreshold;
                    detector.Param1 = 7.0;
                    detector.Param2 = 7.0;
                    detector.MinSize = 0.01f;
                    detector.MaxSize = 0.5f;
                    detector.CornerRefinement = CornerRefinementMethod.Lines;

                    var markerSize = 10;
                    IList<Marker> detectedMarkers = detector.Detect(image2, cameraMatrix, distortion);
                    foreach (Marker marker in detectedMarkers)
                    {

                        Console.WriteLine("Detected a marker top left at: " + marker[0].X + @" " + marker[0].Y);
                        //Upper 3x3 matrix of modelview matrix (0,4,8,1,5,9,2,6,10) is called rotation matrix.
                        double[] modelViewMatrix = marker.GetGLModelViewMatrix();


                    }

                }
            }
Asagohan
  • 583
  • 5
  • 19

1 Answers1

0

It looks like you have not initialized your camera parameters. cameraMatrix and distortion are the intrinsic parameters of your camera. You can use OpenCV to find them.

This is vor OpenCV 2.4 but will help you to understand the basics: http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html

If you have found them you should be able to get the parameters.