Blame view

Python/ImageComponents.py 2.17 KB
78fbd752   jsenella   ajout de ROS et P...
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  #!/usr/bin/env python
  
  import cv2
  import numpy as np
  import sys
  from PIL import Image
  from matplotlib import pyplot as plt
  
  
  def Histogram(image):
  	color = ('b', 'g', 'r')
  	for i,col in enumerate(color):
  		histr = cv2.calcHist([image], [i], None, [256], [0,256])
  		plt.plot(histr,color = col)
  		plt.xlim([0,256])
  	plt.show()
  
  def Corners(image):
  	img = image.copy()
  	gray= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  	gray = np.float32(gray)
  	dst = cv2.cornerHarris(gray, 5, 5, 0.15)
  	dst = cv2.dilate(dst, None)
  	img[dst>0.01*dst.max()] = [0,0,255]
  	cv2.imshow('dst', img)
  	return dst
  
  def Edges(image):
  	img = image.copy()
  	edges = cv2.Canny(img, 100, 200)
  	plt.subplot(121),plt.imshow(img,cmap='gray')
  	plt.title('Original Image'), plt.xticks([]), plt.yticks([])
  	plt.subplot(122),plt.imshow(edges,cmap = 'gray')
  	plt.title('Edge Image'), plt.xticks([]), plt.yticks([])
  	plt.show()
  	return edges
  
  def Components(image):	
  	b = image.copy()
  	# set green and red channels to 0
  	b[:, :, 1] = 0
  	b[:, :, 2] = 0
  
  	g = image.copy()	
  	# set blue and red channels to 0
  	g[:, :, 0] = 0
  	g[:, :, 2] = 0
  
  	r = image.copy()
  	# set blue and green channels to 0
  	r[:, :, 0] = 0
  	r[:, :, 1] = 0
  	
  	return b,g,r
  
  #paper = image.copy()
  #ret, thresh = cv2.threshold(cv2.cvtColor(paper, cv2.COLOR_BGR2GRAY), 100, 255, cv2.THRESH_BINARY)
  #image2, contours, hier = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  #for c in contours:
  #	rect = cv2.minAreaRect(c)
  #	box = cv2.boxPoints(rect)
  #	box = np.int0(box)
  #	cv2.drawContours(paper, [box], 0, (0, 255, 0),1)
  #cv2.imshow('paper', paper)
  
  #image = cv2.imread('couleur.png')
  image = cv2.imread('couleur.png')
  #edges = Edges(image)
  #cv2.imshow('image', image)
  #Histogram(image)
  dst = Corners(image)
  #Histogram(image)
  #r, g, b = Components(image)
  #test = image[100, 200]
  #print(test)
  b,g,r = cv2.split(image)
  #cv2.imwrite('RedDrone.png', r)
  #cv2.imwrite('BlueDrone.png', b)
  #cv2.imwrite('GreenDrone.png', g)
  
  cv2.waitKey(0)
  
  
  
  # RGB - Blue
  #cv2.imshow('B-RGB',b,  cmap = 'gray')
  #cv2.imwrite("flecheBleue.png", b)
  
  # RGB - Green
  #cv2.imshow('G-RGB', g)
  #cv2.imwrite("flecheVerte.png", g)
  
  # RGB - Red
  #cv2.imshow('R-RGB', r)
  #cv2.imwrite("flecheRouge.png", r)
  
  #cv2.waitKey(0)