def batch_load(): ora_backup_files.fbrm_rman().main() session_longops_load.fbrm_rman().main() rman_load.fbrm_rman().main() rman_backup_files.rman_backupfiles().main() threshold.threshold().main()
def thr_main(it): thrs_mult = [[127, 42]] samples = ["A", "B", "C", "A+", "B+", "C+"] filename_src = ( "/nrs/saalfeld/heinrichl/synapses/pre_and_post/pre_and_post-v6.3/cremi/{0:}.n5" ) dataset_srcs = [ "predictions_it{0:}/cleft_dist_cropped".format(it), "predictions_it{0:}/cleft_dist_cropped".format(it), ] filename_tgt = ( "/nrs/saalfeld/heinrichl/synapses/pre_and_post/pre_and_post-v6.3/cremi/{0:}.n5" ) dataset_tgts = [ "predictions_it{0:}".format(it) + "/cleft_dist_cropped_thr{0:}", "predictions_it{0:}".format(it) + "/cleft_dist_cropped_thr{0:}", ] for sample in samples: logging.info("thresholding sample {0:}".format(sample)) for thrs in thrs_mult: for ds_src, ds_tgt, thr in zip(dataset_srcs, dataset_tgts, thrs): logging.info(" dataset {0:} at {1:}".format(ds_src, thr)) threshold.threshold( filename_src.format(sample), ds_src, filename_tgt.format(sample), ds_tgt.format(thr), thr, )
def main(): imgname1='imgs/porta1pb.pnm' imgname2='imgs/larapiopb.pnm' if len(argv)>2: imgname1=argv[1] imgname2=argv[2] thresh_factor = 65 min_size = 10 #(minimum w and h to be not considered noise) print 'Subtracting...' subtract(imgname1, imgname2) print 'Thresholding...' threshold('subtracted_image.png', 65) print 'Eroding...' k=open('kernel', 'w') k.write('''1 1 1 1 1 1 1 1 1 1 1 1 1 1 1''') k.close() erode('thresholded_image.png') print 'Dilating...' dilate('eroded_image.png') #Dilating to merge pieces, then erode to get back to the original size print 'Merging pieces...', k=open('kernel', 'w') for i in range(10): k.write('1 1 1 1 1 1 1 1 1 1\n') k.close() dilate('dilated_image.png', outfile='result0.png') print 'halfway done...' erode('result0.png', outfile = 'result.png') #Using opencv to calculate the bounding box to figure out what we found img = cv2.imread('result.png', cv2.CV_LOAD_IMAGE_GRAYSCALE) contours, hierarchy = cv2.findContours(img,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE) noise=0 for cnt in contours: b_box = cv2.boundingRect(cnt) w,h = b_box[2], b_box[3] #print w,h if w > min_size and h > min_size: #Found something... if w > h: print 'Found a dog!' else: print 'Found an intruder!' else: noise+=1 print 'Found',str(noise),'noise(s).'
def determine(image, k): #Get all the possible canny image throught all the threshold #The eyeball should always be the darkest pixel in the image, so the uppert would be set to 255 for now count = 0 uppert = 255 guessing = [] #Set lower t between 50 and 120 lowert = range(50, 120) for low in lowert: count = count + 1 #Canny image outcome = threshold(image, low, uppert) #Run the hough transform on each outcome #count is simply the naning convention max_cor, max_collec, circled_cases = circle(count, outcome) circle_1, circle_2 = max_collec #circle_1+circle_2 is the summation of two highest votes with coordinates guessing.append([(circle_1 + circle_2), low, uppert, '../output/frame_testing/kang%05d.png' % count]) print('--------------------------------') print('progress:' + str(count / len(lowert))) print('with %s more left' % str(k)) print('--------------------------------') #Sort the best overall and get the best result and picture overall guessing.sort() result = guessing[len(guessing) - 1] result_image = cv2.imread(result[3]) # cv2.imwrite('pretesting/%s.png'%i, circled_cases) # #Write the image to the destinated folder to better examine # cv2.imwrite('testing_result/%s.png'%i, result_image) return result
def main(): # Read RGB image as GRAYSCALE imageName = sys.argv[1] img = cv2.imread(imageName, cv2.IMREAD_GRAYSCALE) # check if image exists or not. If image does not exists img contains None value if img == None: print("Image does not exists!") sys.exit() # removing the extension and storing only name of the image imageName = imageName.split(".")[0] # filter the image using gaussian smoothing img = gaussian_smoothing(img) cv2.imwrite(imageName + "-" + "gaussian.png", img) # compute image gradient imgGX, imgGY, img, imgTheta = compute_gradient(img) cv2.imwrite(imageName + "-" + "gradient-X.png", imgGX) cv2.imwrite(imageName + "-" + "gradient-Y.png", imgGY) cv2.imwrite(imageName + "-" + "gradient.png", img) # find non maxima suppression of given image and return new image and theta values of each pixel in a matrix img = non_maxima_suppression(img, imgTheta) cv2.imwrite(imageName + "-" + "maxima.png", img) # remove unwanted pixels by setting them to zero by using simple thresholding img10, img30, img50 = threshold(img) cv2.imwrite(imageName + "-" + "ptile10.png", img10) cv2.imwrite(imageName + "-" + "ptile30.png", img30) cv2.imwrite(imageName + "-" + "ptile50.png", img50)
def main(args): img = im_to_arr(args[0]) thresholded = threshold(img, 90) projection = np.zeros( (thresholded.shape[0] + 32, thresholded.shape[1] + 32)) projection[32:, 32:] = thresholded projection = np.repeat(projection, 3).reshape( (projection.shape[0], projection.shape[1], 3)) projection[30:32, :] = (0, 0, 200) projection[:, 30:32] = (0, 0, 200) for x in range(thresholded.shape[0]): sum_in_row = np.sum(thresholded[x, :]) white_ratio = sum_in_row / thresholded.shape[1] / 255 stretched = int(round(30 * white_ratio)) for p in range(stretched, -1, -1): projection[x + 32, p] = (255, 0, 0) for x in range(thresholded.shape[1]): sum_in_col = np.sum(thresholded[:, x]) white_ratio = sum_in_col / thresholded.shape[0] / 255 stretched = int(round(30 * white_ratio)) for p in range(stretched, -1, -1): projection[p, x + 32] = (255, 0, 0) projection = Image.fromarray(projection.astype(np.uint8)) projection.show()
def gaussian_blur(image, kernel_size, plot=False): image = np.array(image, dtype=np.int) kernel = gaussian_kernel(kernel_size, sigma=math.sqrt(kernel_size), plot=plot) blur = np.array(convolusion(image, kernel), dtype=np.uint8) return np.array(threshold(blur, 1, 255), dtype=np.uint8)
def process_image(oimg): uimg = undistort.undistort(oimg) _, _, _, timg = threshold.threshold(uimg) wimg = topview.warp(timg) left_fit, right_fit, roc, dfc, ly, lx, ry, rx = lane_finder.find(wimg) result = draw.draw(uimg, wimg, left_fit, right_fit, roc, dfc, ly, lx, ry, rx, False) return result
def printDilationLines(name): img_sh = threshold(name + ".png") lines = getDilationLines(img_sh, 10, 300, 10) print(len(lines)) img = cv.imread(name + ".png") for line in lines: x1, y1, x2, y2 = line[0] cv.line(img, (x1, y1), (x2, y2), (0, 0, 255), 20) cv.imwrite(name+"_out.png", img)
def thr_main(it): thrs_mult = [[127, 42]] samples = ['A', 'B', 'C', 'A+', 'B+', 'C+'] filename_src = '/nrs/saalfeld/heinrichl/synapses/pre_and_post/pre_and_post-v6.3/cremi/{0:}.n5' dataset_srcs = ['predictions_it{0:}/cleft_dist_cropped'.format(it), 'predictions_it{0:}/cleft_dist_cropped'.format(it), ] filename_tgt = '/nrs/saalfeld/heinrichl/synapses/pre_and_post/pre_and_post-v6.3/cremi/{0:}.n5' dataset_tgts = ['predictions_it{0:}'.format(it)+'/cleft_dist_cropped_thr{0:}', 'predictions_it{0:}'.format(it)+'/cleft_dist_cropped_thr{0:}', ] for sample in samples: logging.info("thresholding sample {0:}".format(sample)) for thrs in thrs_mult: for ds_src, ds_tgt, thr in zip(dataset_srcs, dataset_tgts, thrs): logging.info(" dataset {0:} at {1:}".format(ds_src, thr)) threshold.threshold(filename_src.format(sample), ds_src, filename_tgt.format(sample), ds_tgt.format( thr), thr)
def implementation(self): min_value=float(self.field_minValue.text()) max_value=float(self.field_maxValue.text()) self.myepochs=self.epochs(self.data, self.channels, self.points) x,y=threshold.threshold(self.myepochs, min_value, max_value) newSignal=reshape(x,(shape(x)[0],shape(x)[1]*shape(x)[2]),order='F') self.graph_method = window_graph(self.data, self.Fs,3,newSignal,y,shape(self.myepochs)[2]); self.graph_method.show();
def all_filters(frame,scale_percent = 20, threshVal1 = 120, threshVal2 = 255,thresholdVal1_inv = 70,thresholdVal2_inv = 255, thresholdVal3 = 0, thresholdVal4 = 100,median_filter_size = 5,blackign =3): # ret, frame = cap.read() # print (frame.shape) width = int(frame.shape[1] * scale_percent / 100) height = int(frame.shape[0] * scale_percent / 100) dsize = (width, height) frame = cv2.resize(frame, dsize) H = cv2.cvtColor(frame,cv2.COLOR_RGB2HSV_FULL) # H = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY) # print (frame.shape) frame2 = threshold(H[:,:,1].copy(),threshVal1,threshVal2) frame3 = threshold_inv(frame[:,:,1].copy(),thresholdVal1_inv,thresholdVal2_inv) frame4 = threshold(frame[:,:,0].copy(),thresholdVal3,thresholdVal4) frame2 = np.array(frame2,np.uint8) frame3 = np.array(frame3,np.uint8) frame4 = np.array(frame4,np.uint8) # print (frame4.shape) frame2 = median_filter(frame2,filter_size = median_filter_size,plot=False) frame3 = median_filter(frame3,filter_size = median_filter_size,plot=False) frame4 = median_filter(frame4,filter_size = median_filter_size,plot=False) # print (frame4.shape) frame3 = blacker(frame3,blackign) # frame3,a = sobel(frame3,True) frame3 = gaussian(frame3.copy(),9,plot=False) # frame4 = laplacian(frame2) a = pixel_count(frame3) b = pixel_count(frame4) if b !=0: ratio_full = (a/b+1)*100 # print ('ammatasiri methnata wenakan enawa') return frame2, frame3, frame4, a,b, ratio_full
def loss(beta, sigma, X, y, distribution='norm', loc=0, scale=1, a=None, c=None, s=None): ''' Input: beta --pd.Series. with length p + 1, including the intercept beta_0; sigma --scaler. > 0; X --pd.DataFrame. with shape n times p + 1, the elements of its first column are all 1; y --pd.Series. with length n Output: loss --scaler. the negative log likelihood. ''' n = X.shape[0] gammas = threshold(y, distribution, a=a, c=c, s=s) K = len(gammas) fitvalues = np.dot(X, beta) #return an array with shape (n, ) tmp = np.tile(gammas, n) #repeat gammas n times tmp = tmp.reshape(n, K) #transform tmp1 to a matrix with shape (n, K) #subtract each column of tmp by fitvalues. #Remark: in numpy, substract each column of a matrix by a vector only works if #the trailing axes have the same dimension. The shape of tmp is (n, K), and #the shape of fitvalues is (n, ). So we need transport tmp. You can also think #numpy can do "matrix - vector' by row #the sahpe of upper is (n, K), which is the elment in the parentheses of F_0 upper = ((tmp.T - fitvalues).T) / sigma x=np.array([-1.0 * np.inf]) x2 = gammas[:-1] lower_gammas = np.concatenate([x, x2]) tmp = np.tile(lower_gammas, n) tmp = tmp.reshape(n, K) lower = ((tmp.T - fitvalues).T) / sigma if distribution == 'norm': upper = st.norm.cdf(upper) lower = st.norm.cdf(lower) elif distribution == 'weibull': upper = st.exponweib.cdf(upper, a=a, c=c, loc=loc, scale=scale) lower = st.exponweib.cdf(lower, a=a, c=c, loc=loc, scale=scale) elif distribution == 'log': upper = st.lognorm.cdf(upper, s=s, loc=loc, scale=scale) lower = st.lognorm.cdf(lower, s=s, loc=loc, scale=scale) else: raise Exception('unvalid input for parameter distribution.') prob_y = upper - lower #probability of y equals to k log_prob_y = np.log(prob_y) #matrix with shape (n, K) deltah = np.array(delta(y)) loss = deltah * log_prob_y loss = loss.sum() loss = -1.0 * loss return loss
def process(img): global lane_pts undist = undistort(img) clipped = clip(undist) red = clipped[:, :, 0] red = cv2.normalize(red, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) contrast_enhanced = clahe.apply(red) high_red = threshold(contrast_enhanced, thresh=(210, 255)) edges = threshold(sobel(contrast_enhanced, orient='x', ksize=7), thresh=(0.15, 1)) combined = cv2.bitwise_or(high_red, edges) #return to_rgb(combined) binary_warped = warp_forward(combined) #return to_rgb(binary_warped) lane_pts = find_lane_points(binary_warped, window_size=(100, 60), prev_pts=lane_pts, margin=100, thresh=3000) lane_warped = np.zeros(img.shape, img.dtype) draw_lane(lane_warped, lane_pts, (0, 255, 0)) #for pt in lane_pts[0]: draw_window(lane_warped, pt, (100,60), (255,0,0)) #for pt in lane_pts[1]: draw_window(lane_warped, pt, (100,60), (0,0,255)) #return cv2.addWeighted(to_rgb(binary_warped), .5, lane_warped, .5, 0) lane_img = warp_backward(lane_warped) final = cv2.addWeighted(undist, 1, lane_img, .3, 0) print_curve_stats(final, lane_pts, lane_width_m=3.7, ym_per_pix=30.0 / 720, color=(255, 255, 255)) return final
def debug_image(oimg): uimg = undistort.undistort(oimg) _, _, _, timg = threshold.threshold(uimg) wimg = topview.warp(timg) #result = np.dstack((timg, timg, timg)) result = np.dstack((wimg, wimg, wimg)) left_fit, right_fit, roc, dfc, ly, lx, ry, rx = lane_finder.find(wimg) #ploty = np.linspace(0, wimg.shape[0]-1, wimg.shape[0]).astype(int) #left_fitx = left_fit[0]*ploty**2 + left_fit[1]*ploty + left_fit[2] #right_fitx = right_fit[0]*ploty**2 + right_fit[1]*ploty + right_fit[2] #result = np.dstack((wimg, wimg, wimg)) result[ly, lx] = [255, 0, 0] result[ry, rx] = [255, 0, 0] #result[ploty, left_fitx.astype(int)] = [255, 255, 0] #result[ploty, right_fitx.astype(int)] = [255, 255, 0] return result
def pipeline_writeup(display=True, save=True): ###################################################################### ### Camera calibration (camera matrix and distortion coefficients) ### cal_img_dir = '../camera_cal' test_img_dir = '../test_images' nx = 9 # the number of inside corners in x ny = 6 # the number of inside corners in y mtx, dist = get_calibration(cal_img_dir, test_img_dir, nx, ny, display=display, save=save) # dist_pickle = pickle.load( open( "wide_dist_pickle.p", "rb" ) ) # mtx = dist_pickle["mtx"] # dist = dist_pickle["dist"] ###################################################################### ### Read test image ### # img_path = sorted(glob.glob(os.path.join(test_img_dir, '*.png')))[3] # img_RGB = (mpimg.imread(img_path)*255).astype(np.uint8) img_path = sorted(glob.glob(os.path.join(test_img_dir, '*.jpg')))[0] img_RGB = mpimg.imread(img_path) if display: plt.imshow(img_RGB) plt.show() ###################################################################### ### Use different thresholds ### lane_binary, lane_gray = threshold(img_RGB, display=display, save=save) ###################################################################### ### Undistortion and perspective transform ### ## corners for perspective transform choosen mannually (x,y) img_H, img_W = img_RGB.shape[:2] trans_src = np.float32([[225,697], [1078,697], [705,460], [576,460]]) offset = 360 trans_dst = np.float32([[img_W/2-offset,img_H], [img_W/2+offset,img_H], [img_W/2+offset,0], [img_W/2-offset,0]]) # trans_src = np.float32([[585,460], [203,720], [1127,720], [695,460]]) # trans_dst = np.float32([[320,0], [320,720], [960,720], [960,0]]) warped_img, M, Minv = transform(lane_gray, trans_src, trans_dst, mtx, dist, display=display, save=save) ###################################################################### ### Undistortion and perspective transform ### _, _, _, _, _,_,_ = sliding_win_search(warped_img, None, None, display=display, save=save)
def printDilationLines(name): img_sh = threshold(name + ".png") im2 = cv.dilate(img_sh, np.ones((15, 15), np.uint8), 1) lines = cv.HoughLinesP(im2 - img_sh, 1, np.pi / 180, 100, minLineLength=150, maxLineGap=10) flat = [] for line in lines: x1, y1, x2, y2 = line[0] if getAbsTan(x1, y1, x2, y2) < 0.4: flat.append(line) print(str(len(flat)) + " horizotal lines are found!") img = cv.imread(name + ".png") for line in flat: x1, y1, x2, y2 = line[0] cv.line(img, (x1, y1), (x2, y2), (0, 0, 255), 20) cv.imwrite(name + "_out.png", img)
def canny(image): blurred_image = gaussian_blur(image, kernel_size=9) edge_filter = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]) gradient_magnitude, gradient_direction = sobel_edge_detection(blurred_image, edge_filter) new_image = non_max_suppression(gradient_magnitude, gradient_direction) weak = 50 new_image = threshold(new_image, 5, 20, weak) new_image = hysteresis(new_image, weak) new_image = new_image.astype(np.uint8) kernel = np.ones((5, 5)) img_dil = cv2.dilate(new_image, kernel, iterations=1) form = getContours(img_dil, image, image) return form
def critical_frame(self, collections, L, H): count = 0 dic = {} dic['s_center'] = [] dic['s_loc'] = [] dic['h_center'] = [] dic['h_loc'] = [] ncol = len(collections) for i in range(0, ncol): for file in collections[i]: case_name = '../output/analysis_set/kang%05d.png' % file image = cv2.imread(case_name) outcome = threshold(image, L, H) #Here the algorithm starte dto work #max_collec tells you x, y, and r, but really it seems that only x is important in some cases output = circle(outcome) print(output) if i == 0: dic['s_center'].append(max_cor) elif i == 1: dic['s_loc'].append(max_cor) elif i == 2: dic['h_center'].append(max_cor) elif i == 3: dic['h_loc'].append(max_cor) else: print('Something went wrong') exit() count += 1 count = 0 print(dic) print('{}/{} section done'.format(i + 1, ncol)) print('\n\n') return dic self.video_analyze(self.L, self.H)
def main(): # calibrate the camera using the given chessboard images ret, mtx, dist, rvecs, tvecs = calibrate( path='../camera_cal/calibration*.jpg', xy=(9, 6), draw_corners=False) # inst. Lane object lane = Lane() # read video predicted_frames = [] input_video = 'project_video.mp4' cap = cv2.VideoCapture(os.path.join('../input_videos/', input_video)) while cap.isOpened(): ret, frame = cap.read() if not ret: print('Cant receive frame. Exiting..') break # undistort an image rgb_img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # BGR => RGB undist = undistort(rgb_img, mtx, dist) # convert to gray gray = cv2.cvtColor(undist, cv2.COLOR_RGB2GRAY) # RGB => GRAY # apply gradient and color thresholding gradx = th.abs_sobel_thresh(gray) direction = th.dir_thresh(gray) gradient_binary = np.zeros_like(direction) gradient_binary[(gradx == 1) & (direction == 1)] = 1 color_binary = th.saturation_thresh(frame) # combine gradient and color thresholding thresholded_img = th.threshold(gradient_binary, color_binary) # perspective transform: easier to measure curvature of lane from bird's eye view # also makes it easier to match car's location with a road map src, dst, M, M_inv = pt.get_transform_matrix() # transform image size = (thresholded_img.shape[1], thresholded_img.shape[0]) transformed_img = cv2.warpPerspective(thresholded_img, M, size) # draw lines on transformed gray_transformed_img = np.uint8(transformed_img * 255) bgr_transformed_img = cv2.cvtColor(gray_transformed_img, cv2.COLOR_GRAY2BGR) #pt.draw_plot_save(bgr_transformed_img, dst, 'Test Transformation', '../output_images/test_transform.png') # fit lines left_fit, right_fit, y, offset_meters = lane.fit_polynomials( transformed_img) # create blank for drawing lane lines zeros = np.zeros_like(transformed_img).astype(np.uint8) draw_img = np.dstack((zeros, zeros, zeros)) # format points for fill poly pts_left = np.array([np.transpose(np.vstack([left_fit, y]))]) # [left_fit ... y] pts_right = np.array( [np.flipud(np.transpose(np.vstack([right_fit, y])))]) pts = np.hstack((pts_left, pts_right)) # [pts_left, pts_right] cv2.fillPoly(draw_img, np.int_([pts]), (0, 255, 0)) # unwarp transformed image unwarped = cv2.warpPerspective(draw_img, M_inv, (gray.shape[1], gray.shape[0])) # combine lane drawing w/ original image final_image = cv2.addWeighted(undist, 1, unwarped, 0.25, 0) # add measurement data to frame offset_side = 'left' if offset_meters < 0 else 'right' final_image = cv2.putText( final_image, f'Offset: {abs(offset_meters):0.2f}m {offset_side} of center', (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA) # show predict cv2.imshow('frame', cv2.cvtColor(final_image, cv2.COLOR_RGB2BGR)) # store predicted frames predicted_frames.append(final_image) if cv2.waitKey(1) == ord('q'): break # release cap object cap.release() cv2.destroyAllWindows()
def pipeline_video(img_RGB): global old_left_fit global old_right_fit display=False save=False _, lane_gray = threshold(img_RGB, display=display, save=save) warped_img, _, _ = transform(lane_gray, None, None, mtx, dist, M=M, Minv=Minv, display=display, save=save) left_cr, right_cr, left_fitx, right_fitx, plot_fity, left_fit, right_fit = sliding_win_search(warped_img, old_left_fit, old_right_fit, display=display, save=save) ## Sanity Check if abs(left_cr-right_cr) < curve_diff_thx: if left_cr>curve_min and right_cr>curve_min: if len(left_fitx_list)>avg_frame_num: left_fitx_list.pop(0) right_fitx_list.pop(0) left_fitx_list.append(left_fitx) right_fitx_list.append(right_fitx) old_left_fit = left_fit old_right_fit = right_fit left_fitx = np.mean(np.array(left_fitx_list), axis=0) left_fitx = (left_fitx + left_fitx_list[-1])/2 right_fitx = np.mean(np.array(right_fitx_list), axis=0) right_fitx = (right_fitx + right_fitx_list[-1])/2 # Create an image to draw the lines on warp_zero = np.zeros_like(warped_img).astype(np.uint8) color_warp = np.dstack((warp_zero, warp_zero, warp_zero)) # Recast the x and y points into usable format for cv2.fillPoly() pts_left = np.array([np.transpose(np.vstack([left_fitx, plot_fity]))]) pts_right = np.array([np.flipud(np.transpose(np.vstack([right_fitx, plot_fity])))]) pts = np.hstack((pts_left, pts_right)) # Draw the lane onto the warped blank image cv2.fillPoly(color_warp, np.int_([pts]), (0,255, 0)) # Warp the blank back to original image space using inverse perspective matrix (Minv) newwarp = cv2.warpPerspective(color_warp, Minv, (img_RGB.shape[1], img_RGB.shape[0])) # Combine the result with the original image undist = cv2.undistort(img_RGB, mtx, dist, None, mtx) result = cv2.addWeighted(undist, 1, newwarp, 0.3, 0) curvature = "Estimated lane curvature %.2fm" % ((left_cr+right_cr)/2) xm_per_pix = 3.7/700 # meters per pixel in x dimension dist_centre = "Estimated offset from lane center %.2fm" % (abs(left_fitx[-1]+right_fitx[-1]-img_RGB.shape[1])/2*xm_per_pix) font = cv2.FONT_HERSHEY_COMPLEX cv2.putText(result, curvature, (30, 60), font, 1, (255,255,255), 2) cv2.putText(result, dist_centre, (30, 90), font, 1, (255,255,255), 2) return result # plt.imshow(result) # plt.show() # white_output = 'result.mp4' # clip1 = VideoFileClip('../project_video.mp4') # white_clip = clip1.fl_image(pipeline_video) #NOTE: this function expects color images!! # white_clip.write_videofile(white_output, audio=False)
def getSegments(name): # according to detected lines, segment the whole image and wipe the lines img = cv.imread(name + ".png") img_re = threshold(name + ".png", reverse=True) img_sh = threshold(name + ".png", reverse=False) lines = getDilationLines(img_re, 10, 400, 10) # the last 3 params are kernelSize, minLineLength and maxGapLength print(str(len(lines)) + " lines detected!") flat_lines = [] vrt_lines = [] # each line are defined as a duple: # flat line: (sum_y, number_of_lines) # vrt_line: (sum_x, number_of_lines) for line in lines: x1, y1, x2, y2 = line[0] tan = abstan(x1, y1, x2, y2) # 合并lines的过程后面可以用堆来优化 if tan < 0.4: y = (y1 + y2) / 2 found = False for i in range(len(flat_lines)): avg_y = flat_lines[i][0] / flat_lines[i][1] if avg_y - y < 200 and avg_y - y > -200: found = True flat_lines[i] = (flat_lines[i][0] + y, flat_lines[i][1] + 1) break if found is False: flat_lines.append((y, 1)) elif tan > 2.5: x = (x1 + x2) / 2 found = False for i in range(len(vrt_lines)): avg_x = vrt_lines[i][0] / vrt_lines[i][1] if avg_x - x < 200 and avg_x - x > -200: found = True vrt_lines[i] = (vrt_lines[i][0] + x, vrt_lines[i][1] + 1) break if found is False: vrt_lines.append((x, 1)) else: print("A line is neither a flat line or a vertical line!") # find cordinates for segmentation anchor_x = [int(sum_x / nline + 0.5) for (sum_x, nline) in vrt_lines] anchor_y = [int(sum_y / nline + 0.5) for (sum_y, nline) in flat_lines] anchor_x.append(0) anchor_x.append(img.shape[1] - 1) # number of pixels in column anchor_y.append(0) anchor_y.append(img.shape[0] - 1) # number of pixels in row anchor_x.sort() anchor_y.sort() print(anchor_x) print(anchor_y) nx = len(anchor_x) - 1 ny = len(anchor_y) - 1 # wipe originally found lines with white pixels for line in lines: x1, y1, x2, y2 = line[0] cv.line(img_sh, (x1, y1), (x2, y2), 255, 30) # do segmentation in order -- from top to bottom & from right to left segments = [] for i in range(nx * ny): ix = nx - 1 - int(i / ny) iy = i % ny print(str(anchor_y[iy]) + "," + str(anchor_x[ix])) segments.append(img_sh[anchor_y[iy]:anchor_y[iy + 1], anchor_x[ix]:anchor_x[ix + 1]]) # export original image with split lines for DEBUGGING for x in anchor_x: cv.line(img, (x, 0), (x, img.shape[0] - 1), (255, 0, 0), 5) for y in anchor_y: cv.line(img, (0, y), (img.shape[1] - 1, y), (255, 0, 0), 5) cv.imwrite(name + "_seg.png", img) return segments
cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() scale_percent = 100 width = int(frame.shape[1] * scale_percent / 100) height = int(frame.shape[0] * scale_percent / 100) dsize = (width, height) frame = cv2.resize(frame, dsize) H = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV_FULL) # H = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY) frame2 = threshold(H[:, :, 1].copy(), 120, 255) frame3 = threshold_inv(frame[:, :, 1].copy(), 70, 255) frame4 = threshold(frame[:, :, 0].copy(), 0, 100) frame2 = np.array(frame2, np.uint8) frame3 = np.array(frame3, np.uint8) frame4 = np.array(frame4, np.uint8) frame2 = median_filter(frame2, filter_size=3, plot=False) frame3 = median_filter(frame3, filter_size=3, plot=False) frame4 = median_filter(frame4, filter_size=5, plot=False) frame3 = blacker(frame3, 300) # frame3,a = sobel(frame3,True) frame3 = gaussian(frame3.copy(), 9, plot=False) # frame4 = laplacian(frame2)
def remove_bg(input_file, thresh_val=0, window_size=3, block_size=11, c=5, mode=0, thresh_type=0): """ >>> isinstance(remove_bg(test_image), np.ndarray) True >>> isinstance(remove_bg(test_image, mode=1), np.ndarray) True >>> isinstance(remove_bg(test_image, mode=2), np.ndarray) True >>> remove_bg(None) Traceback (most recent call last): File "<stdin>", line 1, in ? IOError: The input file can't be a None object >>> remove_bg("") Traceback (most recent call last): File "<stdin>", line 1, in ? IOError: The input file can't be ''. >>> remove_bg("fakeRoute") Traceback (most recent call last): File "<stdin>", line 1, in ? IOError: Input file not found. >>> remove_bg(test_image, window_size=-3) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Window size value must be greater than 0. >>> remove_bg(test_image, window_size=2) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Window size value must be odd. >>> remove_bg(test_image, block_size=-3) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Block size value must be greater than 0. >>> remove_bg(test_image, block_size=2) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Block size value must be odd. >>> remove_bg(test_image, c='a') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Constraint must be integer. >>> remove_bg(test_image, thresh_type=-1) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Threshold_type value must be between 0 and 4. >>> remove_bg(test_image, thresh_type=6) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Threshold_type value must be between 0 and 4. >>> remove_bg(test_image, mode=-1) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Thres_type value must be between 0 and 2 (0-Adapt-Gauss, 1-Adapt-Mean, 2-Simple). >>> remove_bg(test_image, mode=3) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: Thres_type value must be between 0 and 2 (0-Adapt-Gauss, 1-Adapt-Mean, 2-Simple). """ # Checking arguments check_threshold(thresh_val) check_window_size(window_size) check_block_size(block_size) check_c(c) check_mode(mode) # Loading image image = iu.get_image(input_file) # Removing noise by blurring and thresholding image = cv.GaussianBlur(image, (window_size, window_size), 0) result = [] if mode == 2: result = th.threshold(image, thresh_val, thresh_type=thresh_type) else: result = th.adaptive_threshold(image, block_size=block_size, c=c, mode=mode, thresh_type=thresh_type) return result
# print 0 if __name__ == '__main__': try: camUrl = 'rtsp://192.168.0.112:5540/ch0' rospy.init_node('ipcam_10', anonymous=True) ip_camera = ipcamera(camUrl) output = np.zeros((600, 600, 3)) # output = resize_image(output) while not rospy.is_shutdown(): (rval, frame) = ip_camera.stream.read() if rval: # ADD CODE HERE # print(frame.shape) frame = resize_image(frame) # print(frame.shape) frame = threshold(frame) # print(frame.shape) # print('output image shape',output.shape) output = add_images(frame, output) ip_camera.image_pub.publish( ip_camera.bridge.cv2_to_imgmsg(frame, "bgr8")) key = cv2.waitKey(1) & 0xFF if key == ord("q"): break ip_camera.stream.release() cv2.destroyAllWindows() except rospy.ROSInterruptException: pass
# path = 'F:/sliit/Y 4/Y4 sem 2 2020/image processing/assigninet/PICS/vid1.mp4' cap = cv2.VideoCapture(path) while True: ret, frame = cap.read() scale_percent = 20 width = int(frame.shape[1] * scale_percent / 100) height = int(frame.shape[0] * scale_percent / 100) dsize = (width, height) frame = cv2.resize(frame, dsize) # frame = frame[:,:,2] frame1 = frame.copy() thresh1 = threshold(frame1[:, :, 2].copy(), 170) thresh1 = np.array(thresh1, np.uint8) frame1 = cv2.cvtColor(frame1, cv2.COLOR_RGB2GRAY) # convolution1 = convolution.convolution(frame1.copy(),kernel,0) # convolution1 = np.array(convolution1,np.uint8) # padded_image = np.zeros((width + (2 * 9), height + (2 * 9)),np.ubyte) # padded_image[9:padded_image.shape[0] - 9, 9:padded_image.shape[1] - 9] = frame1 #gaussian blur works don't dlt gaussian1 = gaussian_blur(frame1.copy(), 40) gaussian1 = np.array(gaussian1, np.uint8) iamge1 = np.zeros((gaussian1.shape[0], gaussian1.shape[1]), np.uint8) frame2, direction = sobel_filter(gaussian1.copy(), iamge1, 13, 30)
import threshold as t i1 = Image.open('images/sentdex.png') i2 = Image.open('images/numbers/0.1.png') i3 = Image.open('images/numbers/y0.4.png') i4 = Image.open('images/numbers/y0.5.png') iar1 = np.array(i1) iar2 = np.array(i2) iar3 = np.array(i3) iar4 = np.array(i4) fig = plt.figure() ax1 = plt.subplot2grid((8, 6), (0, 0), rowspan=4, colspan=3) ax2 = plt.subplot2grid((8, 6), (4, 0), rowspan=4, colspan=3) ax3 = plt.subplot2grid((8, 6), (0, 3), rowspan=4, colspan=3) ax4 = plt.subplot2grid((8, 6), (4, 3), rowspan=4, colspan=3) t.threshold(iar1) t.threshold(iar2) t.threshold(iar3) t.threshold(iar4) ax1.imshow(iar1) ax2.imshow(iar2) ax3.imshow(iar3) ax4.imshow(iar4) plt.show()
from skimage import img_as_float import warnings warnings.filterwarnings('ignore') if __name__ == "__main__": img = imread('train.jpg') img = img_as_float(img) f, (ax1, ax2) = plt.subplots(1, 2) ax1.imshow((img - 0.2) * 2) ax2.imshow(contrast(img - 0.2, 2, 0, 1)) plt.show() img = imread('plane.jpg') imshow(img) imshow(invert(img)) plt.show() img = imread('forest.jpg') imshow(img) imshow(threshold(img, 50)) plt.show() img = plt.imread('img_with_noise.jpg') fig, (ax1, ax2) = plt.subplots(1, 2) ax1.imshow(img) ax2.imshow(fft_vs_noise(img)) plt.show()
def move_arm(x, y, ip, port): # get the local ip address of the machine running the script # if('en1' in ni.interfaces()): local_ip = ni.ifaddresses('en1')[ni.AF_INET][0]['addr'] else: local_ip = ni.ifaddresses('wlan0')[ni.AF_INET][0]['addr'] print("ip is {}".format(local_ip)) # initiate the arm chain object # arm = arm_chain.arm Z_HIGH = 10.5 # compute the target frame (homogeneous matrix) where the specified point is # target_vector = [x, y, Z_HIGH] target_frame = np.eye(4) target_frame[:3, 3] = target_vector # compute the required angles to get to the target vector # angles = compute_angles(arm, target_frame) # uncomment to repl # # angles = no_repl() # compare where the end effector is with where the specified point is # real_frame = arm.forward_kinematics(arm.inverse_kinematics(target_frame)) print("Computed position vector : %s, original position vector : %s"\ % (real_frame[:3, 3], target_frame[:3, 3])) # send the angles to the esp32 via socket # send_angles(angles=angles, ip=ip, port=port) # wait some time ? # time.sleep(1) # rcv distance from esp # dist = recv_dist(host=local_ip, port=6666) # compute the z value from current hight # then add 0.5 inches to give space # z = Z_HIGH - dist z = z + (-0.9) print("this is the new z value {}".format(z)) # to fix the suction cup offset # try: theta = math.atan(y / x) hyp = math.sqrt(x**2 + y**2) shifted_hyp = hyp - 0.25 shifted_x = shifted_hyp * math.cos(theta) shifted_y = shifted_hyp * math.sin(theta) except ZeroDivisionError as err: shifted_x = x shifted_y = y # recompute the angles with the new z # new_target_vector = [shifted_x, shifted_y, z] new_target_frame = np.eye(4) new_target_frame[:3, 3] = new_target_vector new_angles = compute_angles(arm, new_target_frame) # wait some time ? # time.sleep(1) # compare where the end effector is with where the specified point is # real_frame = arm.forward_kinematics(arm.inverse_kinematics(new_target_frame)) print("Computed position vector : %s, original position vector : %s" \ % (real_frame[:3, 3], new_target_frame[:3, 3])) new_coordinates = real_frame[:3, 3] WINDOW = 0.75 flag = threshold(real=[shifted_x, shifted_y, z], computed=new_coordinates, window=WINDOW) # check if the new computed coordinates are within the desired threshold # if (flag): # send the angles to the esp32 via socket # send_angles(angles=new_angles, ip=ip, port=port) else: # send old angles # send_angles(angles=angles, ip=ip, port=port) print("staying in old...") # TODO: find a way to know that the arm is now at drop! # time.sleep(15) return 1
def process(self, path): # Start timing initTime = time.time() # Create path for saving pathArr = string.split(path, "/") ##savePath = "out/" + pathArr[1] + "/" + pathArr[2] + "/" savePath = "out/" # Make sure directory structure exists for saving self.ensure_dir(savePath) self.ensure_dir(savePath + "/polar/") self.ensure_dir(savePath + "/circles/") # Get the image name name = os.path.basename(path) # Windows is dumb and creates a Thumbs.db file for each directory with an image. # When doing batch processing, its a good idea to ignore this file. if name == "Thumbs.db": sys.exit() print "Processing File: ", name # Open image inputImage = Image.open(path) w, h = inputImage.size # print "Size: ",w,h # If image is not 8-bit, grayscale it preGS = time.time() grayImageObject = algorithms.grayscaledImage(inputImage) grayscaleImage = grayImageObject.grayImage GStime = time.time() - preGS # Blur the image for pupil detection preB = time.time() blurredImageObject = algorithms.blurredImage(grayscaleImage, 11) blurredImage = blurredImageObject.blurImage Btime = time.time() - preB prePT = time.time() hist = blurredImage.histogram() ind = range(256) threshObj = threshold.threshold(hist) pupilThreshold = threshObj.pupilThresh(0, 70) lut = [255 if v > pupilThreshold else 0 for v in range(256)] pupilThreshImage = blurredImage.point(lut) PTtime = time.time() - prePT preB2 = time.time() iBlurredImageObject = algorithms.blurredImage(grayscaleImage, 3) iBlurredImage = blurredImageObject.blurImage B2time = time.time() - preB2 irisThresh = threshObj.irisThresh(pupilThreshold, 240) lut = [255 if v > irisThresh else 0 for v in range(256)] irisThreshImage = iBlurredImage.point(lut) preSP = time.time() SobelPupilObject = algorithms.sobelFilter(pupilThreshImage) SobelPupilImage = SobelPupilObject.outputImage SPtime = time.time() - preSP ################################################## ###########Pre-hough pupil-processing.############ #Looks for clusters of black to estimate the #pupil size and location. This is a quick hack and #does not work in all cases, such as an image with #a lot of areas as dark as the pupil############## ################################################## prePH = time.time() pupilPixels = pupilThreshImage.load() sumx = 0 sumy = 0 amount = 0 for x in range(10, w): for y in range(10, h): if pupilPixels[x, y] == 0: sumx += x sumy += y amount += 1 if sumx == 0 or sumy == 0: print "Sorry brah, the pupil's gone" sys.exit() sumx /= amount sumy /= amount pupilBoxCenter = (sumx, sumy) # sumx is the average x-location of the black pixels # sumy is the average y-location of the black pixels # A good idea would to have radii calculated for 4 # directions, left and right, x and y, then average radiusXL = sumx while pupilPixels[radiusXL, sumy] == 0: radiusXL += 1 radiusXL -= sumx - 2 radiusYD = sumy while pupilPixels[sumx, radiusYD] == 0: radiusYD += 1 radiusYD -= sumy - 2 rad = (radiusXL, radiusYD) avgRad = int((radiusXL + radiusYD) / 2) HoughObject = hough.HoughTransform(SobelPupilImage, (sumx - 1, sumy - 1), (4, 4), min(rad) - 5, max(rad) + 3) pX, pY, pR = HoughObject.pupilHough() PHtime = time.time() - prePH preSI = time.time() SobelIrisObject = algorithms.sobelFilter(irisThreshImage) SobelIrisImage = SobelIrisObject.outputImage SItime = time.time() - preSI preIH = time.time() irisHoughObj = hough.HoughTransform(SobelIrisImage, (0, 0), (0, 0), 0, 0) iR = irisHoughObj.irisHough(pX, pY, pR) IHtime = time.time() - preIH preUW = time.time() unwrapObj = demod.unwrap(grayscaleImage, (pX, pY), pR, iR) polarImg = unwrapObj.unwrap() polarImg.save(savePath + "/polar/" + name) UWtime = time.time() - preUW gaborObj = demod.demod(polarImg) irisCode = gaborObj.demod() # Save various images. # Mainly used to debug in case of a failure. # This will be set in the prefences. self.saveImagePref = 0 if (self.saveImagePref == 1): grayscaleImage.save(savePath + "gray-" + name) blurredImage.save(savePath + "blur-" + name) pupilThreshImage.save(savePath + "threshp-" + name) irisThreshImage.save(savePath + "threshi-" + name) SobelPupilImage.save(savePath + "sobelp-" + name) SobelIrisImage.save(savePath + "sobeli-" + name) self.saveHist = 0 if (self.saveHist == 1): plt.bar(ind, hist, color='b') plt.savefig(savePath + "hist-" + name + ".png") # Draw circles on result image pupilDrawObject = imgUtils.Utils(inputImage) pupilDraw = pupilDrawObject.drawCircle(pX, pY, pR) irisDrawObject = imgUtils.Utils(inputImage) irisDraw = irisDrawObject.drawCircle(pX, pY, iR) inputImage.save(savePath + "/circles/" + name) #Clean-up del grayscaleImage del blurredImage del pupilThreshImage del irisThreshImage del SobelPupilImage del SobelIrisImage print "Done" segTime = time.time() - initTime print "It took %.3f" % (1000 * segTime), "ms\n" return irisCode, inputImage
# assuming lane center should be at center of image xm_per_pix = 3.7 / 700 # meters per pixel in x dimension y = binary_warped.shape[0] - 1 xl = left_fit[0] * y**2 + left_fit[1] * y + left_fit[2] xr = right_fit[0] * y**2 + right_fit[1] * y + right_fit[2] lane_center = (xl + xr) / 2 img_center = binary_warped.shape[1] / 2 return (lane_center - img_center) * xm_per_pix if __name__ == '__main__': # open an image oimg = mpimg.imread('../CarND-Advanced-Lane-Lines/test_images/test2.jpg') img = undistort.undistort(oimg) _, _, _, img = threshold.threshold(img) binary_warped = topview.warp(img) leftx, lefty, rightx, righty = sliding_window(binary_warped) # Fit a second order polynomial to each left_fit = np.polyfit(lefty, leftx, 2) right_fit = np.polyfit(righty, rightx, 2) left_curverad, right_curverad = roc(binary_warped.shape[0] - 1, left_fit, right_fit) print(left_curverad, 'm', right_curverad, 'm') nonzero = binary_warped.nonzero() nonzeroy = np.array(nonzero[0]) nonzerox = np.array(nonzero[1])
import stddraw from picture import Picture import sys from threshold import threshold if len(sys.argv) < 3: print """ Usage: python %s <run #> <frame delay> [<threshold>] """ % sys.argv[0] sys.exit() stddraw.setCanvasSize(640, 480) run = int(sys.argv[1]) delay = int(sys.argv[2]) tau = None if len(sys.argv) > 3: tau = float(sys.argv[3]) for frame in range(200): pic = Picture('data/run_%d/frame%05d.jpg' % (run, frame)) if tau: threshold(pic, tau) stddraw.picture(pic) stddraw.show(delay)
def process(self,path): # Start timing initTime = time.time() # Create path for saving pathArr = string.split(path,"/") ##savePath = "out/" + pathArr[1] + "/" + pathArr[2] + "/" savePath = "out/" # Make sure directory structure exists for saving self.ensure_dir(savePath) self.ensure_dir(savePath + "/polar/") self.ensure_dir(savePath + "/circles/") # Get the image name name = os.path.basename(path) # Windows is dumb and creates a Thumbs.db file for each directory with an image. # When doing batch processing, its a good idea to ignore this file. if name == "Thumbs.db": sys.exit() print "Processing File: ",name # Open image inputImage = Image.open(path) w,h = inputImage.size # print "Size: ",w,h # If image is not 8-bit, grayscale it preGS = time.time() grayImageObject = algorithms.grayscaledImage(inputImage) grayscaleImage = grayImageObject.grayImage GStime = time.time() - preGS # Blur the image for pupil detection preB = time.time() blurredImageObject = algorithms.blurredImage(grayscaleImage,11) blurredImage = blurredImageObject.blurImage Btime = time.time() - preB prePT = time.time() hist = blurredImage.histogram() ind = range(256) threshObj = threshold.threshold(hist) pupilThreshold = threshObj.pupilThresh(0,70) lut = [255 if v > pupilThreshold else 0 for v in range(256)] pupilThreshImage = blurredImage.point(lut) PTtime = time.time() - prePT preB2 = time.time() iBlurredImageObject = algorithms.blurredImage(grayscaleImage,3) iBlurredImage = blurredImageObject.blurImage B2time = time.time() - preB2 irisThresh = threshObj.irisThresh(pupilThreshold,240) lut = [255 if v > irisThresh else 0 for v in range(256)] irisThreshImage = iBlurredImage.point(lut) preSP = time.time() SobelPupilObject = algorithms.sobelFilter(pupilThreshImage) SobelPupilImage = SobelPupilObject.outputImage SPtime = time.time() - preSP ################################################## ###########Pre-hough pupil-processing.############ #Looks for clusters of black to estimate the #pupil size and location. This is a quick hack and #does not work in all cases, such as an image with #a lot of areas as dark as the pupil############## ################################################## prePH = time.time() pupilPixels = pupilThreshImage.load() sumx = 0 sumy = 0 amount = 0 for x in range(10,w): for y in range(10,h): if pupilPixels[x,y] == 0: sumx += x sumy += y amount += 1 if sumx == 0 or sumy == 0: print "Sorry brah, the pupil's gone" sys.exit() sumx /= amount sumy /= amount pupilBoxCenter = (sumx, sumy) # sumx is the average x-location of the black pixels # sumy is the average y-location of the black pixels # A good idea would to have radii calculated for 4 # directions, left and right, x and y, then average radiusXL = sumx while pupilPixels[radiusXL,sumy] == 0: radiusXL += 1 radiusXL -= sumx - 2 radiusYD = sumy while pupilPixels[sumx,radiusYD] == 0: radiusYD += 1 radiusYD -= sumy - 2 rad = (radiusXL,radiusYD) avgRad = int((radiusXL+radiusYD)/2) HoughObject = hough.HoughTransform(SobelPupilImage,(sumx-1,sumy-1),(4,4),min(rad)-5,max(rad)+3) pX,pY,pR = HoughObject.pupilHough() PHtime = time.time() - prePH preSI = time.time() SobelIrisObject = algorithms.sobelFilter(irisThreshImage) SobelIrisImage = SobelIrisObject.outputImage SItime = time.time() - preSI preIH = time.time() irisHoughObj = hough.HoughTransform(SobelIrisImage,(0,0),(0,0),0,0) iR = irisHoughObj.irisHough(pX,pY,pR) IHtime = time.time() - preIH preUW = time.time() unwrapObj = demod.unwrap(grayscaleImage,(pX,pY),pR,iR) polarImg = unwrapObj.unwrap() polarImg.save(savePath + "/polar/" + name) UWtime = time.time() - preUW gaborObj = demod.demod(polarImg) irisCode = gaborObj.demod() # Save various images. # Mainly used to debug in case of a failure. # This will be set in the prefences. self.saveImagePref = 0 if (self.saveImagePref == 1): grayscaleImage.save(savePath + "gray-" + name) blurredImage.save(savePath + "blur-" + name) pupilThreshImage.save(savePath + "threshp-" + name) irisThreshImage.save(savePath + "threshi-" + name) SobelPupilImage.save(savePath + "sobelp-"+name) SobelIrisImage.save(savePath + "sobeli-"+name) self.saveHist = 0 if (self.saveHist == 1): plt.bar(ind,hist,color='b') plt.savefig(savePath + "hist-" + name + ".png") # Draw circles on result image pupilDrawObject = imgUtils.Utils(inputImage) pupilDraw = pupilDrawObject.drawCircle(pX,pY,pR) irisDrawObject = imgUtils.Utils(inputImage) irisDraw = irisDrawObject.drawCircle(pX,pY,iR) inputImage.save(savePath + "/circles/" + name) #Clean-up del grayscaleImage del blurredImage del pupilThreshImage del irisThreshImage del SobelPupilImage del SobelIrisImage print "Done" segTime = time.time()-initTime print "It took %.3f" % (1000 * segTime),"ms\n" return irisCode, inputImage