To find the coordinates of corners detected by Harris corner detection
I have applied harris corner detection on the following image
and obtained the result as
and now i want to find the coordinates of these corner pixels marked in red how do i do so?
Code:
import numpy as np
import cv2
img=cv2.imread('trial1.jpg')
h,w,l=img.shape
res=cv2.resize(img,(w/4,h/4),interpolation=cv2.INTER_LINEAR)
gray = cv2.cvtColor(res,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)
cv2.imwrite('dsttest.jpg',dst)
dst = cv2.dilate(dst,None)
res[dst>0.01*dst.max()]=[0,0,255]
points=np.unravel_index(dst.argmax(),dst.shape)
print list(points)
cv2.imwrite('dst.jpg',res)
cv2.waitKey(0)
cv2.destroyAllWindows()
I want to be able to find out the coordinates of the corner points, the points in red aren't going to give me a single pixel value since each of them comprise of several pixels.I need this information so that i can automatically separate the image into it's constituent squares by using numpy array slicing
first of all, don't dilate the dst image. from there on it's basically non-maximum-suppression
(and probably you need a higher threshold value)
or use goodFeaturesToTrack() instead ?
Hi @csthakur Were you able to solve this issue. I am also working on similar problem where i am trying to find the corners of a grid and then slice it. I was trying to find the lines using HoughTransformP, seperate horizontal and vertical line, and then detect the point of intersections. Do let me know if you were able to solve this problem.
It will of great help for me & others like me if you add your solution in the answers below and accept it as a right answer.