How to use FindChessboardCorners

I am using the new EmguCV 3.0.0 alpha to detect a checkerboard with a webcam and have a problem understanding with the angle matrix.

        Size patternSize = new Size(5, 4);
        Matrix<float> corners = new Matrix<float>(1, 2);

        bool find = CvInvoke.FindChessboardCorners(grayFrame, patternSize, corners, CalibCbType.AdaptiveThresh | CalibCbType.FilterQuads);
        CvInvoke.DrawChessboardCorners(grayFrame, patternSize, corners, find);
        if (find)
        {
            Console.Write(corners.Size);
        }

The chessboard will be detected and displayed correctly!

But how big should the size of the matrix of angles be and how do I extract angular positions?

All the samples I found on the Internet use older versions of EmguCV, and now there is a completely different syntax. I would use an older version, but the new alpha is much faster, and time is a big problem in my application.

+4
source share
1 answer

CvInvoke.FindChessboardCornersThe method has this signature 1 :

public static bool FindChessboardCorners(
    IInputArray image,
    Size patternSize,
    IOutputArray corners,
    CalibCbType flags = CalibCbType.Default|CalibCbType.AdaptiveThresh|CalibCbType.NormalizeImage
)

IOutputArray 2. , /, , .

, Matrix ( CvArray), , , . CvInvoke.FindChessboardCorners ( ). googled , IOutputArray VectorOfPoints. , , Matrix.

, , .

:

public class Calibration
{
    static void Main(string[] args)
    {
        // chessboard pattern size
        Size patternSize = new Size(9, 7);

        // for each image, have one Image object and one VectorOfPoints
        // for many images have a List of each
        List<VectorOfPoint> corners = new List<VectorOfPoint>();
        List<Image<Gray, Byte>> images = new List<Image<Gray, byte>>();

        // get paths to image files
        string[] imageFiles = Directory.GetFiles(@"C:\your\directory", "*.jpg");

        // for every image
        foreach (string imageFile in imageFiles)
        {
            // create new image object from file path
            var image = new Image<Gray, byte>(imageFile);
            images.Add(image);

            // create new list of corner points
            var cornerPoints = new VectorOfPoint();
            corners.Add(cornerPoints);

            // find chessboard corners
            bool result = CvInvoke.FindChessboardCorners(image, patternSize, cornerPoints);

            // some debug output
            Console.WriteLine("=== " + Path.GetFileName(imageFile) + " === " + result);

            if (!result)
            {
                continue;
            }

            // list points
            foreach (Point cornerPoint in cornerPoints.ToArray())
            {
                Console.WriteLine(cornerPoint.X + ", " + cornerPoint.Y);
            }
        }

        Console.ReadLine();
    }
}

- CvInvoke.DrawChessboardCorners . . Console, :

enter image description here

, .

TL;DR

, IOutputArray, VectorOfPoints.


1 , , , , "".

2 , - !

+4

All Articles