import cv2 import numpy as np from matplotlib import pyplot as plt def auto_canny(image, sigma=0.33): median = np.median(image) lower = int(max(0, (1.0 - sigma) * median)) upper = int(min(255, (1.0 + sigma) * median)) edged = cv2.Canny(image, lower, upper, L2gradient=True) return edged def findPlane(pic): img = cv2.imread(pic,0) #0 -w odc szarosci edges = cv2.GaussianBlur(img, (3, 3), 0) #filtr gaussowski edges = auto_canny(edges) #canny edges = cv2.blur(edges, (5, 5)) #blur image, contours, hierarchy = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) #pobieram krawedzie edges = cv2.drawContours(edges, contours, -1, (255, 255, 255), cv2.FILLED) #nakladam wypelnione krawedzie edges = auto_canny(edges) cv2.imwrite("edged-" + pic, edges) #zapis obrazka return edges pics = ['samolot17.jpg','samolot07.jpg','samolot08.jpg','samolot09.jpg','samolot10.jpg','samolot14.jpg'] fig = plt.figure(1) fig.subplots_adjust(wspace=0, hspace=0, top=1, bottom=0, left=0, right=1) for each in pics: ax = fig.add_subplot(3, 2, pics.index(each) + 1) new_pic = findPlane(each) height, width = new_pic.shape[:2] #skalowanie dla lepszego rysowania max_height = 200 max_width = 300 scaling_factor = max_height / float(height) new_pic = cv2.resize(new_pic, None, fx=scaling_factor, fy=scaling_factor, interpolation=cv2.INTER_AREA) ax.imshow(new_pic, cmap="gray", aspect='auto') plt.show() key = cv2.waitKey()