Commit 81de032f26d477a407d8e26fb99da1b0da0688d4
1 parent
78fbd752
Ajout de l'application
Showing
43 changed files
with
753 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,76 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +from Parameters import * | |
4 | + | |
5 | +def IsolateObject(frame ,Lower, Upper): | |
6 | + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) | |
7 | + mask = cv2.inRange(hsv, Lower, Upper) | |
8 | + kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5)) | |
9 | + mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) | |
10 | + res = cv2.bitwise_and(frame,frame, mask= mask) | |
11 | + return mask, res | |
12 | + | |
13 | +def ColorDisplayResults(liste, nb): | |
14 | + for i in range (0, len(liste)): | |
15 | + if i == 0: | |
16 | + titre = 'mask'+str(nb) | |
17 | + else: | |
18 | + titre = 'res'+str(nb) | |
19 | + cv2.imshow(titre, liste[i]) | |
20 | + return | |
21 | + | |
22 | +def CombineColors(color1, color2): | |
23 | + mask = cv2.bitwise_or(color1[0], color2[0]) | |
24 | + res = cv2.bitwise_or(color1[1], color2[1]) | |
25 | + return mask, res | |
26 | + | |
27 | +def ColorChoiceProcessing(image, choix): | |
28 | + if choix == '1': | |
29 | + blueMask, blueRes = IsolateObject(image, LowerBlue, UpperBlue) | |
30 | + return [blueMask, blueRes] | |
31 | + elif choix == '2': | |
32 | + greenMask, greenRes = IsolateObject(image, LowerGreen, UpperGreen) | |
33 | + return [greenMask, greenRes] | |
34 | + elif choix == '3': | |
35 | + redMask, redRes = IsolateObject(image, LowerRed, UpperRed) | |
36 | + return[redMask, redRes] | |
37 | + elif choix == '4': | |
38 | + blue = ColorChoiceProcessing(image, '1') | |
39 | + green = ColorChoiceProcessing(image, '2') | |
40 | + bgMask, bgRes = CombineColors(blue, green) | |
41 | + return [bgMask, bgRes] | |
42 | + elif choix == '5': | |
43 | + blue = ColorChoiceProcessing(image, '1') | |
44 | + red = ColorChoiceProcessing(image, '3') | |
45 | + brMask, brRes = CombineColors(blue, red) | |
46 | + return [brMask, brRes] | |
47 | + elif choix == '6': | |
48 | + red = ColorChoiceProcessing(image, '3') | |
49 | + green = ColorChoiceProcessing(image, '2') | |
50 | + rgMask, rgRes = CombineColors(red, green) | |
51 | + return [rgMask, rgRes] | |
52 | + elif choix == '7': | |
53 | + bg = ColorChoiceProcessing(image, '4') | |
54 | + red = ColorChoiceProcessing(image, '3') | |
55 | + bgrMask, bgrRes = CombineColors(bg, red) | |
56 | + return [bgrMask, bgrRes] | |
57 | + else: | |
58 | + return | |
59 | + | |
60 | +def ColorChoice() : | |
61 | + image = None | |
62 | + print('\t\tFind Color Object Menu\n') | |
63 | + while (image is None): | |
64 | + image = str(raw_input('\tImage to use ? By default couleur.png \n')) | |
65 | + if not image: | |
66 | + image = 'couleur.png' | |
67 | + image = cv2.imread(str(image)) | |
68 | + print ('\t1. Blue\n\t2. Green\n\t3. Red\n\t4. Blue Green\n\t5. Blue Red\n\t6. Red Green\n\t7. Blue Green Red\n') | |
69 | + choix = raw_input('\n\tMultiple choices possible\n') | |
70 | + for i in range (0, len(choix)): | |
71 | + liste = ColorChoiceProcessing(image, choix[i]) | |
72 | + if liste : | |
73 | + ColorDisplayResults(liste,choix[i]) | |
74 | + cv2.waitKey(0) | |
75 | + cv2.destroyAllWindows() | |
76 | + return | ... | ... |
... | ... | @@ -0,0 +1,130 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +import numpy as np | |
4 | +import cv2 | |
5 | + | |
6 | +def FindContours(img): | |
7 | + imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) | |
8 | + #cv2.imshow("Gray", imgray) | |
9 | + ret,thresh = cv2.threshold(imgray,127,255,0) | |
10 | + #cv2.imshow("threshold", thresh) | |
11 | + _,contours,hierarchy = cv2.findContours(thresh, 1, 2) | |
12 | + return contours | |
13 | + | |
14 | +def FindCenterofMass(contours): | |
15 | + liste = [] | |
16 | + area = [] | |
17 | + centerMass = [] | |
18 | + for i in range (0,len(contours)): | |
19 | + cnt = contours[i] | |
20 | + #print cnt | |
21 | + M = cv2.moments(cnt) | |
22 | + area.append(cv2.contourArea(cnt)) | |
23 | + tmp = cv2.contourArea(cnt) | |
24 | + if (M['m00'] != 0) and (tmp > 1000): | |
25 | + cx = int(M['m10']/M['m00']) | |
26 | + cy = int(M['m01']/M['m00']) | |
27 | + centerMass.append((cx,cy)) | |
28 | + else: | |
29 | + liste.append(i) | |
30 | + return liste, area, centerMass | |
31 | + | |
32 | + | |
33 | + | |
34 | +def CleanContours(img): | |
35 | + contours = FindContours(img) | |
36 | + liste, _, _ = FindCenterofMass(contours) | |
37 | + for j in range (0,len(liste)): | |
38 | + a = liste[j] | |
39 | + if (a < len(contours)): | |
40 | + contours.pop(a) | |
41 | + return contours | |
42 | + | |
43 | +def DrawBoundingBox(img): | |
44 | + contours = FindContours(img) | |
45 | + for cnt in contours: | |
46 | + x,y,w,h = cv2.boundingRect(cnt) | |
47 | + img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) | |
48 | + cv2.imshow('Bounding Box', img) | |
49 | + return img | |
50 | + | |
51 | +def DrawEnclosingCircle(img): | |
52 | + contours = FindContours(img) | |
53 | + for cnt in contours: | |
54 | + (x,y),radius = cv2.minEnclosingCircle(cnt) | |
55 | + center = (int(x),int(y)) | |
56 | + radius = int(radius) | |
57 | + img = cv2.circle(img,center,radius,(0,255,0),2) | |
58 | + cv2.imshow('Enclosing Circle', img) | |
59 | + return img | |
60 | + | |
61 | +def DrawContours(img, contours, titre): | |
62 | + img = cv2.drawContours(img, contours, -1, (0,255,0), 3) | |
63 | + cv2.imshow(titre, img) | |
64 | + return img | |
65 | + | |
66 | +def DrawCenterofMass(img): | |
67 | + contours = FindContours(img) | |
68 | + _, _, centerMass = FindCenterofMass(contours) | |
69 | + for x, y in centerMass: | |
70 | + img=cv2.circle(img, (x,y), 10, (124,255,255), 1) | |
71 | + cv2.imshow('Center of Mass', img) | |
72 | + return img | |
73 | + | |
74 | +def DrawArea(img): | |
75 | + contours = CleanContours(img) | |
76 | + img = cv2.drawContours(img, contours, -1, (255, 0, 0), cv2.FILLED) | |
77 | + cv2.imshow('Area', img) | |
78 | + return img | |
79 | + | |
80 | +def ContourChoiceProcessing(img, choice): | |
81 | + if choice == '1': | |
82 | + contours = FindContours(img) | |
83 | + img = DrawContours(img, contours, 'Contours') | |
84 | + return img | |
85 | + elif choice == '2': | |
86 | + contours = CleanContours(img) | |
87 | + img = DrawContours(img, contours, 'Clean Contours') | |
88 | + return img | |
89 | + elif choice == '3': | |
90 | + img = DrawCenterofMass(img) | |
91 | + return img | |
92 | + elif choice == '4': | |
93 | + img = DrawArea(img) | |
94 | + return img | |
95 | + elif choice == '5': | |
96 | + img = ContourChoiceProcessing(img, '2') | |
97 | + img = DrawCenterofMass(img) | |
98 | + return img | |
99 | + elif choice == '6': | |
100 | + img = DrawArea(img) | |
101 | + img = DrawCenterofMass(img) | |
102 | + return img | |
103 | + elif choice == '7': | |
104 | + img = DrawBoundingBox(img) | |
105 | + return img | |
106 | + elif choice == '8': | |
107 | + img = DrawEnclosingCircle(img) | |
108 | + return img | |
109 | + else: | |
110 | + return | |
111 | + | |
112 | +def ContourChoice(): | |
113 | + image = None | |
114 | + img = None | |
115 | + print('\t\tContours Features Menu\n') | |
116 | + while (image is None): | |
117 | + image = str(raw_input('\tImage to use? By default couleur.png \n')) | |
118 | + if not image: | |
119 | + image = 'couleur.png' | |
120 | + image = cv2.imread(str(image)) | |
121 | + print ('\t1. Contours\n\t2. Clean Contours\n\t3. Center of Mass\n\t4. Area\n\t5. Contours + Center of Mass\n\t6. Area + Center of Mass\n\t7. Bounding Box\n\t8. Enclosing Circle\n') | |
122 | + choix = raw_input('\n\tMultiple choices possible\n') | |
123 | + for i in range (0, len(choix)): | |
124 | + img = image.copy() | |
125 | + img = ContourChoiceProcessing(img, choix[i]) | |
126 | + if img is not None: | |
127 | + cv2.waitKey(0) | |
128 | + cv2.destroyAllWindows() | |
129 | + return | |
130 | + | ... | ... |
28.4 KB
... | ... | @@ -0,0 +1,73 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +from matplotlib import pyplot as plt | |
4 | +img = cv2.imread('couleur.png',0) | |
5 | + | |
6 | +def Everything (img): | |
7 | + laplacian = cv2.Laplacian(img,cv2.CV_64F) | |
8 | + sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) | |
9 | + sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) | |
10 | + plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') | |
11 | + plt.title('Original'), plt.xticks([]), plt.yticks([]) | |
12 | + plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') | |
13 | + plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) | |
14 | + plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') | |
15 | + plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) | |
16 | + plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') | |
17 | + plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) | |
18 | + plt.show() | |
19 | + return laplacian | |
20 | + | |
21 | +def Laplacian(img): | |
22 | + laplacian = cv2.Laplacian(img,cv2.CV_64F) | |
23 | + plt.plot,plt.imshow(laplacian,cmap = 'gray') | |
24 | + plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) | |
25 | + plt.show() | |
26 | + return laplacian | |
27 | + | |
28 | +def SobelX(img): | |
29 | + sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) | |
30 | + plt.plot,plt.imshow(sobelx,cmap = 'gray') | |
31 | + plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) | |
32 | + plt.show() | |
33 | + return sobelx | |
34 | + | |
35 | +def SobelY(img): | |
36 | + sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) | |
37 | + plt.plot,plt.imshow(sobely,cmap = 'gray') | |
38 | + plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) | |
39 | + plt.show() | |
40 | + return sobely | |
41 | + | |
42 | +def GradientChoiceProcessing(img, choice): | |
43 | + if choice == '1': | |
44 | + img = Laplacian(img) | |
45 | + return img | |
46 | + elif choice == '2': | |
47 | + img = SobelX(img) | |
48 | + return img | |
49 | + elif choice == '3': | |
50 | + img = SobelY(img) | |
51 | + return img | |
52 | + elif choice == '4': | |
53 | + img = Everything(img) | |
54 | + return img | |
55 | + else: | |
56 | + return | |
57 | + | |
58 | + | |
59 | +def GradientChoice() : | |
60 | + image = None | |
61 | + print('\t\tGradient Menu\n') | |
62 | + while (image is None): | |
63 | + image = str(raw_input('\tImage to use? By default couleur.png \n')) | |
64 | + if not image: | |
65 | + image = 'couleur.png' | |
66 | + image = cv2.imread(str(image), 0) | |
67 | + print ('\t1. Laplacian\n\t2. Sobel X\n\t3. Sobel Y\n\t4. Everything\n') | |
68 | + choice = raw_input('\n\tMultiple choices possible\n') | |
69 | + for i in range (0, len(choice)): | |
70 | + img = image.copy() | |
71 | + img = GradientChoiceProcessing(img, choice[i]) | |
72 | + return | |
73 | + | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +from matplotlib import pyplot as plt | |
4 | + | |
5 | +def Corners(): | |
6 | + image = None | |
7 | + while (image is None): | |
8 | + image = str(raw_input('\tImage to use ? By default couleur.png \n')) | |
9 | + if not image: | |
10 | + image = 'couleur.png' | |
11 | + image = cv2.imread(str(image)) | |
12 | + img = image.copy() | |
13 | + gray= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
14 | + gray = np.float32(gray) | |
15 | + dst = cv2.cornerHarris(gray, 5, 5, 0.15) | |
16 | + dst = cv2.dilate(dst, None) | |
17 | + img[dst>0.01*dst.max()] = [0,0,255] | |
18 | + cv2.imshow('dst', img) | |
19 | + cv2.waitKey(0) | |
20 | + cv2.destroyAllWindows() | |
21 | + return | |
22 | + | |
23 | +def Edges(): | |
24 | + image = None | |
25 | + while (image is None): | |
26 | + image = str(raw_input('\tImage to use ? By default couleur.png \n')) | |
27 | + if not image: | |
28 | + image = 'couleur.png' | |
29 | + image = cv2.imread(str(image)) | |
30 | + img = image.copy() | |
31 | + edges = cv2.Canny(img, 100, 200) | |
32 | + plt.subplot(121),plt.imshow(img,cmap='gray') | |
33 | + plt.title('Original Image'), plt.xticks([]), plt.yticks([]) | |
34 | + plt.subplot(122),plt.imshow(edges,cmap = 'gray') | |
35 | + plt.title('Edge Image'), plt.xticks([]), plt.yticks([]) | |
36 | + plt.show() | |
37 | + return | ... | ... |
... | ... | @@ -0,0 +1,67 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +import Contour | |
4 | + | |
5 | +##!!!!!Faire le pretraitement | |
6 | + | |
7 | +#Test : Luminosite, orientation dans l'espace, distance | |
8 | +#Etudier les limites | |
9 | + | |
10 | +def FindCircles(): | |
11 | + image = None | |
12 | + while (image is None): | |
13 | + image = str(raw_input('\tImage to use ? By default couleur.png \n')) | |
14 | + if not image: | |
15 | + image = 'couleur.png' | |
16 | + image = cv2.imread(str(image), 0) | |
17 | + img = cv2.medianBlur(image, 5) | |
18 | + cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) | |
19 | + circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20, param1 = 50, param2 = 30, minRadius = 0, maxRadius = 0) | |
20 | + circles = np.uint16(np.around(circles)) | |
21 | + for i in circles[0,:]: | |
22 | + cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2) | |
23 | + cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3) | |
24 | + | |
25 | + cv2.imshow('detected circles',cimg) | |
26 | + cv2.waitKey(0) | |
27 | + cv2.destroyAllWindows() | |
28 | + return | |
29 | + | |
30 | +def FindShapes(): | |
31 | + image = None | |
32 | + while (image is None): | |
33 | + image = str(raw_input('\tImage to use ? By default couleur.png \n')) | |
34 | + if not image: | |
35 | + image = 'couleur.png' | |
36 | + image = cv2.imread(str(image)) | |
37 | + height, width, channels = image.shape | |
38 | + mask = np.zeros((height, width, 3), dtype = "uint8") | |
39 | + contours = Contour.FindContours(image) | |
40 | + img = image.copy() | |
41 | + #Contour.DrawContours(img, contours, "Contours Shape Detection") | |
42 | + for cnt in contours: | |
43 | + approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True) | |
44 | + if len(approx) == 3 : | |
45 | + print "Triangle" | |
46 | + cv2.drawContours(image, [cnt], 0, (255, 255, 0), -1) | |
47 | + elif len(approx) == 4: | |
48 | + print "Square" | |
49 | + cv2.drawContours(image, [cnt], 0, (255, 255, 255), -1) | |
50 | + elif len(approx) == 5: | |
51 | + print "Pentagon" | |
52 | + cv2.drawContours(image, [cnt], 0, (0, 255, 0), -1) | |
53 | + #elif len(approx) == 8: | |
54 | + # print "Huit" | |
55 | + # cv2.drawContours(image, [cnt], 0, (0, 0, 0), -1) | |
56 | + elif len(approx) > 6 and len(approx) < 9: | |
57 | + print "Arrow" | |
58 | + cv2.drawContours(image, [cnt], 0, (255, 0, 255), -1) | |
59 | + cv2.drawContours(mask, [cnt], 0, (255,255,255), -1) | |
60 | + elif len(approx) > 19: | |
61 | + print "Circle" | |
62 | + cv2.drawContours(image, [cnt], 0, (255, 0, 0), -1) | |
63 | + cv2.imshow('Mask', mask) | |
64 | + cv2.imshow('detected shapes', image) | |
65 | + cv2.waitKey(0) | |
66 | + cv2.destroyAllWindows() | |
67 | + return | ... | ... |
... | ... | @@ -0,0 +1,63 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | + | |
4 | +def Skeletization(img, shape, size): | |
5 | + if shape == '1': | |
6 | + shape = cv2.MORPH_RECT | |
7 | + elif shape == '2': | |
8 | + shape = cv2.MORPH_ELLIPSE | |
9 | + elif shape == '3': | |
10 | + shape = cv2.MORPH_CROSS | |
11 | + else: | |
12 | + return | |
13 | + | |
14 | + cv2.normalize(img, img, 0, 255, cv2.NORM_MINMAX) | |
15 | + skeleton = np.zeros(img.shape, np.uint8) | |
16 | + eroded = np.zeros(img.shape, np.uint8) | |
17 | + temp = np.zeros(img.shape, np.uint8) | |
18 | + | |
19 | + _,thresh = cv2.threshold(img, 127, 255, 0) | |
20 | + | |
21 | + kernel = cv2.getStructuringElement(shape,(int(size), int(size))) | |
22 | + | |
23 | + while(True): | |
24 | + cv2.erode(thresh, kernel, eroded) | |
25 | + cv2.dilate(eroded, kernel, temp) | |
26 | + cv2.subtract(thresh, temp, temp) | |
27 | + cv2.bitwise_or(skeleton, temp, skeleton) | |
28 | + thresh, eroded = eroded, thresh | |
29 | + | |
30 | + if cv2.countNonZero(thresh) == 0: | |
31 | + break | |
32 | + | |
33 | + kernel = np.ones((20,20), np.uint8) | |
34 | + skeleton = cv2.morphologyEx(skeleton, cv2.MORPH_CLOSE, kernel) | |
35 | + cv2.imwrite('DefaultSkeleton.png', skeleton) | |
36 | + cv2.imshow('skeleton', skeleton) | |
37 | + return skeleton | |
38 | + | |
39 | +def KernelChoice(): | |
40 | + image = None | |
41 | + size = '0' | |
42 | + choice = '0' | |
43 | + print('\t\tSkeleton Menu\n') | |
44 | + while (image is None): | |
45 | + image = str(raw_input('\tImage to use? By default FondNoir.png \n')) | |
46 | + if not image: | |
47 | + image = 'FondNoir.png' | |
48 | + image = cv2.imread(str(image),0) | |
49 | + print('\t1. Rectangle\n\t2. Ellipse\n\t3. Cross\n') | |
50 | + while choice < '1' or choice > '3': | |
51 | + choice = raw_input('\n\tKernel Choice. Rectangle by Default\n') | |
52 | + if not choice: | |
53 | + choice = '1' | |
54 | + while int(size) % 2 == 0: | |
55 | + size = raw_input('\n\tPlease specify the kernel size (Odd number). By default it\'s 3\n') | |
56 | + if not size: | |
57 | + size = '3' | |
58 | + Skeletization(image, choice, size) | |
59 | + | |
60 | + cv2.waitKey(0) | |
61 | + cv2.destroyAllWindows() | |
62 | + | |
63 | + return | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +import Contour | |
4 | +import ColorObject | |
5 | +from Parameters import * | |
6 | + | |
7 | +def ColoredArrow(): | |
8 | + image = cv2.imread('couleur.png') | |
9 | + height, width, channels = image.shape | |
10 | + mask = np.zeros((height, width, 3), dtype = "uint8") | |
11 | + contours = Contour.FindContours(image) | |
12 | + for cnt in contours: | |
13 | + tmp = cv2.contourArea(cnt) | |
14 | + approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True) | |
15 | + if len(approx) > 6 and len(approx) < 9 and tmp > 1000: | |
16 | + print "Arrow" | |
17 | + cv2.drawContours(mask, [cnt], 0, (255,255,255), -1) | |
18 | + cv2.imshow('Mask', mask) | |
19 | + arrows = cv2.bitwise_and(image, mask) | |
20 | + cv2.imshow('Arrows', arrows) | |
21 | + cv2.imwrite('Arrows.png', arrows) | |
22 | + cv2.waitKey(0) | |
23 | + cv2.destroyAllWindows() | |
24 | + return arrows | |
25 | + | |
26 | +def FindColor(img): | |
27 | + height, width, channels = img.shape | |
28 | + blueMask, blueRes = ColorObject.IsolateObject(img, LowerBlue, UpperBlue) | |
29 | + redMask, redRes = ColorObject.IsolateObject(img, LowerRed, UpperRed) | |
30 | + greenMask, greenRes = ColorObject.IsolateObject(img, LowerGreen, UpperGreen) | |
31 | + greyRes = cv2.bitwise_xor(img, greenRes) | |
32 | + greyRes = cv2.bitwise_xor(greyRes, redRes) | |
33 | + greyRes = cv2.bitwise_xor(greyRes, blueRes) | |
34 | + kernel = np.ones((5,5),np.uint8) | |
35 | + greyRes = cv2.erode(greyRes,kernel,iterations = 1) | |
36 | + cv2.imshow('Grey Arrow', greyRes) | |
37 | + cv2.imshow('Red Arrow', redRes) | |
38 | + cv2.imshow('Blue Arrow', blueRes) | |
39 | + cv2.imshow('Green Arrow', greenRes) | |
40 | + cv2.waitKey(0) | |
41 | + cv2.destroyAllWindows() | |
42 | + return | |
43 | + | |
44 | +image = ColoredArrow() | |
45 | +FindColor(image) | ... | ... |
... | ... | @@ -0,0 +1,72 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +from matplotlib import pyplot as plt | |
4 | + | |
5 | +def ThresholdEverything(img): | |
6 | + ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) | |
7 | + th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) | |
8 | + th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) | |
9 | + titles = ['Original Image', 'Global Thresholding (v = 127)', | |
10 | + 'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding'] | |
11 | + images = [img, th1, th2, th3] | |
12 | + for i in xrange(4): | |
13 | + plt.subplot(2,2,i+1),plt.imshow(images[i],'gray') | |
14 | + plt.title(titles[i]) | |
15 | + plt.xticks([]),plt.yticks([]) | |
16 | + plt.show() | |
17 | + return images | |
18 | + | |
19 | +def GlobalThresholding(img): | |
20 | + ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) | |
21 | + plt.plot(), plt.imshow(th1, 'gray') | |
22 | + plt.title('Global Thresholding (v = 127)') | |
23 | + plt.show() | |
24 | + return th1 | |
25 | + | |
26 | +def AdaptiveMeanThresholding(img): | |
27 | + th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) | |
28 | + plt.plot(), plt.imshow(th2, 'gray') | |
29 | + plt.title('Adaptive Mean Thresholding') | |
30 | + plt.show() | |
31 | + return th2 | |
32 | + | |
33 | +def AdaptiveGaussianThresholding(img): | |
34 | + th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) | |
35 | + plt.plot(), plt.imshow(th3, 'gray') | |
36 | + plt.title('Adaptive Gaussian Thresholding') | |
37 | + plt.show() | |
38 | + return th3 | |
39 | + | |
40 | +def ThresholdChoiceProcessing(img, choice): | |
41 | + if choice == '1': | |
42 | + img = GlobalThresholding(img) | |
43 | + return img | |
44 | + elif choice == '2': | |
45 | + img = AdaptiveMeanThresholding(img) | |
46 | + return img | |
47 | + elif choice == '3': | |
48 | + img = AdaptiveGaussianThresholding(img) | |
49 | + return img | |
50 | + elif choice == '4': | |
51 | + img = ThresholdEverything(img) | |
52 | + return img | |
53 | + else: | |
54 | + return | |
55 | + | |
56 | + | |
57 | +def ThresholdChoice() : | |
58 | + image = None | |
59 | + print('\t\tThreshold Menu\n') | |
60 | + while (image is None): | |
61 | + image = str(raw_input('\tImage to use? By default couleur.png \n')) | |
62 | + if not image: | |
63 | + image = 'couleur.png' | |
64 | + image = cv2.imread(str(image), 0) | |
65 | + img = cv2.medianBlur(image,5) | |
66 | + print ('\t1. Global Thresholding\n\t2. Adaptive Mean Thresholding\n\t3. Adaptive Gaussian Thresholding\n\t4. Everything\n') | |
67 | + choice = raw_input('\n\tMultiple choices possible\n') | |
68 | + for i in range (0, len(choice)): | |
69 | + img = image.copy() | |
70 | + img = ThresholdChoiceProcessing(img, choice[i]) | |
71 | + return | |
72 | + | ... | ... |
Python/couleur.png renamed to Python/Application/couleur.png
473 KB
... | ... | @@ -0,0 +1,49 @@ |
1 | +import ColorObject | |
2 | +import Contour | |
3 | +import Gradient | |
4 | +import Skeleton2 | |
5 | +import Threshold | |
6 | +import ImageComponents | |
7 | +import ShapeDetection | |
8 | + | |
9 | +def ProcessChoiceMenu(choice): | |
10 | + if choice == '1': | |
11 | + ColorObject.ColorChoice() | |
12 | + elif choice == '2' : | |
13 | + Skeleton2.KernelChoice() | |
14 | + elif choice == '3' : | |
15 | + Contour.ContourChoice() | |
16 | + elif choice == '4' : | |
17 | + ImageComponents.Edges() | |
18 | + elif choice == '5' : | |
19 | + ImageComponents.Corners() | |
20 | + elif choice == '6' : | |
21 | + ShapeDetection.FindCircles() | |
22 | + elif choice == '7' : | |
23 | + ShapeDetection.FindShapes() | |
24 | + elif choice == '8' : | |
25 | + Gradient.GradientChoice() | |
26 | + elif choice == '9': | |
27 | + Threshold.ThresholdChoice() | |
28 | + else: | |
29 | + exit() | |
30 | + return | |
31 | + | |
32 | +def MenuApplication(): | |
33 | + print ('\t\t\tMenu Traitement d\'images \n\n') | |
34 | + print ('\t1. Find a colored object') | |
35 | + print ('\t2. Skeletisation') | |
36 | + print ('\t3. Contours') | |
37 | + print ('\t4. Canny edge detection') | |
38 | + print ('\t5. Corner detection') | |
39 | + print ('\t6. Find a circle') | |
40 | + print ('\t7. Find Basic shapes') | |
41 | + print ('\t8. Gradient') | |
42 | + print ('\t9. Threshold') | |
43 | + choice = raw_input('\n\tChoix multiple possible\n') | |
44 | + for i in range (0, len(choice)): | |
45 | + ProcessChoiceMenu(choice[i]) | |
46 | + return | |
47 | + | |
48 | +MenuApplication() | |
49 | + | ... | ... |
Python/B.png renamed to Python/Debut/B.png
260 KB
Python/Blue.png renamed to Python/Debut/Blue.png
7.65 KB
Python/BlueDrone.png renamed to Python/Debut/BlueDrone.png
177 KB
Python/CornersEdgesFleches.png renamed to Python/Debut/CornersEdgesFleches.png
393 KB
Python/CornersFleches.png renamed to Python/Debut/CornersFleches.png
369 KB
Python/G-RGB.png renamed to Python/Debut/G-RGB.png
254 KB
Python/Green.png renamed to Python/Debut/Green.png
8.88 KB
Python/GreenDrone.png renamed to Python/Debut/GreenDrone.png
170 KB
Python/ImageComponents.py renamed to Python/Debut/ImageComponents.py
Python/ImageDrone.png renamed to Python/Debut/ImageDrone.png
432 KB
Python/R-RGB.png renamed to Python/Debut/R-RGB.png
254 KB
Python/RGB_Bebop.png renamed to Python/Debut/RGB_Bebop.png
297 KB
Python/Red.png renamed to Python/Debut/Red.png
7.67 KB
Python/RedDrone.png renamed to Python/Debut/RedDrone.png
172 KB
Python/Total.png renamed to Python/Debut/Total.png
66 KB
Python/TotalMedium.png renamed to Python/Debut/TotalMedium.png
66.1 KB
Python/cornerDetectio,.png renamed to Python/Debut/cornerDetectio,.png
372 KB
473 KB
Python/couleur2.png renamed to Python/Debut/couleur2.png
492 KB
Python/flecheBleue.png renamed to Python/Debut/flecheBleue.png
279 KB
Python/flecheRouge.png renamed to Python/Debut/flecheRouge.png
271 KB
Python/flecheVerte.png renamed to Python/Debut/flecheVerte.png
269 KB
Python/fleches.png renamed to Python/Debut/fleches.png
31.2 KB
Python/test.png renamed to Python/Debut/test.png
13.6 KB
Python/test.txt renamed to Python/Debut/test.txt
No preview for this file type
No preview for this file type
No preview for this file type
... | ... | @@ -0,0 +1,89 @@ |
1 | +<div style="-webkit-column-count: 2; -moz-column-count: 2; column-count: 2; -webkit-column-rule: 1px dotted #e0e0e0; -moz-column-rule: 1px dotted #e0e0e0; column-rule: 1px dotted #e0e0e0;"> | |
2 | + <div style="display: inline-block;"> | |
3 | + | |
4 | +<h1><span style="color:red">OpenCV</span></h1> | |
5 | + | |
6 | + | |
7 | + | |
8 | +<h4><span style="color:green">Filtre</span></h4> | |
9 | +<pre> | |
10 | +filter2D() Filtre linéaire non séparable | |
11 | +sepFilter2D() Filtre linéaire séparable | |
12 | +boxFilter(), Lisse une image avec un filtre | |
13 | +GaussianBlur(), linéaire ou non linéaire | |
14 | +medianBlur(), | |
15 | +bilateralFilter(). | |
16 | +Sobel(),Scharr() Calcule les dérivées de l'image spatiale | |
17 | +Laplatian() Calcule le Laplacien | |
18 | +exode(),dilate() Opérations morphologiques | |
19 | +</pre> | |
20 | +<h4><span style="color:green">Histogrammes</span></h4> | |
21 | +<pre> | |
22 | +calcHist() Calcule l'histogramme d'une image | |
23 | +calcBackProject() Projette l'histogrmme | |
24 | +equalizeHist() Normalise le contraste et la luminosité | |
25 | + d'une image | |
26 | +compareHist() Compare deux histogrammes</pre> | |
27 | +<h4><span style="color:green">Détection d'objets</span></h4> | |
28 | +<pre> | |
29 | +matchTemplate Calcule la carte de distance pour un modèle | |
30 | + donné | |
31 | +CascadeClassifier | |
32 | +HOGDescriptor Détecteur d'objets de N. Dalal utilisant | |
33 | + l'histogramme des gradients orientés (HOG). | |
34 | +</pre> | |
35 | +<h4><span style="color:green">Manipulation de matrices</span></h4> | |
36 | +<pre> | |
37 | +src.copyTo(dst) Copie une matrice vers une autre | |
38 | +m.clone() Fait une copie d'une matrice | |
39 | +m.reshape(ch,rows) Change les dimensions d'une matrice ou son | |
40 | + nombre de canaux sans copier les données | |
41 | +m.row(i),m.col(i) Prend la ligne/colonne d'une matrice | |
42 | +m.rowRange(Range()) Prend un intervalle de lignes/colonnes | |
43 | +m.colRange(Range()) | |
44 | +m.diag(i) Prend la diagonale d'une matrice | |
45 | +m(Range(),Range()) Prend une sous-matrice | |
46 | +split() Sépare les canaux d'une matrice | |
47 | +merge() Fusionne plusieurs canaux dans une matrice</pre> | |
48 | +</div> | |
49 | + | |
50 | + <h4> <span style="color:green">Transformations géométriques</span></h4> | |
51 | + <pre> | |
52 | + resize() Redimensionne l'image | |
53 | + getRectSubPix() Extrait un patch | |
54 | + warpAffine() Déforme une image affinement | |
55 | + warpPerspective() Déforme une image perspectivement | |
56 | + remap() Déformation d'image générique | |
57 | + convertMaps() Optimise les chemins pour une exécution | |
58 | + plus rapide de remap()</pre> | |
59 | + <h4> <span style="color:green">Diverses transformations d'image</span></h4> | |
60 | + <pre> | |
61 | + cvtColor() Convertit une image d'un espace | |
62 | + de couleur à l'autre | |
63 | + threshold() Convertit une image niveau de gris en | |
64 | + image binaire | |
65 | + adaptivethreshold() Utilise un seuil fixe ou variable | |
66 | + floodFill() Trouve un composant connecté en utilisant | |
67 | + un algorithme de croissance de région | |
68 | + integral() Calcule l'intégral d'une image | |
69 | + distanceTransform() Construit une carte de distance ou un | |
70 | + diagramme discret de Voronir pour une | |
71 | + image binaire | |
72 | + watershed() Algorithmes degmentation d'image à base | |
73 | + grabCut() de marqueurs</pre> | |
74 | + | |
75 | + <h4> <span style="color:green">Opérations arithmétiques</span></h4> | |
76 | + <pre> | |
77 | + bitwise_and() Opérations booléennes sur deux images | |
78 | + bitwise_or() | |
79 | + bitwise_xor() | |
80 | + add() Additions de deux images | |
81 | + addWeighted() Mélange de deux images</pre> | |
82 | + <div style="display: inline-block;"> | |
83 | + <h4> <span style="color:green">Interface Graphique Simple</span></h4> | |
84 | + <pre> | |
85 | + destroyWindow(name) Détruit la fenêtre spécifiée | |
86 | + imshow(name, img) Affiche une image dans une fenêtre | |
87 | + waitKey(delay) Attend un appui de touche pendant le temps spécifié </pre> | |
88 | + | |
89 | + </div> | |
0 | 90 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,44 @@ |
1 | +import cv2 | |
2 | +import numpy as np | |
3 | +from matplotlib import pyplot as plt | |
4 | + | |
5 | +image = cv2.imread('couleur.png') | |
6 | +bilateral = cv2.bilateralFilter(image, 5, 75, 75) | |
7 | +blur = cv2.blur(image, (5, 5)) | |
8 | +box = cv2.boxFilter(image, -1, (5, 5)) | |
9 | +DD = cv2.filter2D(image, -1, (5, 5)) | |
10 | +gaussian = cv2.GaussianBlur(image, (5, 5), 50) | |
11 | +median = cv2.medianBlur(image, 5) | |
12 | +sep = cv2.sepFilter2D(image, -1, 75, 75) | |
13 | + | |
14 | +kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]]) | |
15 | +im = cv2.filter2D(image, -1, kernel) | |
16 | +bilateral2 = cv2.bilateralFilter(im, 5, 150, 150) | |
17 | + | |
18 | +plt.subplot(2,3,1),plt.imshow(image) | |
19 | +plt.title('Original'), plt.xticks([]), plt.yticks([]) | |
20 | +plt.subplot(2,3,2),plt.imshow(bilateral) | |
21 | +plt.title('Bilateral Filter'), plt.xticks([]), plt.yticks([]) | |
22 | +plt.subplot(2,3,3),plt.imshow(blur) | |
23 | +plt.title('Blur'), plt.xticks([]), plt.yticks([]) | |
24 | +plt.subplot(2,3,4),plt.imshow(box) | |
25 | +plt.title('Box Filter'), plt.xticks([]), plt.yticks([]) | |
26 | +plt.subplot(2,3,5),plt.imshow(gaussian) | |
27 | +plt.title('Gaussian Filter'), plt.xticks([]), plt.yticks([]) | |
28 | +plt.subplot(2,3,6),plt.imshow(median) | |
29 | +plt.title('Median Blur'), plt.xticks([]), plt.yticks([]) | |
30 | +plt.show() | |
31 | + | |
32 | +cv2.imshow('Sharp', im) | |
33 | +cv2.imshow('Bilateral', bilateral2) | |
34 | +#cv2.imshow('original', image) | |
35 | +#cv2.imshow('bilateral filter', bilateral) | |
36 | +#cv2.imshow('blur', blur) | |
37 | +#cv2.imshow('box', box) | |
38 | +#cv2.imshow('filter 2D', DD) | |
39 | +#cv2.imshow('gaussian filter', gaussian) | |
40 | +#cv2.imshow('median blur', median) | |
41 | +#cv2.imshow('sep Filter 2D', sep) | |
42 | + | |
43 | +cv2.waitKey(0) | |
44 | +cv2.destroyAllWindows() | ... | ... |
473 KB