简体   繁体   English

如何使用python获取x,y坐标?

[英]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). 我已使用以下算法(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.
img[dst>0.01*dst.max()]=[0,0,255]

cv2.imshow('dst',img)
cv2.waitKey(0)
cv2.imwrite('CornerSquare.jpg',img)

在此处输入图片说明

coord = np.where(np.all(img == (0, 0, 255), axis=-1))
print zip(coord[0], coord[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM