I am working with OpenCV and inside there is the function goodFeaturesToTrack to apply ShiTomasi method to find corners.
We know that Shi-Tomasi is based on finding eigenvalues so there is even a function in OpenCV to calculate the minimal eigenvalue of gradient matrices for corner detection called cornerMinEigenVal
in case you want to do your own implementation:
void cv::cornerMinEigenVal ( InputArray src,
OutputArray dst,
int blockSize,
int ksize = 3,
int borderType = BORDER_DEFAULT
)
However this function finds the minimum eigenvalue for ALL points in the image (and store the results in dst
).
My question is:
Is there a function (in OpenCV or if not any other C++ library) to find the eigenvalues
(or its minimum) for a particular point (X,Y)
of an image (and not evaluated in the whole image) (with a blocksize) ?
Short answer: There is no such function in OpenCV that calculate MinEigenVals for sparse points. However, you can implement one from HarrisResponses() with just small modifications.
The HarrisResponses()
function is used to calculate Harris score for sparse points (it's static in OpenCV, so you can't call it directly).
Look through the code of calcMinEigenVal() and calcHarris(), and you will find that the only difference between them is how they use values from the cov
matrix:
// MinEigenVal
float a = cov[j*3]*0.5f;
float b = cov[j*3+1];
float c = cov[j*3+2]*0.5f;
dst[j] = (float)((a + c) - std::sqrt((a - c)*(a - c) + b*b));
// Harris
float a = cov[j*3];
float b = cov[j*3+1];
float c = cov[j*3+2];
dst[j] = (float)(a*c - b*b - k*(a + c)*(a + c));
Just change this line to:
// scale_sq = scale * scale
pts[ptidx].response = (float)((a + b)*0.5f - stb::sqrt((a - b)*(a - b)*0.25f + c*c))*scale_sq;
and you will get what you need.