def findMask(images_name): # for each image calculates its mask compare_images = [] for img_name in images_name : img = cv2.imread(img_name) compare_images = compare_images + [calc_binary_image2.calcMask(img,img_name)] return compare_images
def compareBySize(images_name): global H,compare_images,nu print help_message ######### STEP 1 ################# # for each image calculates its mask compare_images = [] for img_name in images_name : img = cv2.imread(img_name) compare_images = compare_images + [calc_binary_image2.calcMask(img,img_name)] ######## STEP 2 ################## # destroy old windows cv2.destroyWindow('config') cv2.destroyWindow('floodfill') cv2.destroyWindow('median_blur') cv2.destroyWindow('erode') cv2.destroyWindow('final_img') cv2.destroyWindow('img') cv2.destroyWindow('canny') print ''' STEP 2 (comparison) s - look for the more similar images with the chosen data q - EXIT ''' # creates config window with its trackbars cv2.namedWindow('config2') cv2.createTrackbar('eps1','config2',100,1000,dummy) cv2.createTrackbar('eps2','config2',50,1000,dummy) cv2.createTrackbar('eps3','config2',25,1000,dummy) cv2.createTrackbar('eps4','config2',150,1000,dummy) cv2.createTrackbar('eps5','config2',150,1000,dummy) cv2.createTrackbar('eps6','config2',150,1000,dummy) cv2.createTrackbar('eps7(area)','config2',150,5000,dummy) cv2.createTrackbar('show all input images', 'config2',0,2,onShowImages) cv2.createTrackbar('show all masks','config2', 0,2,onMaskImages) cv2.createTrackbar('show all selected masks','config2', 0,1,onShowImages) # selects main image for comparison and calculates its moments pimg = compare_images[0][0] img = compare_images[0][1].copy() moments = cv2.moments(pimg,True) #print moments nu = [moments['nu02']] + [moments['nu11']] + [moments['nu12']] + [moments['nu20']] + [moments['nu21']] + [moments['nu30']] + [moments['m00']] #print nu H = cv2.HuMoments(moments) cv2.putText(img,str(nu[0:2]),(50,img.shape[0]-100),cv2.FONT_HERSHEY_SIMPLEX,0.5,(100,0,200)) cv2.putText(img,str(nu[2:4]),(50,img.shape[0]-75),cv2.FONT_HERSHEY_SIMPLEX,0.5,(100,0,200)) cv2.putText(img,str(nu[4:6]),(50,img.shape[0]-50),cv2.FONT_HERSHEY_SIMPLEX,0.5,(100,0,200)) cv2.putText(img,str(H[6:]),(50,img.shape[0]-25),cv2.FONT_HERSHEY_SIMPLEX,0.5,(100,0,200)) # compares pimg moments with all other images moments imToShow = compare(nu,compare_images,0,0) while True: cv2.imshow('image',img) key = cv2.waitKey(5) # removes old windows and calculates the most similar images with the new values if key == ord('s'): for im in compare_images: cv2.destroyWindow('im_'+str(im[2])) cv2.destroyWindow('im_mask_'+str(im[2])) cv2.destroyWindow('selected_'+str(im[2])) cv2.imshow('image',img) imToShow = compare(nu,compare_images,cv2.getTrackbarPos('show all input images','config2'), cv2.getTrackbarPos('sohw all selected masks','config2')) # EXIT if key == ord('q'): return imToShow