2017-08-04 166 views
1

我正在嘗試查找這些三角形邊角的像素值。 我可以標記輸出圖像上的點,但不知道如何獲取它作爲打印變量。我希望這些角落值被存儲在一個變量中。 This是輸入圖像「triangles.png」。 This是輸出圖像。查找三角形的邊角

import cv2 
import numpy as np 
from matplotlib import pyplot as plt 
filename = 'triangles.png' 
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) 
img[dst>0.01*dst.max()]=[250,0,0] 
cv2.imshow('dst',img) 
if cv2.waitKey(0) & 0xff == 27: 
    cv2.destroyAllWindows() 
+1

文檔中的示例有什麼問題? http://docs.opencv.org/2.4/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.html – Piglet

回答

1
dst = cv2.cornerHarris(gray, 2, 3, 0.04) 
x, y = np.nonzero(dst > 0.01 * dst.max()) 

的x,y - numpy的陣列,x和角y座標。您可以稍後使用它:

coordinates = zip(x, y)