角点检测 c语言 棋盘格,EmguCV 中检测棋盘格角点的方法 FindChessboardCorners

EmguCV中封装了直接用于棋盘格角点检测的方法FindChessboardCorners,返回的结果具有顺序性,不必再对角点进行排序。

配合亚像素点的检测可以得到用于相机标定的棋盘格角点的图像坐标。

下面一段代码是winform程序中的一按钮单击事件,点击该按钮所做的操作是提出输入图像中的棋盘格角点,并叠加显示在图像上。

private void simpleButton_FindChessboardCorners_Click(object sender, EventArgs e)

{

Image img = (Image)imageBox_Ori.Image;

Image ImgGray = img.Convert();

corners = CameraCalibration.FindChessboardCorners(ImgGray, patternSize,

CALIB_CB_TYPE.ADAPTIVE_THRESH

//| CALIB_CB_TYPE.FILTER_QUADS

// CALIB_CB_TYPE.NORMALIZE_IMAGE

//CALIB_CB_TYPE.DEFAULT

);

if (corners != null) //chess board found

{

//make mesurments more accurate by using FindCornerSubPixel

ImgGray.FindCornerSubPix(new PointF[1][] { corners }, new Size(11, 11), new Size(-1, -1), new MCvTermCriteria(30, 0.1));

//fill line colour array

Random R = new Random();

for (int i = 0; i < corners.Length; i++)

{

line_colour_array[i] = new Bgr(R.Next(0, 255), R.Next(0, 255), R.Next(0, 255));

}

//dram the results

img.Draw(new CircleF(corners[0], 3), new Bgr(Color.Yellow), 1);

for (int i = 1; i < corners.Length; i++)

{

img.Draw(new LineSegment2DF(corners[i - 1], corners[i]), line_colour_array[i], 2);

img.Draw(new CircleF(corners[i], 5), new Bgr(Color.Yellow), 2);

}

//corners_points_list[0] = corners;

imageBox_Ori.Refresh();

}

}

如输入图像如下图所示:

0818b9ca8b590ca3270a3433284dd417.png

则 patternSize 设置如下:

const int width = 9; //width of chessboard no. squares in width - 1

const int height = 6; // heght of chess board no. squares in heigth - 1

Size patternSize = new Size(width, height); //size of chess board to be detected

运行后,显示结果如下图所示:

0818b9ca8b590ca3270a3433284dd417.png

你可能感兴趣的:(角点检测,c语言,棋盘格)