def canny(imgray): # zamagljivanje slike pomoćću Gaussian filtera, korisno za uklanjanje šuma # zapravo uklnja visoke frekvencije (šumove, ivice) sa slike img_gaussian = cv2.GaussianBlur(imgray, (5,5), 200) my.display_image('3. gaussian', img_gaussian) canny_low = 50 #5 canny_high = 200 #150 # pronalazi ivice na slici pomoću Canny algoritma # pomoću 1. i 2. threshold-a za histesisnu proceduru img_canny = cv2.Canny(img_gaussian,canny_low,canny_high) my.display_image('4. canny', img_canny) return img_canny
# -*- coding: utf-8 -*- """ Created on Wed Jun 22 16:38:27 2016 @author: Milos """ import notebookOperacije as my # TODO - IMAGE PROCESSING # ucitavanje digitalne slike img_color = my.load_image('images/stop15.jpg') my.plt.figure(1) my.display_image('Ucitavanje digitalne slike', img_color) # formiranje grayscale slike img_grayscale = my.image_gray((img_color)) my.plt.figure(2) my.display_image('Formiranje grayscale slike', img_grayscale) # formiranje binarne slike img_bin = my.image_bin_adaptive(img_grayscale) my.plt.figure(3) my.display_image('Formiranje binarne slike', img_bin) # uklanjanje šuma sa binarne slike img_no_noise = my.remove_noiseColor(img_bin) my.plt.figure(4) my.display_image('img_bin sa remove_noise', img_no_noise) # pronalaženje regiona od interesa
Created on Sun Jun 26 18:01:03 2016 @author: Milos """ import notebookOperacije as my import cv2 import numpy as np # TODO - IMAGE PROCESSING img_path = 'images/obucavajuciSkup13.jpg' # ucitavanje digitalne slike img_color = my.load_image(img_path) my.plt.figure(1) my.display_image('TRAIN_Ucitavanje digitalne slike', img_color) # ucitavanje hsv slikes img_hsv = my.load_imageHSV(img_path) my.plt.figure(5) my.display_image('TRAIN_img_hsv', img_hsv) # define range of blue color in HSV lower_blue = np.array([100,50,50]) upper_blue = np.array([130,255,255]) mask_blue1 = cv2.inRange(img_hsv, lower_blue, upper_blue) # define range of red color in HSV lower_red = np.array([0,50,50]) upper_red = np.array([10,255,255]) mask_red1 = cv2.inRange(img_hsv, lower_red, upper_red)
Created on Fri Jun 24 15:30:21 2016 @author: Milos """ import notebookOperacije as my import neuralNetwork as nn import numpy as np # TODO - NEURAL NETWORK TRAIN # obučavanje neuronske mreže image_original_obucavanje = my.load_image('images/obucavajuciSkup12.jpg') image_obucavanje = my.remove_noise(my.image_bin(my.image_gray(image_original_obucavanje))) img_selected_regions_obucavanje, regions_obucavanje, regions_color_obucavanje, regions_signs_obucavnje = my.select_roiV3(image_original_obucavanje.copy(), image_obucavanje, 'TRAIN') my.plt.figure(3) my.display_image('img_selected_regions_obucavanje', img_selected_regions_obucavanje) inputs_obucavanje = nn.prepare_for_ann(regions_obucavanje) ''' #signs_alphabet = ['Obavezno zaustavljanje', 'Zabrana saobraćaja u oba smera'] signs_alphabet = {} for x in range(0, 8): signs_alphabet[x] = str((x+1)*10) #print "We're on time %d" % (signs_alphabet[x]) ''' signs_alphabet = ['opasnost na putu', 'ogranicenje 30', 'obrnuti trougao', 'stop', 'zabrenjo oba smera', 'ogranicenje 40', 'zabranjeno polukruzno', 'obavezan smer desno', 'pesacki prelaz'] outputs_obucavanje = nn.convert_output(signs_alphabet) print '\nlen(inputs_obucavanje)=', len(inputs_obucavanje), ' len(outputs_obucavanje)=', len(outputs_obucavanje) ann = nn.create_ann() ann = nn.train_ann(ann, inputs_obucavanje, outputs_obucavanje)
upper_red = np.array([180,255,255]) mask1 = cv2.inRange(img_hsv, lower_red, upper_red) # define range of blue color in HSV lower_blue = np.array([110,50,50]) upper_blue = np.array([130,255,255]) mask2 = cv2.inRange(img_hsv, lower_blue, upper_blue) # define range of blue color in HSV lower_white = np.array([20,100,100]) upper_white = np.array([40,255,255]) mask3 = cv2.inRange(img_hsv, lower_white, upper_white) # join my masks mask = mask0+mask1+mask2+mask3 # set my output img to zero everywhere except my mask output_img = img.copy() output_img[np.where(mask==0)] = 0 # or your HSV image, which I *believe* is what you want output_hsv = img_hsv.copy() output_hsv[np.where(mask==0)] = 0 my.display_image('output_hsv', output_hsv) white = np.uint8([[[0,0,0 ]]]) hsv_green = cv2.cvtColor(white,cv2.COLOR_BGR2HSV) print hsv_green
h = img_color.shape[0]/3 print 'h=',h # računnje i iscrtravanje Hough-ovih linija for i in range(0,3): for rho,theta in lines[i]: a = np.cos(theta) b = np.sin(theta) x0 = a*rho y0 = b*rho x1 = int(x0 + 1000*(-b)) y1 = int(y0 + 1000*(a)) x2 = int(x0 - 1000*(-b)) y2 = int(y0 - 1000*(a)) cv2.line(img_result,(x1,y1),(x2,y2),(255,0,0),5) #***************************************************** # TODO - run img_color = cv2.imread('images_test/put11.jpg') img_result = img_color.copy() img_gray = cv2.cvtColor(img_color, cv2.COLOR_BGR2GRAY) filtering(img_gray) my.display_image('1. original', img_color) my.display_image('2. gray', img_gray) my.display_image('5. result', img_result)