当前位置:网站首页>(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)
- RDS数据库的监测页面在哪看?
- TCP congestion control details | 3 design space
- [mathematical logic] equivalent calculus and reasoning calculus of predicate logic (individual word | predicate | quantifier | predicate logic formula | two basic formulas | proposition symbolization
- 【JokerのZYNQ7020】DDS_ Compiler。
- Golang unit test, mock test and benchmark test
- Vs2013 has blocked the installer, and ie10 needs to be installed
- Basic grammar of interview (Part 2)
- Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
- Leetcode 669 pruning binary search tree -- recursive method and iterative method
猜你喜欢

How to purchase Google colab members in China
![[set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela](/img/df/a034032e203e7935dafaf8a71cb6c8.jpg)
[set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela

Qt调节Win屏幕亮度和声音大小
![[RT thread] NXP rt10xx device driver framework -- Audio construction and use](/img/85/32a83eaa4b7f5b30d4d7c4f4c32791.png)
[RT thread] NXP rt10xx device driver framework -- Audio construction and use

Embedded-c language-7

STM32实现74HC595控制

Interviewer: why is the value nil not equal to nil?

Wechat applet for the first time

The third day of writing C language by Yabo people

Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
随机推荐
PR second time
A day's work list of an ordinary programmer
[RT thread] construction and use of --hwtimer of NXP rt10xx device driver framework
[vscode] convert tabs to spaces
AcWing 4489. 最长子序列
[RT thread] NXP rt10xx device driver framework -- pin construction and use
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
Comparison of kotlin collaboration + retro build network request schemes
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
VM11289 WAService. js:2 Do not have __ e handler in component:
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
Answer to the homework assessment of advanced English reading (II) of the course examination of Fuzhou Normal University in February 2022
Brief introduction to the core functions of automatic penetration testing tool
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
Basic grammar of interview (Part 2)
Five problems of database operation in commodity supermarket system
SQL injection database operation foundation
Servlet specification Part II
AcWing 3438. Number system conversion
1147_ Makefile learning_ Target files and dependent files in makefile