opencv之棋盘格检测

代码:

#include 
#include 
#include   
#include 
#include 
using namespace cv;  
using namespace std;
/*
棋盘格角点检测应用
*/

int main()
{
	//***********************************  1  ****************************************************************
	/*Mat img = imread("C:\\Users\\H\\Desktop\\13.png", IMREAD_GRAYSCALE);
	vector corner;
	bool result = findChessboardCorners(img, Size(5, 7), corner, CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE);
	cornerSubPix(img, corner, Size(11, 11), Size(-1, -1), TermCriteria(TermCriteria::EPS | TermCriteria::MAX_ITER, 20, 0.03));
	drawChessboardCorners(img, Size(5, 7), corner, result);
	imshow("src", img);*/
	//**********************************************************************************************************


	// **********************************  2  **************************************************
	//读入图像
	Mat src = imread("C:\\Users\\H\\Desktop\\13.png", IMREAD_COLOR);
	Mat image_gray;
	cvtColor(src, image_gray, COLOR_BGR2GRAY);
	//定义存储角点的容器
	vector corners;
	//进行角点检测
	bool ret = findChessboardCorners(image_gray,
										Size(5, 7), // 棋盘格每列点数和每一行点数
										corners,    // 输出检测到角点的数组
										CALIB_CB_ADAPTIVE_THRESH |
										CALIB_CB_NORMALIZE_IMAGE);

	//指定亚像素计算迭代标注
	TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS,
										40,   // 要计算的最大迭代次数或元素数
										0.1); // 迭代算法停止时所需的精度或参数变化
	//亚像素检测
	cornerSubPix(image_gray, 
					corners, 
					Size(5, 5), //搜索窗口大小
					Size(-1, -1), 
					criteria);
	//角点绘制
	drawChessboardCorners(src,
							Size(5, 7), //棋盘格每列点数和每一行点数
							corners, 
							ret);
	cout << "corner: " << corners << endl;

	//在原图中绘制点
	Point pt;
	pt.x = corners[9].x;
	pt.y = corners[9].y;
	circle(src, pt, 4, Scalar(0, 255, 0),-1);

	imshow("chessboard corners", src);
	// ****************************************************************************************

	waitKey(0);

	return 0;
}

结果展示:

opencv之棋盘格检测_第1张图片

 

你可能感兴趣的:(javascript,html,c#)