從標題看,相關內容可參閱《learning opencv》
本文摘自
http://blog.csdn.net/moc062066/article/details/6634120
- void cvGoodFeaturesToTrack(
- const CvArr* image //(8,1) or (32,1) (8-bit ,single-channel) (floating-point 32-bit,single-channel)
- CvArr* eigImage,//(32,1)
- CvArr* tempImage //(32,1)
- CvPoint2D32f* corners
- int* cornerCount
- double qualityLevel
- double minDistance
- const CvArr* mask=NULL
- int blockSize=3
- int useHarris=0
- double k=0.04 );
- corners //是數組,檢測到的角點的位置座標就存在這裏
- int* cornerCount //表示最多可以檢測到的角點(如果有那麼多的話),實際上檢測到的點沒有那麼多,所以調用函數以後,<pre name="code" class="cpp">cornerCount的值就變成實際檢測到的角點的數目。因此,在對cornerCount賦初始值的時候,可以給大一點,本文賦初始值爲1000。</pre>
- double qualityLevel //理解還不是很好,只知道一般取值是0.10 或者0.01 ,why?誰可以告訴我答案
- minDistance Limit, specifying the minimum possible distance between the returned corners;
- Euclidian distance is used //角點與角點之間的距離不小於minDistance個像素。
- mask Region of interest. The function selects points either in the specified region or in the whole
- image if the mask is NULL //如果mask不爲空,則在mask指定的區域內尋找角點;mask爲NULL則在整張圖像中尋找角點。
- blockSize Size of the averaging block, passed to the underlying cvCornerMinEigenVal or cvCornerHarris used by the function //默認就行了
- useHarris If nonzero, Harris operator ( cvCornerHarris) is used instead of default cvCorner-
- MinEigenVal //非零,就用cvCornerHarris而不是使用默認的cvCornerMinEigenVal。這是函數內部的處理過程。
- k Free parameter of Harris detector; used only if (useHarris! = 0)
demo代碼如下,不解析,很簡單
- //http://blog.csdn.net/moc062066
- //[email protected]
- //2011年7月26日10:41:54
- //
- #include <cv.h>
- #include <highgui.h>
- #include <stdio.h>
- #pragma comment(lib, "opencv_core220d.lib")
- #pragma comment(lib, "opencv_highgui220d.lib")
- #pragma comment(lib, "opencv_imgproc220d.lib")
- int main(int argc, char *argv[])
- {
- // Load a color image, and convert it into grayscale
- const char* filename = "D:\\mochen_WIN32\\opencv\\CH10\\good_fearture_to_track_demo\\one_way_train_0001.jpg" ;
- const char* windowname = "http://blog.csdn.net/moc062066" ;
- IplImage* img = cvLoadImage(filename,CV_LOAD_IMAGE_COLOR);
- assert( NULL != img ) ;
- IplImage* img_gray = cvCreateImage(cvGetSize(img), 8, 1);
- cvCvtColor(img, img_gray, CV_BGR2GRAY);
- // Create temporary images required by cvGoodFeaturesToTrack
- IplImage* img_temp = cvCreateImage(cvGetSize(img), 32, 1);
- IplImage* img_eigen = cvCreateImage(cvGetSize(img), 32, 1);
- // Create the array to store the points detected( <= 1000 )
- int count = 1000;
- CvPoint2D32f* corners = new CvPoint2D32f[count];
- // Find corners
- cvGoodFeaturesToTrack(img_gray, img_eigen, img_temp, corners, &count, 0.1, 10);
- // Mark these corners on the original image
- for(int i=0;i<count;i++)
- {
- cvLine(img, cvPoint(corners[i].x, corners[i].y), cvPoint(corners[i].x, corners[i].y), CV_RGB(255,0,0), 5);
- }
- // Display it
- cvNamedWindow(windowname);
- cvShowImage(windowname, img);
- // Print the number of corners
- printf("Detected Points : %d\n", count);
- cvWaitKey(0);
- return 0 ;
- }
結果:
實驗所用圖像: