OpenCV: Wie finde ich die Farbe innerhalb einer Kontur / eines Polygons?
Hier ist was ich habe
im = cv2.imread('luffy.jpg')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,127,255,0)
contours,h = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
// return color inside of the contour here
mask = np.zeros(cnt.shape[:2],np.uint8)
mean = cv2.mean(cant,mask) // I think this is promising but so far it returns arrays with just zeros. I think its because I used np.zeros above to find the mask....
moment = cv2.moments(cnt) //maybe this will help?
Ich kann keine solche eingebaute openCV-Funktion finden. Ich nehme an, Sie können es vielleicht mit den Momenten machen? Wie kann ich das erreichen ??
EDIT: mit der von Zaw Lin vorgeschlagenen Lösung habe ich dieses Eingabebild:
und dieses Ausgabebild: