亚像素级的角点检测

目标

在本教程中我们将涉及以下内容:

  • 使用OpenCV函数 cornerSubPix 寻找更精确的角点位置 (不是整数类型的位置,而是更精确的浮点类型位置).

理论

代码

这个教程的代码如下所示。源代码还可以从 这个链接下载得到

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace cv; using namespace std; /// Global variables Mat src, src_gray; int maxCorners = 10; int maxTrackbar = 25; RNG rng(12345); char* source_window = "Image"; /// Function header void goodFeaturesToTrack_Demo( int, void* ); /** @function main */ int main( int argc, char** argv ) { /// Load source image and convert it to gray src = imread( argv[1], 1 ); cvtColor( src, src_gray, CV_BGR2GRAY ); /// Create Window namedWindow( source_window, CV_WINDOW_AUTOSIZE ); /// Create Trackbar to set the number of corners createTrackbar( "Max corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo); imshow( source_window, src ); goodFeaturesToTrack_Demo( 0, 0 ); waitKey(0); return(0); } /**  * @function goodFeaturesToTrack_Demo.cpp  * @brief Apply Shi-Tomasi corner detector  */ void goodFeaturesToTrack_Demo( int, void* ) { if( maxCorners < 1 ) { maxCorners = 1; } /// Parameters for Shi-Tomasi algorithm vector<Point2f> corners; double qualityLevel = 0.01; double minDistance = 10; int blockSize = 3; bool useHarrisDetector = false; double k = 0.04; /// Copy the source image Mat copy; copy = src.clone(); /// Apply corner detection goodFeaturesToTrack( src_gray, corners, maxCorners, qualityLevel, minDistance, Mat(), blockSize, useHarrisDetector, k ); /// Draw corners detected cout<<"** Number of corners detected: "<<corners.size()<<endl; int r = 4; for( int i = 0; i < corners.size(); i++ ) { 

转载于:https://www.cnblogs.com/GarfieldEr007/p/5292259.html

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐