Blame view

Python/Application/Test.py 1.44 KB
81de032f   Justine   Ajout de l'applic...
1
2
3
4
5
6
7
  import cv2
  import numpy as np
  import Contour
  import ColorObject
  from Parameters import *
  
  def ColoredArrow():
3f217332   Justine   mise à jour du git
8
9
  	#image = cv2.imread('couleur.png')
  	image = cv2.imread('Bilateral.png')
81de032f   Justine   Ajout de l'applic...
10
11
12
13
14
15
  	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)
3f217332   Justine   mise à jour du git
16
17
  		if len(approx) > 6 and len(approx) < 9 and tmp >  2000:
  			print tmp
81de032f   Justine   Ajout de l'applic...
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
46
  			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)