OpenCV:goodFeaturesToTrack角点检测的应用( 二 )


法式:
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\core\core.hpp>
using namespace std; 
using namespace cv; 
int main()
{
       Mat image_color = imread("Lighthouse.jpg", 1);  
       Mat image_gray; 
       cvtColor(image_color, image_gray, COLOR_BGR2GRAY); 
      
       //设置角点检测参数 
       vector<Point2f> corners; 
       int max_corners = 500; 
       double quality_level = 0.01; 
       double min_distance = 3.0; 
       int block_size = 3; 
       bool use_harris = false; 
       double k = 0.04; 
       goodFeaturesToTrack(image_gray,  
                             corners,  
                             max_corners,  
                             quality_level,  
                             min_distance,  
                                      Mat(),  
                                      block_size,  
                                      use_harris,  
                                      k); 
       //将检测到的角点绘制到原图上 
       for (int i = 0; i < corners.size(); i++) 
       { 
              circle(image_color, corners[i], 1, Scalar(0, 0, 255), 2, 8, 0); 
       }
       namedWindow("house corner",CV_WINDOW_NORMAL);
       imshow("house corner", image_color); 
       waitKey(0); 
       return 0; 
}

OpenCV:goodFeaturesToTrack角点检测的应用

文章插图

3cornerSubPix()格局

推荐阅读