import cv2 import numpy as np import Contour import ColorObject from Parameters import * def ColoredArrow(): #image = cv2.imread('couleur.png') image = cv2.imread('Bilateral.png') height, width, channels = image.shape mask = np.zeros((height, width, 3), dtype = "uint8") contours = Contour.FindContours(image) for cnt in contours: tmp = cv2.contourArea(cnt) approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True) if len(approx) > 6 and len(approx) < 9 and tmp > 2000: print tmp cv2.drawContours(mask, [cnt], 0, (255,255,255), -1) cv2.imshow('Mask', mask) arrows = cv2.bitwise_and(image, mask) cv2.imshow('Arrows', arrows) cv2.imwrite('Arrows.png', arrows) cv2.waitKey(0) cv2.destroyAllWindows() return arrows def FindColor(img): height, width, channels = img.shape blueMask, blueRes = ColorObject.IsolateObject(img, LowerBlue, UpperBlue) redMask, redRes = ColorObject.IsolateObject(img, LowerRed, UpperRed) greenMask, greenRes = ColorObject.IsolateObject(img, LowerGreen, UpperGreen) greyRes = cv2.bitwise_xor(img, greenRes) greyRes = cv2.bitwise_xor(greyRes, redRes) greyRes = cv2.bitwise_xor(greyRes, blueRes) kernel = np.ones((5,5),np.uint8) greyRes = cv2.erode(greyRes,kernel,iterations = 1) cv2.imshow('Grey Arrow', greyRes) cv2.imshow('Red Arrow', redRes) cv2.imshow('Blue Arrow', blueRes) cv2.imshow('Green Arrow', greenRes) cv2.waitKey(0) cv2.destroyAllWindows() return image = ColoredArrow() FindColor(image)