opencv之灰度圖強角點檢測
阿新 • • 發佈:2019-02-12
本文需要了解的庫函式:
void cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, CvArr* temp_image,
CvPoint2D32f* corners, int* corner_count,
double quality_level, double min_distance,
const CvArr* mask=NULL );
演示程式碼
#include<cv.h> #include<highgui.h> #include<stdio.h> #include<malloc.h> #pragma comment(lib,"cv.lib") #pragma comment(lib,"cxcore.lib") #pragma comment(lib,"highgui.lib") #pragma comment(lib,"cvaux.lib") /******************************************************************************** * * * 本程式是強角點檢測演示例程 * 作者:xlh145 * 部落格:http://blog.csdn.net/xlh145/ * * ********************************************************************************/ IplImage * image =NULL; IplImage * gray =NULL; IplImage * dist =NULL; //顯示影象 //下面是兩幅檢測角點的臨時影象 IplImage * eig_image =NULL; IplImage * temp_image =NULL; int quality_level=0; //最小質量因子 int min_distance = 40;//角點間的最小歐氏距離 void OnTrack(int ) { cvZero(dist);//清空影象 cvCopy(image,dist);//拷貝原始資料 CvPoint2D32f corners[200];//儲存角點座標 最大檢測200個點 int count=200;//角點座標 double level = (double)quality_level/100+0.02; double distance = (double)min_distance; cvGoodFeaturesToTrack(gray,eig_image,temp_image, corners,&count,level,distance,NULL); //角點檢測 for(int i=0;i<count;i++) { CvPoint center; center.x = cvRound(corners[i].x); center.y = cvRound(corners[i].y); cvCircle(dist,center,5,CV_RGB(255,0,0),1,8,0); } cvShowImage("角點",dist); } int main() { image = cvLoadImage("2.jpg",1); //載入 dist = cvCloneImage(image); gray = cvCreateImage(cvGetSize(image),IPL_DEPTH_8U,1); eig_image = cvCreateImage(cvGetSize(image),IPL_DEPTH_32F,1); temp_image = cvCreateImage(cvGetSize(image),IPL_DEPTH_32F,1); cvCvtColor(image,gray,CV_BGR2GRAY); //灰度轉換 cvNamedWindow("角點",1); cvCreateTrackbar("quality_level","角點",&quality_level,100,OnTrack); cvCreateTrackbar("min_distance","角點",&min_distance,200,OnTrack); OnTrack(0); cvWaitKey(0); //釋放資料 cvReleaseImage(&image); cvReleaseImage(&dist); cvReleaseImage(&gray); cvReleaseImage(&eig_image); cvReleaseImage(&temp_image); cvDestroyWindow("角點"); return 0; }