opencv實(shí)現(xiàn)棋盤格檢測
本文實(shí)例為大家分享了opencv實(shí)現(xiàn)棋盤格檢測的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
#include <iostream> #include <vector> #include <opencv2/opencv.hpp> ? #include <opencv2/xfeatures2d.hpp> #include <opencv2/optflow/motempl.hpp> using namespace cv; ? using namespace std; /* 棋盤格角點(diǎn)檢測應(yīng)用 */ ? int main() { ?? ?//*********************************** ?1 ?**************************************************************** ?? ?/*Mat img = imread("C:\\Users\\H\\Desktop\\13.png", IMREAD_GRAYSCALE); ?? ?vector<Point2f> 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); ?? ?//定義存儲(chǔ)角點(diǎn)的容器 ?? ?vector<Point2f> corners; ?? ?//進(jìn)行角點(diǎn)檢測 ?? ?bool ret = findChessboardCorners(image_gray, ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?Size(5, 7), // 棋盤格每列點(diǎn)數(shù)和每一行點(diǎn)數(shù) ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?corners, ? ?// 輸出檢測到角點(diǎn)的數(shù)組 ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?CALIB_CB_ADAPTIVE_THRESH | ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?CALIB_CB_NORMALIZE_IMAGE); ? ?? ?//指定亞像素計(jì)算迭代標(biāo)注 ?? ?TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?40, ? // 要計(jì)算的最大迭代次數(shù)或元素?cái)?shù) ?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?0.1); // 迭代算法停止時(shí)所需的精度或參數(shù)變化 ?? ?//亞像素檢測 ?? ?cornerSubPix(image_gray,? ?? ??? ??? ??? ??? ?corners,? ?? ??? ??? ??? ??? ?Size(5, 5), //搜索窗口大小 ?? ??? ??? ??? ??? ?Size(-1, -1),? ?? ??? ??? ??? ??? ?criteria); ?? ?//角點(diǎn)繪制 ?? ?drawChessboardCorners(src, ?? ??? ??? ??? ??? ??? ??? ?Size(5, 7), //棋盤格每列點(diǎn)數(shù)和每一行點(diǎn)數(shù) ?? ??? ??? ??? ??? ??? ??? ?corners,? ?? ??? ??? ??? ??? ??? ??? ?ret); ?? ?cout << "corner: " << corners << endl; ? ?? ?//在原圖中繪制點(diǎn) ?? ?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; }
結(jié)果展示:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C語言中結(jié)構(gòu)體struct編寫的一些要點(diǎn)解析
這篇文章主要介紹了C語言中結(jié)構(gòu)體struct編寫的一些要點(diǎn)解析,談到了結(jié)構(gòu)體的聲明和指針指向等重要知識(shí)點(diǎn),需要的朋友可以參考下2016-04-04VC++實(shí)現(xiàn)輸出GIF到窗體并顯示GIF動(dòng)畫的方法
這篇文章主要介紹了VC++實(shí)現(xiàn)輸出GIF到窗體并顯示GIF動(dòng)畫的方法,需要的朋友可以參考下2014-07-07詳解C++中二進(jìn)制求補(bǔ)運(yùn)算符與下標(biāo)運(yùn)算符的用法
這篇文章主要介紹了C++中二進(jìn)制求補(bǔ)運(yùn)算符與下標(biāo)運(yùn)算符的用法,是C++入門學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2016-01-01數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組翻轉(zhuǎn)的實(shí)現(xiàn)方法
這篇文章主要介紹了數(shù)據(jù)結(jié)構(gòu)之?dāng)?shù)組翻轉(zhuǎn)的實(shí)現(xiàn)方法的相關(guān)資料,這里用幾種實(shí)現(xiàn)方法來實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10