Reputation: 2679
Ive been reading about feature detection and wanted to try harris corner detector. I realize that it is achieved by calling
void cornerHarris(InputArray src, OutputArray dst, int blockSize, int ksize, double k, int borderType=BORDER_DEFAULT )
where the dst is an image of floats containing corner strengths at each pixel.
I wanted to see it work so I wanted to apply it to the following picture:
The result produced was this:
As you can tell the results are not good. It looks to me that it just picked up noise, the main corners were not even detected.
Here is the code I used to print corners on the image, I used threshold and set any arbitrary value for threshold.
int _tmain(int argc, _TCHAR* argv[])
{
Mat img, dst, threshed;
img = imread("c:\\laptop.jpg",0);
dst = Mat::zeros(img.size(), CV_32FC1);
cornerHarris(img, dst, 2, 3, 0.04, BORDER_DEFAULT);
threshold(dst, threshed, 0.00001, 255, THRESH_BINARY_INV);
namedWindow("meh", CV_WINDOW_AUTOSIZE);
imshow("meh", threshed);
//imwrite("harris.jpg", threshed);
waitKey(0);
return 0;
If I reduce threshold the result is white with just a few black dots (detections) Increasing threshold just produces a more noisy like image.
Am I missing something? How can I improve the quality of this function?
Thank you
Upvotes: 4
Views: 8187
Reputation: 30122
You can try a goodFeaturesToTrack function. It is built on top of Harris corner detector but filters our the noise and returns only strong corners.
Upvotes: 9