在相机标定中通常首先需要检测出棋盘标定板上黑白格内角点的位置:
网上的一段cvFindChessboardCorners函数调用代码:
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/legacy/legacy.hpp"
using namespace std;
//by Huang, Haiqiao 25 Jun. 2011, fzyhhq@bift.edu.cn
//http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=14214
int main( )
{
cout<<"Draw Chess OpenCV!"<<endl;
char* filename="e:/src2/chess2.bmp";
IplImage* imgRGB = cvLoadImage(filename,1);
IplImage* imgGrey = cvLoadImage(filename,CV_LOAD_IMAGE_GRAYSCALE);
if (imgGrey==NULL){//image validation
cout<< "No valid image input."<<endl;
char c=getchar();
return 1;
}
//-------find chessboard corners--------------
int corner_row=12;//沿着行的内角点数//interior number of row corners.(this can be countered by fingers.)
int corner_col=10;//沿着列的内角点数//interior number of column corners.
int corner_n=corner_row*corner_col;
CvSize pattern_size=cvSize(corner_row,corner_col);
CvPoint2D32f* corners=new CvPoint2D32f[corner_n];
int corner_count;
int found=cvFindChessboardCorners(//returning non-zero means sucess.
imgGrey,// 8-bit single channel greyscale image.
pattern_size,//how many INTERIOR corners in each row and column of the chessboard.
corners,//a pointer to an array where the corner locations can be recorded.
&corner_count,// optional, if non-NULL, its a point to an integer where the nuber of corners found can be recorded.
CV_CALIB_CB_ADAPTIVE_THRESH|CV_CALIB_CB_FILTER_QUADS// check page 382-383.
);
cout<<"corner_count = "<<corner_count;
//-------Draw the corner pattern-------
cvDrawChessboardCorners(
imgRGB,
pattern_size,
corners,
corner_count,
found
);
//to summary a bit of findings.
cout<<endl;
cout<<"found="<<found<<endl;
//显示角点的坐标
//for (int c = 0; c<corner_col; c++)
//{
// cout<<endl;
// for (int r = 0; r<corner_row; r++)
// {
// cout<<"[x="<<corners[c*corner_row+r].x;
// cout<<" y="<<corners[c*corner_row+r].y<<"] ";
// }
//}
//cvNamedWindow("Find and Draw ChessBoard", 0 );//窗口大小可调节
cvShowImage( "Find and Draw ChessBoard", imgRGB );
cvWaitKey(0);
cvReleaseImage(&imgGrey);
cvReleaseImage(&imgRGB);
//cvDestroyWindow("Find and Draw ChessBoard");
return 0;
}
执行结果图:
检测结果存储在corner中,沿着连线的方向,从红色的起始。
原文链接: https://www.cnblogs.com/sunniflyer/p/4556220.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/217278
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!