[learning opencv]第十章cvGoodFeaturesToTrack的demo

从标题看,相关内容可参阅《learning opencv

本文摘自

http://blog.csdn.net/moc062066/article/details/6634120


[cpp]  view plain copy
  1. void cvGoodFeaturesToTrack(  
  2. const CvArr* image //(8,1) or (32,1) (8-bit ,single-channel) (floating-point 32-bit,single-channel)  
  3. CvArr* eigImage,//(32,1)  
  4. CvArr* tempImage //(32,1)  
  5. CvPoint2D32f* corners  
  6. int* cornerCount  
  7. double qualityLevel  
  8. double minDistance  
  9. const CvArr* mask=NULL  
  10. int blockSize=3  
  11. int useHarris=0  
  12. double k=0.04 );  

[cpp]  view plain copy
  1. corners //是数组,检测到的角点的位置坐标就存在这里  

[cpp]  view plain copy
  1. int* cornerCount //表示最多可以检测到的角点(如果有那么多的话),实际上检测到的点没有那么多,所以调用函数以后,<pre name="code" class="cpp">cornerCount的值就变成实际检测到的角点的数目。因此,在对cornerCount赋初始值的时候,可以给大一点,本文赋初始值为1000。</pre>  

[cpp]  view plain copy
  1. double qualityLevel //理解还不是很好,只知道一般取值是0.10 或者0.01 ,why?谁可以告诉我答案  

[cpp]  view plain copy
  1. minDistance Limit, specifying the minimum possible distance between the returned corners;  
  2. Euclidian distance is used //角点与角点之间的距离不小于minDistance个像素。  

[cpp]  view plain copy
  1. mask Region of interest. The function selects points either in the specified region or in the whole  
  2. image if the mask is NULL //如果mask不为空,则在mask指定的区域内寻找角点;mask为NULL则在整张图像中寻找角点。  

[cpp]  view plain copy
  1. blockSize Size of the averaging block, passed to the underlying cvCornerMinEigenVal or cvCornerHarris used by the function //默认就行了  

[cpp]  view plain copy
  1. useHarris If nonzero, Harris operator ( cvCornerHarris) is used instead of default cvCorner-  
  2. MinEigenVal //非零,就用cvCornerHarris而不是使用默认的cvCornerMinEigenVal。这是函数内部的处理过程。  

[cpp]  view plain copy
  1. k Free parameter of Harris detector; used only if (useHarris! = 0)  



demo代码如下,不解析,很简单

[cpp]  view plain copy
  1. //http://blog.csdn.net/moc062066  
  2. //chinamochen@gmail.com  
  3. //2011年7月26日10:41:54  
  4. //  
  5.   
  6. #include <cv.h>  
  7. #include <highgui.h>  
  8. #include <stdio.h>  
  9.   
  10. #pragma comment(lib, "opencv_core220d.lib")  
  11. #pragma comment(lib, "opencv_highgui220d.lib")  
  12. #pragma comment(lib, "opencv_imgproc220d.lib")  
  13.   
  14. int main(int argc, char *argv[])  
  15. {  
  16.   
  17.     // Load a color image, and convert it into grayscale  
  18.     const char* filename = "D:\\mochen_WIN32\\opencv\\CH10\\good_fearture_to_track_demo\\one_way_train_0001.jpg" ;  
  19.     const char* windowname = "http://blog.csdn.net/moc062066" ;  
  20.   
  21.     IplImage* img = cvLoadImage(filename,CV_LOAD_IMAGE_COLOR);  
  22.     assert( NULL != img ) ;  
  23.     IplImage* img_gray = cvCreateImage(cvGetSize(img), 8, 1);  
  24.     cvCvtColor(img, img_gray, CV_BGR2GRAY);  
  25.   
  26.     // Create temporary images required by cvGoodFeaturesToTrack  
  27.     IplImage* img_temp = cvCreateImage(cvGetSize(img), 32, 1);  
  28.     IplImage* img_eigen = cvCreateImage(cvGetSize(img), 32, 1);  
  29.   
  30.     // Create the array to store the points detected( <= 1000 )  
  31.     int count = 1000;  
  32.     CvPoint2D32f* corners = new CvPoint2D32f[count];  
  33.   
  34.     // Find corners  
  35.     cvGoodFeaturesToTrack(img_gray, img_eigen, img_temp, corners, &count, 0.1, 10);  
  36.   
  37.     // Mark these corners on the original image  
  38.     for(int i=0;i<count;i++)  
  39.     {  
  40.         cvLine(img, cvPoint(corners[i].x, corners[i].y), cvPoint(corners[i].x, corners[i].y), CV_RGB(255,0,0), 5);  
  41.     }  
  42.   
  43.     // Display it  
  44.     cvNamedWindow(windowname);  
  45.     cvShowImage(windowname, img);  
  46.   
  47.     // Print the number of corners  
  48.     printf("Detected Points : %d\n", count);  
  49.   
  50.     cvWaitKey(0);  
  51.   
  52.     return  0 ;  
  53. }  


结果:


实验所用图像:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值