首页 > 代码库 > OpenCV Tutorials —— Shi-Tomasi corner detector
OpenCV Tutorials —— Shi-Tomasi corner detector
Shi-Tomasi 算法是Harris 算法的改进。
Harris 算法最原始的定义是将矩阵 M 的行列式值与 M 的迹相减,再将差值同预先给定的阈值进行比较。后来Shi 和Tomasi 提出改进的方法,若两个特征值中较小的一个大于最小阈值,则会得到强角点。
void goodFeaturesToTrack(InputArray image, OutputArray corners, int maxCorners, double qualityLevel, doubleminDistance, InputArray mask=noArray(), int blockSize=3, bool useHarrisDetector=false, double k=0.04 )
Parameters:
- image – Input 8-bit or floating-point 32-bit, single-channel image.
- corners – Output vector of detected corners.
- maxCorners – Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned.
- qualityLevel – Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see cornerMinEigenVal() ) or the Harris function response (see cornerHarris() ). The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure less than 15 are rejected.
- minDistance – Minimum possible Euclidean distance between the returned corners.
- mask – Optional region of interest. If the image is not empty (it needs to have the type CV_8UC1and the same size as image ), it specifies the region in which the corners are detected.
- blockSize – Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See cornerEigenValsAndVecs() .
- useHarrisDetector – Parameter indicating whether to use a Harris detector (see cornerHarris()) or cornerMinEigenVal().
- k – Free parameter of the Harris detector.
论文看过之后过来补充 ~~
Code
#include "stdafx.h"#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 variablesMat src, src_gray;int maxCorners = 23;int maxTrackbar = 100;RNG rng(12345);char* source_window = "Image";/// Function headervoid goodFeaturesToTrack_Demo( int, void* );/** * @function main */int main( int argc, char** argv ){ /// Load source image and convert it to gray src = http://www.mamicode.com/imread("xue.jpg", 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++ ) { circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255), rng.uniform(0,255)), -1, 8, 0 ); } /// Show what you got namedWindow( source_window, CV_WINDOW_AUTOSIZE ); imshow( source_window, copy );}
OpenCV Tutorials —— Shi-Tomasi corner detector
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。