81de032f
Justine
Ajout de l'applic...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import cv2
import numpy as np
import Contour
import ColorObject
from Parameters import *
def ColoredArrow():
image = cv2.imread('couleur.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 > 1000:
print "Arrow"
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)
|