I am new using OpenCV and I am having a problem detecting corners in a image. Supposing I have an image-grid like this one where there are multiple corners.
I'd like to catch just the 4 extreme corners, highlighted in red.
Using cv2.cornerHarris() I've managed to highlight all the possible corners really accurately but I can't find a way to adjust these values and let just the 4 extreme remain.
This is my code:
import cv2
import numpy as np
filename = 'start.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,29,0.04)
#result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)
# Threshold for an optimal value, it may vary depending on the image.
img[dst>0.01*dst.max()]=[0,0,255]
cv2.imshow('dst',img)
if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()
I've got this code from the official OpenCV website and I've adjusted few values.
Anyone be able to help? Am I in the completely wrong direction? If I've not been clear what I'd like to have is the output-image the I've attached in my question while my code is just giving me all the possible corners in the grid.
Grid does not start from coordinates x,y = 0,0
Thank you in advance guys


