Manoj Amarasekera Manoj Amarasekera - 1 year ago 122
Python Question

How to get x,y coordinates using python?

I have detected the corners (red dots in the image) of this image using below algorithm (cornerHarris). Now I want to get the coordinates of that points. How can I do that?

import cv2
import numpy as np

filename = 'Square.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,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.


enter image description here

Answer Source
coord = np.where(np.all(img == (0, 0, 255), axis=-1))
print zip(coord[0], coord[1])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download