当前位置:网站首页>(8) HS corner detection
(8) HS corner detection
2022-07-03 17:45:00 【Hengyoucheng】
1. The basic theory
When processing feature descriptors suitable for multiple images , There are two main feature detection methods , One is angle based detection , The other is to process all areas in the image . Here we mainly discuss angle based detection .
1988 year ,Harris and Stephens An angle detection algorithm is proposed , HS Angle detector , See paper A Combined Corner and Edge Detector.
HS The principle of the detector is as follows , There are three cases of gray changes ,1 Is that the gray level does not change in all directions , 2 It changes in a certain direction , But in the other direction, the grayscale remains unchanged ,3 It's a change in both directions .HS The angle detector uses mathematical formulas to distinguish these three situations .

f Represents an image ,f(s, t) By (s, t) A small piece of image defined by the value of patch,f(s+x, t+y) Is the same size but moved (x,y) Small image of patch, The weighted sum of the squares of the differences between the pixel values of each pixel of the two image blocks is expressed as :
C ( x , y ) = ∑ ∑ ω ( s , t ) [ f ( s + x , t + y ) − f ( s , t ) ] 2 C(x,y) = \sum\sum\omega(s,t)[f(s+x, t+y)-f(s,t)]^2 C(x,y)=∑∑ω(s,t)[f(s+x,t+y)−f(s,t)]2
ω ( s , t ) \omega(s,t) ω(s,t) Is a weighting function . Where there are corners , namely C(x,y) Taking the maximum . Take a pixel , Calculate in its adjacent pixels C ( x , y ) C(x,y) C(x,y).
take f ( s + x , t + y ) f(s+x, t+y) f(s+x,t+y) Represents the approximation of Taylor expansion ,
f ( s + x , t + y ) ≈ f ( s , t ) + x f x ( s , t ) + y f y ( s , t ) f(s+x, t+y)\approx f(s,t)+xf_x(s,t)+yf_y(s,t) f(s+x,t+y)≈f(s,t)+xfx(s,t)+yfy(s,t)
then :
C ( x , y ) = ∑ ∑ ω ( s , t ) [ x f x ( s , t ) + y f y ( s , t ) ] 2 C(x,y) = \sum\sum\omega(s,t)[xf_x(s,t)+yf_y(s,t)]^2 C(x,y)=∑∑ω(s,t)[xfx(s,t)+yfy(s,t)]2
The above equation can be expressed in matrix form :
C ( x , y ) = [ x , y ] M [ x y ] C(x,y) = [x,y]M\begin{bmatrix} x\\ y \end{bmatrix} C(x,y)=[x,y]M[xy]
among ,
M = ∑ ∑ ω ( s , t ) A M = \sum\sum\omega(s,t)A M=∑∑ω(s,t)A
A = [ f x 2 f x f y f x f y f y 2 ] A = \begin{bmatrix} f_x^2 & f_xf_y\\ f_xf_y & f_y^2 \end{bmatrix} A=[fx2fxfyfxfyfy2]
M M M Sometimes called Harris matrix .
matrix M M M The feature vector of points to the largest data expansion direction , And the corresponding eigenvalue is directly proportional to the amount of data expansion in the direction of the eigenvector . So we can know , Two small eigenvalues represent almost constant grayscale , A small eigenvalue and a large eigenvalue indicate the existence of a vertical or horizontal boundary , Two large eigenvalues indicate the existence of an isolated point or angle .
However , Because the computation cost of solving eigenvalues is large ,HS The angle detector does not use eigenvalues , Instead, it makes use of the properties of the square matrix , The trace is equal to the sum of the eigenvalues of the matrix , The determinant is equal to the product of eigenvalues ,
R = λ x λ y − k ( λ x + λ y ) 2 = d e t ( M ) − k t r a c e 2 ( M ) R=\lambda_x\lambda_y - k(\lambda_x + \lambda_y)^2=det(M)-ktrace^2(M) R=λxλy−k(λx+λy)2=det(M)−ktrace2(M)

k k k It's a constant , Usually take ( 0 , 0.25 ) (0, 0.25) (0,0.25).
When both eigenvalues are large , R Take the larger positive value , A larger eigenvalue and a smaller eigenvalue ,R Take a larger negative value , Both eigenvalues are small ,R The absolute value of is small
k It can be regarded as a sensitive factor ,k The smaller, the more corners you find
Shi-Tomasi Corner detector
1994 year ,Jianbo Shi and Carlo Tomasi Put forward Good features to track
Use it directly R = m i n ( λ x , λ y ) R=min(\lambda_x,\lambda_y) R=min(λx,λy) As a measure , Super parameters are avoided k k k
2.OpenCV API
2.1cornerHarris
void cv::cornerHarris(
InputArray src,
OutputArray dst,
int blockSize,
int ksize,
double k,
int borderType = BORDER_DEFAULT
)
src: Input ,8 Bit single channel image , grayscaledst: StorageHarrisData of test results , data typeCV_32FC1blockSize: CalculationC(x,y)Size of time neighborhoodksize: UseSobelWhen the operator calculates the gradient , The size of the convolution kernelk: CalculationRSuper parameter of time , That is, the mediation factor of the sensitivity of the detection angle , Small makes many angles , The bigger the horn, the lessborderType: How to deal with boundary pixels
2.2 goodFeaturesToTrack
void cv::goodFeaturesToTrack (
InputArray image,
OutputArray corners,
int maxCorners,
double qualityLevel,
double minDistance,
InputArray mask = noArray(),
int blockSize = 3,
bool useHarrisDetector = false,
double k = 0.04
)
What this function does ,
1. First use cornerHarris Calculate the measurement of each corner
2. In each pixel 3x3 The neighborhood range of performs maximum suppression
3. Each corner corresponds to Harris The minimum eigenvalue of the matrix is less than q u a l i t y L e v e l ∗ m a x ( q u a l i t y M e a s u r e M a p ( x , y ) ) qualityLevel*max(qualityMeasureMap(x,y)) qualityLevel∗max(qualityMeasureMap(x,y)), This corner will be discarded
4. According to quality measure Descending order
5. Remove those with distances less than maxDistance The corner of
image: Single channel imagecorners: The output vector of the anglemaxCorners: The maximum number of detected corners is supportedqualityLevel: Control the quality level of the angle , For example, the best is1500,qualityLevelby0.01, bequality measureLess than1500*0.01What you want will be abandonedminDistance: The minimum distance between cornersmask: Mask , Controls which part of the image to detect cornersblockSize: The neighborhood size used in calculating the gradient correlation matrix , Reference resources cornerEigenValsAndVecsuseHarrisDetector: Whether to useHarrisCorner detectionk:HarrisSuper parameter of corner detection
3. Example
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
using namespace cv;
using namespace std;
Mat src, src_gray;
int maxCorners = 23;
int maxTrackbar = 100;
RNG rng(12345);
int thresh = 200;
int max_thresh = 255;
const char* source_window = "Source image";
const char* corners_window = "Corners detected";
void cornerHarris_demo( int, void* );
void goodFeaturesToTrack_Demo( int, void* );
int main( int argc, char** argv )
{
CommandLineParser parser( argc, argv, "{@input | building.jpg | input image}" );
src = imread( samples::findFile( parser.get<String>( "@input" ) ) );
if ( src.empty() )
{
cout << "Could not open or find the image!\n" << endl;
cout << "Usage: " << argv[0] << " <Input image>" << endl;
return -1;
}
cvtColor( src, src_gray, COLOR_BGR2GRAY );
namedWindow( source_window );
createTrackbar( "Threshold: ", source_window, &thresh, max_thresh, cornerHarris_demo );
imshow( source_window, src );
// cornerHarris_demo( 0, 0 );
goodFeaturesToTrack_Demo( 0, 0 );
waitKey();
return 0;
}
void cornerHarris_demo( int, void* )
{
int blockSize = 2;
int apertureSize = 3;
double k = 0.04;
Mat dst = Mat::zeros( src.size(), CV_32FC1 );
cornerHarris( src_gray, dst, blockSize, apertureSize, k );
Mat dst_norm, dst_norm_scaled;
normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
convertScaleAbs( dst_norm, dst_norm_scaled );
for( int i = 0; i < dst_norm.rows ; i++ )
{
for( int j = 0; j < dst_norm.cols; j++ )
{
if( (int) dst_norm.at<float>(i,j) > thresh )
{
circle( dst_norm_scaled, Point(j,i), 5, Scalar(0), 2, 8, 0 );
}
}
}
namedWindow( corners_window );
imshow( corners_window, dst_norm_scaled );
imwrite("corner_grid.png", dst_norm_scaled);
}
void goodFeaturesToTrack_Demo( int, void* )
{
maxCorners = MAX(maxCorners, 1);
vector<Point2f> corners;
double qualityLevel = 0.01;
double minDistance = 10;
int blockSize = 3, gradientSize = 3;
bool useHarrisDetector = false;
double k = 0.04;
Mat copy = src.clone();
goodFeaturesToTrack( src_gray,
corners,
maxCorners,
qualityLevel,
minDistance,
Mat(),
blockSize,
gradientSize,
useHarrisDetector,
k );
cout << "** Number of corners detected: " << corners.size() << endl;
int radius = 8;
for( size_t i = 0; i < corners.size(); i++ )
{
circle( copy, corners[i], radius, Scalar(0, 0, rng.uniform(0, 256)), FILLED );
}
namedWindow( source_window );
imwrite("corner_grid_st.png", copy);
imshow( source_window, copy );
}

边栏推荐
- Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
- List of financial products in 2022
- [UE4] brush Arctic pack high quality Arctic terrain pack
- Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
- TCP拥塞控制详解 | 3. 设计空间
- The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
- Qt调节Win屏幕亮度和声音大小
- 自动渗透测试工具核心功能简述
- AcWing 3438. 数制转换
- Create a new file from templates with bash script - create new file from templates with bash script
猜你喜欢

面试官:值为 nil 为什么不等于 nil ?

MySQL has been stopped in the configuration interface during installation

Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code

Five problems of database operation in commodity supermarket system

MySQL grouping query

Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028

1164 Good in C

Baiwen.com 7 days Internet of things smart home learning experience punch in the next day

Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
![How to read the source code [debug and observe the source code]](/img/40/a2fca67bcde3c468a739c6990325f4.jpg)
How to read the source code [debug and observe the source code]
随机推荐
PUT vs. POST for Uploading Files - RESTful API to be Built Using Zend Framework
AcWing 3438. 数制转换
微服务组件Sentinel控制台调用
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
[RT thread] NXP rt10xx device driver framework -- pin construction and use
Brief introduction to the core functions of automatic penetration testing tool
MySQL grouping query
POM in idea XML graying solution
Test your trained model
企业级自定义表单引擎解决方案(十一)--表单规则引擎1
1164 Good in C
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
ArrayList分析3 : 删除元素
Web-ui automated testing - the most complete element positioning method
September, 19, "cam principle and application" online assignment [Full Score answer]
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
AcWing 3438. Number system conversion
Five problems of database operation in commodity supermarket system
List的stream中Long对象与long判等问题记录
University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]