diff --git a/Python/Application/ColorObject.py b/Python/Application/ColorObject.py new file mode 100644 index 0000000..fcf44ea --- /dev/null +++ b/Python/Application/ColorObject.py @@ -0,0 +1,76 @@ +import cv2 +import numpy as np +from Parameters import * + +def IsolateObject(frame ,Lower, Upper): + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) + mask = cv2.inRange(hsv, Lower, Upper) + kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5)) + mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) + res = cv2.bitwise_and(frame,frame, mask= mask) + return mask, res + +def ColorDisplayResults(liste, nb): + for i in range (0, len(liste)): + if i == 0: + titre = 'mask'+str(nb) + else: + titre = 'res'+str(nb) + cv2.imshow(titre, liste[i]) + return + +def CombineColors(color1, color2): + mask = cv2.bitwise_or(color1[0], color2[0]) + res = cv2.bitwise_or(color1[1], color2[1]) + return mask, res + +def ColorChoiceProcessing(image, choix): + if choix == '1': + blueMask, blueRes = IsolateObject(image, LowerBlue, UpperBlue) + return [blueMask, blueRes] + elif choix == '2': + greenMask, greenRes = IsolateObject(image, LowerGreen, UpperGreen) + return [greenMask, greenRes] + elif choix == '3': + redMask, redRes = IsolateObject(image, LowerRed, UpperRed) + return[redMask, redRes] + elif choix == '4': + blue = ColorChoiceProcessing(image, '1') + green = ColorChoiceProcessing(image, '2') + bgMask, bgRes = CombineColors(blue, green) + return [bgMask, bgRes] + elif choix == '5': + blue = ColorChoiceProcessing(image, '1') + red = ColorChoiceProcessing(image, '3') + brMask, brRes = CombineColors(blue, red) + return [brMask, brRes] + elif choix == '6': + red = ColorChoiceProcessing(image, '3') + green = ColorChoiceProcessing(image, '2') + rgMask, rgRes = CombineColors(red, green) + return [rgMask, rgRes] + elif choix == '7': + bg = ColorChoiceProcessing(image, '4') + red = ColorChoiceProcessing(image, '3') + bgrMask, bgrRes = CombineColors(bg, red) + return [bgrMask, bgrRes] + else: + return + +def ColorChoice() : + image = None + print('\t\tFind Color Object Menu\n') + while (image is None): + image = str(raw_input('\tImage to use ? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(image)) + 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') + choix = raw_input('\n\tMultiple choices possible\n') + for i in range (0, len(choix)): + liste = ColorChoiceProcessing(image, choix[i]) + if liste : + ColorDisplayResults(liste,choix[i]) + cv2.waitKey(0) + cv2.destroyAllWindows() + return diff --git a/Python/Application/Contour.py b/Python/Application/Contour.py new file mode 100644 index 0000000..83115fb --- /dev/null +++ b/Python/Application/Contour.py @@ -0,0 +1,130 @@ +import cv2 +import numpy as np +import numpy as np +import cv2 + +def FindContours(img): + imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) + #cv2.imshow("Gray", imgray) + ret,thresh = cv2.threshold(imgray,127,255,0) + #cv2.imshow("threshold", thresh) + _,contours,hierarchy = cv2.findContours(thresh, 1, 2) + return contours + +def FindCenterofMass(contours): + liste = [] + area = [] + centerMass = [] + for i in range (0,len(contours)): + cnt = contours[i] + #print cnt + M = cv2.moments(cnt) + area.append(cv2.contourArea(cnt)) + tmp = cv2.contourArea(cnt) + if (M['m00'] != 0) and (tmp > 1000): + cx = int(M['m10']/M['m00']) + cy = int(M['m01']/M['m00']) + centerMass.append((cx,cy)) + else: + liste.append(i) + return liste, area, centerMass + + + +def CleanContours(img): + contours = FindContours(img) + liste, _, _ = FindCenterofMass(contours) + for j in range (0,len(liste)): + a = liste[j] + if (a < len(contours)): + contours.pop(a) + return contours + +def DrawBoundingBox(img): + contours = FindContours(img) + for cnt in contours: + x,y,w,h = cv2.boundingRect(cnt) + img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2) + cv2.imshow('Bounding Box', img) + return img + +def DrawEnclosingCircle(img): + contours = FindContours(img) + for cnt in contours: + (x,y),radius = cv2.minEnclosingCircle(cnt) + center = (int(x),int(y)) + radius = int(radius) + img = cv2.circle(img,center,radius,(0,255,0),2) + cv2.imshow('Enclosing Circle', img) + return img + +def DrawContours(img, contours, titre): + img = cv2.drawContours(img, contours, -1, (0,255,0), 3) + cv2.imshow(titre, img) + return img + +def DrawCenterofMass(img): + contours = FindContours(img) + _, _, centerMass = FindCenterofMass(contours) + for x, y in centerMass: + img=cv2.circle(img, (x,y), 10, (124,255,255), 1) + cv2.imshow('Center of Mass', img) + return img + +def DrawArea(img): + contours = CleanContours(img) + img = cv2.drawContours(img, contours, -1, (255, 0, 0), cv2.FILLED) + cv2.imshow('Area', img) + return img + +def ContourChoiceProcessing(img, choice): + if choice == '1': + contours = FindContours(img) + img = DrawContours(img, contours, 'Contours') + return img + elif choice == '2': + contours = CleanContours(img) + img = DrawContours(img, contours, 'Clean Contours') + return img + elif choice == '3': + img = DrawCenterofMass(img) + return img + elif choice == '4': + img = DrawArea(img) + return img + elif choice == '5': + img = ContourChoiceProcessing(img, '2') + img = DrawCenterofMass(img) + return img + elif choice == '6': + img = DrawArea(img) + img = DrawCenterofMass(img) + return img + elif choice == '7': + img = DrawBoundingBox(img) + return img + elif choice == '8': + img = DrawEnclosingCircle(img) + return img + else: + return + +def ContourChoice(): + image = None + img = None + print('\t\tContours Features Menu\n') + while (image is None): + image = str(raw_input('\tImage to use? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(image)) + 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') + choix = raw_input('\n\tMultiple choices possible\n') + for i in range (0, len(choix)): + img = image.copy() + img = ContourChoiceProcessing(img, choix[i]) + if img is not None: + cv2.waitKey(0) + cv2.destroyAllWindows() + return + diff --git a/Python/Application/FondNoir.png b/Python/Application/FondNoir.png new file mode 100644 index 0000000..01295d6 Binary files /dev/null and b/Python/Application/FondNoir.png differ diff --git a/Python/Application/Gradient.py b/Python/Application/Gradient.py new file mode 100644 index 0000000..0f42a73 --- /dev/null +++ b/Python/Application/Gradient.py @@ -0,0 +1,73 @@ +import cv2 +import numpy as np +from matplotlib import pyplot as plt +img = cv2.imread('couleur.png',0) + +def Everything (img): + laplacian = cv2.Laplacian(img,cv2.CV_64F) + sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) + sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) + plt.subplot(2,2,1),plt.imshow(img,cmap = 'gray') + plt.title('Original'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,2),plt.imshow(laplacian,cmap = 'gray') + plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,3),plt.imshow(sobelx,cmap = 'gray') + plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) + plt.subplot(2,2,4),plt.imshow(sobely,cmap = 'gray') + plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) + plt.show() + return laplacian + +def Laplacian(img): + laplacian = cv2.Laplacian(img,cv2.CV_64F) + plt.plot,plt.imshow(laplacian,cmap = 'gray') + plt.title('Laplacian'), plt.xticks([]), plt.yticks([]) + plt.show() + return laplacian + +def SobelX(img): + sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5) + plt.plot,plt.imshow(sobelx,cmap = 'gray') + plt.title('Sobel X'), plt.xticks([]), plt.yticks([]) + plt.show() + return sobelx + +def SobelY(img): + sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5) + plt.plot,plt.imshow(sobely,cmap = 'gray') + plt.title('Sobel Y'), plt.xticks([]), plt.yticks([]) + plt.show() + return sobely + +def GradientChoiceProcessing(img, choice): + if choice == '1': + img = Laplacian(img) + return img + elif choice == '2': + img = SobelX(img) + return img + elif choice == '3': + img = SobelY(img) + return img + elif choice == '4': + img = Everything(img) + return img + else: + return + + +def GradientChoice() : + image = None + print('\t\tGradient Menu\n') + while (image is None): + image = str(raw_input('\tImage to use? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(image), 0) + print ('\t1. Laplacian\n\t2. Sobel X\n\t3. Sobel Y\n\t4. Everything\n') + choice = raw_input('\n\tMultiple choices possible\n') + for i in range (0, len(choice)): + img = image.copy() + img = GradientChoiceProcessing(img, choice[i]) + return + diff --git a/Python/Application/ImageComponents.py b/Python/Application/ImageComponents.py new file mode 100644 index 0000000..3cc6e90 --- /dev/null +++ b/Python/Application/ImageComponents.py @@ -0,0 +1,37 @@ +import cv2 +import numpy as np +from matplotlib import pyplot as plt + +def Corners(): + image = None + while (image is None): + image = str(raw_input('\tImage to use ? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(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) + cv2.waitKey(0) + cv2.destroyAllWindows() + return + +def Edges(): + image = None + while (image is None): + image = str(raw_input('\tImage to use ? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(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 diff --git a/Python/Application/Parameters.py b/Python/Application/Parameters.py new file mode 100644 index 0000000..066dab3 --- /dev/null +++ b/Python/Application/Parameters.py @@ -0,0 +1,8 @@ +import numpy as np + +LowerBlue = np.array([102,50,50]) +UpperBlue = np.array([107,255,255]) +LowerRed = np.array([0,50,50]) +UpperRed = np.array([11,255,255]) +LowerGreen = np.array([60,50,50]) +UpperGreen = np.array([80, 255, 255]) diff --git a/Python/Application/ShapeDetection.py b/Python/Application/ShapeDetection.py new file mode 100644 index 0000000..b869f58 --- /dev/null +++ b/Python/Application/ShapeDetection.py @@ -0,0 +1,67 @@ +import cv2 +import numpy as np +import Contour + +##!!!!!Faire le pretraitement + +#Test : Luminosite, orientation dans l'espace, distance +#Etudier les limites + +def FindCircles(): + image = None + while (image is None): + image = str(raw_input('\tImage to use ? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(image), 0) + img = cv2.medianBlur(image, 5) + cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) + circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 20, param1 = 50, param2 = 30, minRadius = 0, maxRadius = 0) + circles = np.uint16(np.around(circles)) + for i in circles[0,:]: + cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2) + cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3) + + cv2.imshow('detected circles',cimg) + cv2.waitKey(0) + cv2.destroyAllWindows() + return + +def FindShapes(): + image = None + while (image is None): + image = str(raw_input('\tImage to use ? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(image)) + height, width, channels = image.shape + mask = np.zeros((height, width, 3), dtype = "uint8") + contours = Contour.FindContours(image) + img = image.copy() + #Contour.DrawContours(img, contours, "Contours Shape Detection") + for cnt in contours: + approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True) + if len(approx) == 3 : + print "Triangle" + cv2.drawContours(image, [cnt], 0, (255, 255, 0), -1) + elif len(approx) == 4: + print "Square" + cv2.drawContours(image, [cnt], 0, (255, 255, 255), -1) + elif len(approx) == 5: + print "Pentagon" + cv2.drawContours(image, [cnt], 0, (0, 255, 0), -1) + #elif len(approx) == 8: + # print "Huit" + # cv2.drawContours(image, [cnt], 0, (0, 0, 0), -1) + elif len(approx) > 6 and len(approx) < 9: + print "Arrow" + cv2.drawContours(image, [cnt], 0, (255, 0, 255), -1) + cv2.drawContours(mask, [cnt], 0, (255,255,255), -1) + elif len(approx) > 19: + print "Circle" + cv2.drawContours(image, [cnt], 0, (255, 0, 0), -1) + cv2.imshow('Mask', mask) + cv2.imshow('detected shapes', image) + cv2.waitKey(0) + cv2.destroyAllWindows() + return diff --git a/Python/Application/Skeleton2.py b/Python/Application/Skeleton2.py new file mode 100644 index 0000000..748186f --- /dev/null +++ b/Python/Application/Skeleton2.py @@ -0,0 +1,63 @@ +import cv2 +import numpy as np + +def Skeletization(img, shape, size): + if shape == '1': + shape = cv2.MORPH_RECT + elif shape == '2': + shape = cv2.MORPH_ELLIPSE + elif shape == '3': + shape = cv2.MORPH_CROSS + else: + return + + cv2.normalize(img, img, 0, 255, cv2.NORM_MINMAX) + skeleton = np.zeros(img.shape, np.uint8) + eroded = np.zeros(img.shape, np.uint8) + temp = np.zeros(img.shape, np.uint8) + + _,thresh = cv2.threshold(img, 127, 255, 0) + + kernel = cv2.getStructuringElement(shape,(int(size), int(size))) + + while(True): + cv2.erode(thresh, kernel, eroded) + cv2.dilate(eroded, kernel, temp) + cv2.subtract(thresh, temp, temp) + cv2.bitwise_or(skeleton, temp, skeleton) + thresh, eroded = eroded, thresh + + if cv2.countNonZero(thresh) == 0: + break + + kernel = np.ones((20,20), np.uint8) + skeleton = cv2.morphologyEx(skeleton, cv2.MORPH_CLOSE, kernel) + cv2.imwrite('DefaultSkeleton.png', skeleton) + cv2.imshow('skeleton', skeleton) + return skeleton + +def KernelChoice(): + image = None + size = '0' + choice = '0' + print('\t\tSkeleton Menu\n') + while (image is None): + image = str(raw_input('\tImage to use? By default FondNoir.png \n')) + if not image: + image = 'FondNoir.png' + image = cv2.imread(str(image),0) + print('\t1. Rectangle\n\t2. Ellipse\n\t3. Cross\n') + while choice < '1' or choice > '3': + choice = raw_input('\n\tKernel Choice. Rectangle by Default\n') + if not choice: + choice = '1' + while int(size) % 2 == 0: + size = raw_input('\n\tPlease specify the kernel size (Odd number). By default it\'s 3\n') + if not size: + size = '3' + Skeletization(image, choice, size) + + cv2.waitKey(0) + cv2.destroyAllWindows() + + return diff --git a/Python/Application/Test.py b/Python/Application/Test.py new file mode 100644 index 0000000..73a8bcc --- /dev/null +++ b/Python/Application/Test.py @@ -0,0 +1,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) diff --git a/Python/Application/Threshold.py b/Python/Application/Threshold.py new file mode 100644 index 0000000..8911c01 --- /dev/null +++ b/Python/Application/Threshold.py @@ -0,0 +1,72 @@ +import cv2 +import numpy as np +from matplotlib import pyplot as plt + +def ThresholdEverything(img): + ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) + th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) + th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) + titles = ['Original Image', 'Global Thresholding (v = 127)', + 'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding'] + images = [img, th1, th2, th3] + for i in xrange(4): + plt.subplot(2,2,i+1),plt.imshow(images[i],'gray') + plt.title(titles[i]) + plt.xticks([]),plt.yticks([]) + plt.show() + return images + +def GlobalThresholding(img): + ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY) + plt.plot(), plt.imshow(th1, 'gray') + plt.title('Global Thresholding (v = 127)') + plt.show() + return th1 + +def AdaptiveMeanThresholding(img): + th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) + plt.plot(), plt.imshow(th2, 'gray') + plt.title('Adaptive Mean Thresholding') + plt.show() + return th2 + +def AdaptiveGaussianThresholding(img): + th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) + plt.plot(), plt.imshow(th3, 'gray') + plt.title('Adaptive Gaussian Thresholding') + plt.show() + return th3 + +def ThresholdChoiceProcessing(img, choice): + if choice == '1': + img = GlobalThresholding(img) + return img + elif choice == '2': + img = AdaptiveMeanThresholding(img) + return img + elif choice == '3': + img = AdaptiveGaussianThresholding(img) + return img + elif choice == '4': + img = ThresholdEverything(img) + return img + else: + return + + +def ThresholdChoice() : + image = None + print('\t\tThreshold Menu\n') + while (image is None): + image = str(raw_input('\tImage to use? By default couleur.png \n')) + if not image: + image = 'couleur.png' + image = cv2.imread(str(image), 0) + img = cv2.medianBlur(image,5) + print ('\t1. Global Thresholding\n\t2. Adaptive Mean Thresholding\n\t3. Adaptive Gaussian Thresholding\n\t4. Everything\n') + choice = raw_input('\n\tMultiple choices possible\n') + for i in range (0, len(choice)): + img = image.copy() + img = ThresholdChoiceProcessing(img, choice[i]) + return + diff --git a/Python/Application/couleur.png b/Python/Application/couleur.png new file mode 100644 index 0000000..eaf0d73 Binary files /dev/null and b/Python/Application/couleur.png differ diff --git a/Python/Application/main.py b/Python/Application/main.py new file mode 100644 index 0000000..9f152f2 --- /dev/null +++ b/Python/Application/main.py @@ -0,0 +1,49 @@ +import ColorObject +import Contour +import Gradient +import Skeleton2 +import Threshold +import ImageComponents +import ShapeDetection + +def ProcessChoiceMenu(choice): + if choice == '1': + ColorObject.ColorChoice() + elif choice == '2' : + Skeleton2.KernelChoice() + elif choice == '3' : + Contour.ContourChoice() + elif choice == '4' : + ImageComponents.Edges() + elif choice == '5' : + ImageComponents.Corners() + elif choice == '6' : + ShapeDetection.FindCircles() + elif choice == '7' : + ShapeDetection.FindShapes() + elif choice == '8' : + Gradient.GradientChoice() + elif choice == '9': + Threshold.ThresholdChoice() + else: + exit() + return + +def MenuApplication(): + print ('\t\t\tMenu Traitement d\'images \n\n') + print ('\t1. Find a colored object') + print ('\t2. Skeletisation') + print ('\t3. Contours') + print ('\t4. Canny edge detection') + print ('\t5. Corner detection') + print ('\t6. Find a circle') + print ('\t7. Find Basic shapes') + print ('\t8. Gradient') + print ('\t9. Threshold') + choice = raw_input('\n\tChoix multiple possible\n') + for i in range (0, len(choice)): + ProcessChoiceMenu(choice[i]) + return + +MenuApplication() + diff --git a/Python/B.png b/Python/B.png deleted file mode 100644 index dec34b9..0000000 Binary files a/Python/B.png and /dev/null differ diff --git a/Python/Blue.png b/Python/Blue.png deleted file mode 100644 index 77c2592..0000000 Binary files a/Python/Blue.png and /dev/null differ diff --git a/Python/BlueDrone.png b/Python/BlueDrone.png deleted file mode 100644 index 064eca7..0000000 Binary files a/Python/BlueDrone.png and /dev/null differ diff --git a/Python/CornersEdgesFleches.png b/Python/CornersEdgesFleches.png deleted file mode 100644 index c6c14ea..0000000 Binary files a/Python/CornersEdgesFleches.png and /dev/null differ diff --git a/Python/CornersFleches.png b/Python/CornersFleches.png deleted file mode 100644 index 14b9d1c..0000000 Binary files a/Python/CornersFleches.png and /dev/null differ diff --git a/Python/Debut/B.png b/Python/Debut/B.png new file mode 100644 index 0000000..dec34b9 Binary files /dev/null and b/Python/Debut/B.png differ diff --git a/Python/Debut/Blue.png b/Python/Debut/Blue.png new file mode 100644 index 0000000..77c2592 Binary files /dev/null and b/Python/Debut/Blue.png differ diff --git a/Python/Debut/BlueDrone.png b/Python/Debut/BlueDrone.png new file mode 100644 index 0000000..064eca7 Binary files /dev/null and b/Python/Debut/BlueDrone.png differ diff --git a/Python/Debut/CornersEdgesFleches.png b/Python/Debut/CornersEdgesFleches.png new file mode 100644 index 0000000..c6c14ea Binary files /dev/null and b/Python/Debut/CornersEdgesFleches.png differ diff --git a/Python/Debut/CornersFleches.png b/Python/Debut/CornersFleches.png new file mode 100644 index 0000000..14b9d1c Binary files /dev/null and b/Python/Debut/CornersFleches.png differ diff --git a/Python/Debut/G-RGB.png b/Python/Debut/G-RGB.png new file mode 100644 index 0000000..04fabe9 Binary files /dev/null and b/Python/Debut/G-RGB.png differ diff --git a/Python/Debut/Green.png b/Python/Debut/Green.png new file mode 100644 index 0000000..6d0829f Binary files /dev/null and b/Python/Debut/Green.png differ diff --git a/Python/Debut/GreenDrone.png b/Python/Debut/GreenDrone.png new file mode 100644 index 0000000..f934341 Binary files /dev/null and b/Python/Debut/GreenDrone.png differ diff --git a/Python/Debut/ImageComponents.py b/Python/Debut/ImageComponents.py new file mode 100644 index 0000000..b91cfac --- /dev/null +++ b/Python/Debut/ImageComponents.py @@ -0,0 +1,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) diff --git a/Python/Debut/ImageDrone.png b/Python/Debut/ImageDrone.png new file mode 100644 index 0000000..e62ee70 Binary files /dev/null and b/Python/Debut/ImageDrone.png differ diff --git a/Python/Debut/R-RGB.png b/Python/Debut/R-RGB.png new file mode 100644 index 0000000..145bc51 Binary files /dev/null and b/Python/Debut/R-RGB.png differ diff --git a/Python/Debut/RGB_Bebop.png b/Python/Debut/RGB_Bebop.png new file mode 100644 index 0000000..f4d6073 Binary files /dev/null and b/Python/Debut/RGB_Bebop.png differ diff --git a/Python/Debut/Red.png b/Python/Debut/Red.png new file mode 100644 index 0000000..ee92eb6 Binary files /dev/null and b/Python/Debut/Red.png differ diff --git a/Python/Debut/RedDrone.png b/Python/Debut/RedDrone.png new file mode 100644 index 0000000..235e557 Binary files /dev/null and b/Python/Debut/RedDrone.png differ diff --git a/Python/Debut/Total.png b/Python/Debut/Total.png new file mode 100644 index 0000000..be805e5 Binary files /dev/null and b/Python/Debut/Total.png differ diff --git a/Python/Debut/TotalMedium.png b/Python/Debut/TotalMedium.png new file mode 100644 index 0000000..8b71da5 Binary files /dev/null and b/Python/Debut/TotalMedium.png differ diff --git a/Python/Debut/cornerDetectio,.png b/Python/Debut/cornerDetectio,.png new file mode 100644 index 0000000..0f55a6f Binary files /dev/null and b/Python/Debut/cornerDetectio,.png differ diff --git a/Python/Debut/couleur.png b/Python/Debut/couleur.png new file mode 100644 index 0000000..eaf0d73 Binary files /dev/null and b/Python/Debut/couleur.png differ diff --git a/Python/Debut/couleur2.png b/Python/Debut/couleur2.png new file mode 100644 index 0000000..21ee4e8 Binary files /dev/null and b/Python/Debut/couleur2.png differ diff --git a/Python/Debut/flecheBleue.png b/Python/Debut/flecheBleue.png new file mode 100644 index 0000000..bcd2bea Binary files /dev/null and b/Python/Debut/flecheBleue.png differ diff --git a/Python/Debut/flecheRouge.png b/Python/Debut/flecheRouge.png new file mode 100644 index 0000000..51c6294 Binary files /dev/null and b/Python/Debut/flecheRouge.png differ diff --git a/Python/Debut/flecheVerte.png b/Python/Debut/flecheVerte.png new file mode 100644 index 0000000..08c130f Binary files /dev/null and b/Python/Debut/flecheVerte.png differ diff --git a/Python/Debut/fleches.png b/Python/Debut/fleches.png new file mode 100644 index 0000000..8f26de8 Binary files /dev/null and b/Python/Debut/fleches.png differ diff --git a/Python/Debut/test.png b/Python/Debut/test.png new file mode 100644 index 0000000..e8b9746 Binary files /dev/null and b/Python/Debut/test.png differ diff --git a/Python/Debut/test.txt b/Python/Debut/test.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Python/Debut/test.txt diff --git a/Python/Documentation/ROScheatsheet.pdf b/Python/Documentation/ROScheatsheet.pdf new file mode 100644 index 0000000..3c7e4a2 Binary files /dev/null and b/Python/Documentation/ROScheatsheet.pdf differ diff --git a/Python/Documentation/opencv-python-tutroals.pdf b/Python/Documentation/opencv-python-tutroals.pdf new file mode 100644 index 0000000..2fed8d4 Binary files /dev/null and b/Python/Documentation/opencv-python-tutroals.pdf differ diff --git a/Python/Documentation/opencv_cheatsheet.pdf b/Python/Documentation/opencv_cheatsheet.pdf new file mode 100644 index 0000000..5fdfbba Binary files /dev/null and b/Python/Documentation/opencv_cheatsheet.pdf differ diff --git a/Python/Documentation/opencv_python_cheatsheet b/Python/Documentation/opencv_python_cheatsheet new file mode 100644 index 0000000..fe75d32 --- /dev/null +++ b/Python/Documentation/opencv_python_cheatsheet @@ -0,0 +1,89 @@ +
+filter2D() Filtre linéaire non séparable +sepFilter2D() Filtre linéaire séparable +boxFilter(), Lisse une image avec un filtre +GaussianBlur(), linéaire ou non linéaire +medianBlur(), +bilateralFilter(). +Sobel(),Scharr() Calcule les dérivées de l'image spatiale +Laplatian() Calcule le Laplacien +exode(),dilate() Opérations morphologiques ++
+calcHist() Calcule l'histogramme d'une image +calcBackProject() Projette l'histogrmme +equalizeHist() Normalise le contraste et la luminosité + d'une image +compareHist() Compare deux histogrammes+
+matchTemplate Calcule la carte de distance pour un modèle + donné +CascadeClassifier +HOGDescriptor Détecteur d'objets de N. Dalal utilisant + l'histogramme des gradients orientés (HOG). ++
+src.copyTo(dst) Copie une matrice vers une autre +m.clone() Fait une copie d'une matrice +m.reshape(ch,rows) Change les dimensions d'une matrice ou son + nombre de canaux sans copier les données +m.row(i),m.col(i) Prend la ligne/colonne d'une matrice +m.rowRange(Range()) Prend un intervalle de lignes/colonnes +m.colRange(Range()) +m.diag(i) Prend la diagonale d'une matrice +m(Range(),Range()) Prend une sous-matrice +split() Sépare les canaux d'une matrice +merge() Fusionne plusieurs canaux dans une matrice+
+ resize() Redimensionne l'image + getRectSubPix() Extrait un patch + warpAffine() Déforme une image affinement + warpPerspective() Déforme une image perspectivement + remap() Déformation d'image générique + convertMaps() Optimise les chemins pour une exécution + plus rapide de remap()+
+ cvtColor() Convertit une image d'un espace + de couleur à l'autre + threshold() Convertit une image niveau de gris en + image binaire + adaptivethreshold() Utilise un seuil fixe ou variable + floodFill() Trouve un composant connecté en utilisant + un algorithme de croissance de région + integral() Calcule l'intégral d'une image + distanceTransform() Construit une carte de distance ou un + diagramme discret de Voronir pour une + image binaire + watershed() Algorithmes degmentation d'image à base + grabCut() de marqueurs+ +
+ bitwise_and() Opérations booléennes sur deux images + bitwise_or() + bitwise_xor() + add() Additions de deux images + addWeighted() Mélange de deux images+
+ destroyWindow(name) Détruit la fenêtre spécifiée + imshow(name, img) Affiche une image dans une fenêtre + waitKey(delay) Attend un appui de touche pendant le temps spécifié+ +