OpenCV: Como posso encontrar a cor dentro de um contorno / polígono?
Aqui está o que eu tenho
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?
Não consigo encontrar nenhuma função openCV embutida. Suponho que talvez você consiga fazê-lo com os momentos? Como posso conseguir isso?
EDIT: com a solução proposta dada por Zaw Lin, tenho esta imagem de entrada:
e esta imagem de saída: