Reputation: 407
I have been reading about cornerHarris
in OpenCV. I read through the documentation but I am not sure what does this function return.
While reading through the examples, there is a statement written as:
dst = cv2.cornerHarris(gray,2,3,0.04)
img[dst>0.01*dst.max()]=[0,0,255]
I just cannot understand the second statement above, may be because I do not understand, what is cornerHarris
actually returning.
I do sense, that there is some kind of threshold being applied, but I cannot explain.
Upvotes: 4
Views: 6967
Reputation: 467
dst = cv2.cornerHarris(gray,2,3,0.04)
dst is resultant 2D probability array with the same shape as of input image.
img[dst>0.01*dst.max()]=[0,0,255]
The above code is marely a post-processing technique, where "low-confidence-corners" are filtered out.
or to interpret differently:
Filter in those probabilities whose confidence is more than 1% of the max. probability in the resultant 2D probability array
From the examples documentation. If the image is less complex as given below, Even the below code will work fine:
img[dst == dst.max()]=[0,0,255]
For more clarity, plot the resultant 2D probability array using matplotlib:
def display(img, mapp='gray'):
plt.imshow(img, cmap=mapp)
plt.show()
Upvotes: 0
Reputation: 467
I just checked the example page you linked:
Threshold for an optimal value, it may vary depending on the image. img[dst>0.01*dst.max()]=[0,0,255]
This is the documentation page I was actually looking for: https://docs.opencv.org/2.4/modules/imgproc/doc/feature_detection.html?highlight=cornerharris#cornerharris
Corners in the image can be found as the local maxima of this response map.
The cv2.cornerHarris detector returns the corners that were found. As usual this method does not return a list of corners that were found. Instead, it returns an 2d-array - same size as the input - with probabilities. Each position inside this array holds the confidence in this pixel being a corner (to be precise it is not the single pixel, that is predicted to be a corner. It is the neighbourhood that is centered at this coordinates)
So most likely cv2.cornerHarris returns a value for confidence in it's own prediction. And with
dst>0.01*dst.max()
the code filters corners that are only "low-confidence-corners". Any corner that is detected will just be marked as a corner if the confidence is higher than 1% of the highest confidence.
Upvotes: 5