2017-08-04 3 views
1

Ich versuche, die Pixelwerte der Ecken dieser Dreiecke zu finden. Ich kann die Punkte auf dem Ausgabebild markieren, weiß aber nicht, wie man sie als Variable zum Drucken erhält. Ich möchte, dass diese Eckwerte in einer Variablen gespeichert werden. This ist das Eingabebild "Dreiecke.png". This ist das Ausgabebild.Finden Sie Ecken eines Dreiecks

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

Was ist falsch an dem Beispiel in der Dokumentation? http://docs.opencv.org/2.4/doc/tutorials/features2d/trackingmotion/harris_detector/harris_detector.html – Piglet

Antwort

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

x, y - numpy Arrays mit x und y Koordinaten der Ecken. Sie können es später verwenden:

coordinates = zip(x, y) 
Verwandte Themen