当前位置:网站首页>(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 );
}

边栏推荐
- Kubernetes resource object introduction and common commands (III)
- Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
- 【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
- Loop through JSON object list
- 面试官:值为 nil 为什么不等于 nil ?
- MySQL has been stopped in the configuration interface during installation
- Introduction to SolidWorks gear design software tool geartrax
- Managing multiple selections with MVVM - managing multiple selections with MVVM
- [vscode] convert tabs to spaces
- How to purchase Google colab members in China
猜你喜欢

鸿蒙第四次培训

Notes on problems -- watching videos on edge will make the screen green

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

微服务组件Sentinel控制台调用

互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码

Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028
![[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th](/img/f1/c96c4a6d34e1ae971f492f4aed5a93.jpg)
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th

Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method

Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028

Play with fancy special effects. This AE super kit is for you
随机推荐
1164 Good in C
[combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
Talk about the design and implementation logic of payment process
面试官:值为 nil 为什么不等于 nil ?
互联网医院HIS管理平台源码,在线问诊,预约挂号 智慧医院小程序源码
企业级自定义表单引擎解决方案(十一)--表单规则引擎1
[UE4] brush Arctic pack high quality Arctic terrain pack
The difference between i++ and ++i: tell their differences easily
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
Where is the monitoring page of RDS database?
数学公式(测试)
Leetcode540: a single element in an ordered array
A day's work list of an ordinary programmer
Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
Tensorboard quick start (pytoch uses tensorboard)
[combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)