1、角点检测函数和参数说明
cvGoodFeaturesToTrack()函数主要是处理IplImage数据格式的图像,而goodFeaturesToTrack()函数主要是处理Mat数据格式的图像。参数quality_level :特征值最大值最小值乘法因子;参数minDistance:角点之间最小距离;均对图像中harris角点检测的个数有影响。
2、具体代码如下
(1)harris角点检测
#include "opencv2/core/core.hpp" #include "opencv2/flann/miniflann.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/video/video.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/objdetect/objdetect.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/ml/ml.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/contrib/contrib.hpp" #include <iostream> #include <stdio.h> using namespace std; using namespace cv; int main() { //FILE* fp=fopen("E:\\实验室项目\\ImagePro\\GoodFeatures\\result.txt","w+"); //char* filename="E:\\实验室项目\\ImagePro\\GoodFeatures\\j10.jpg"; IplImage* img=cvLoadImage("F22.jpg",CV_LOAD_IMAGE_COLOR); if (!img) { cout<<"读取图像失败!"<<endl; } IplImage* img_copy=cvCloneImage(img); IplImage* img_gray=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); IplImage* eig_img=cvCreateImage(cvGetSize(img),IPL_DEPTH_32F,1); IplImage* temp_img=cvCloneImage(eig_img); cvCvtColor(img,img_gray,CV_BGR2GRAY); const int MAX_CORNERS=1000;//定义角点个数最大值 CvPoint2D32f* corners=new CvPoint2D32f[MAX_CORNERS];//分配保存角点的空间 int corner_count=MAX_CORNERS; double quality_level=0.01;//or 0.01 double min_distance=10; cvGoodFeaturesToTrack(img_gray,eig_img,temp_img,corners,&corner_count,quality_level,min_distance); //画角点 for(int i=0;i<corner_count;i++) { cvCircle(img_copy,cvPoint((int)corners[i].x,(int)corners[i].y),1,CV_RGB(255,0,0),2,8); //fprintf(fp,"\t%f,%f\n",corners[i].x,corners[i].y); } cout<<"检测到角点个数为:"<<corner_count; cvNamedWindow("角点检测",CV_WINDOW_AUTOSIZE); cvShowImage("角点检测",img_copy); cvWaitKey(0); cvReleaseImage(&img); cvReleaseImage(&img_copy); cvReleaseImage(&img_gray); cvReleaseImage(&eig_img); cvReleaseImage(&temp_img); cvDestroyWindow("角点检测"); return 0; }