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 //表示最多可以检测到的角点(如果有那么多的话),实际上检测到的点没有那么多,所以调用函数以后,cornerCount的值就变成实际检测到的角点的数目。因此,在对cornerCount赋初始值的时候,可以给大一点,本文赋初始值为1000。
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 ; }
结果:
实验所用图像: