def process_image(): reset_tiles() start_time = time.time() break_fully = False output = '' debug_images = [] for blur in [1,3,5,7,9]: print(break_fully) if break_fully: break for erode in [1,2,3,4,5,6,7]: if break_fully: break for iterations in [1,2,3,4]: try: debug_images, output = frameProcessor.process_image(blur, threshold, adjustment, erode, iterations) if '.' in output and len(output) == 4: output = remove_duplicate_chars(output) elif '.' not in output and len(output) == 3: output = remove_duplicate_chars(output) if output != '' and ((len(output) == 2 and '.' not in output) or (len(output) == 3 and '.' in output) ) and (check_instance(output, float) or check_instance(output, int)): print("Output:"+output) break_fully = True break except: output = output for image in debug_images: show_img(image[0], image[1]) print(output) print("Processed image in %s seconds" % (time.time() - start_time)) cv2.imshow(window_name, frameProcessor.img) cv2.moveWindow(window_name, 600, 600)
def process_image(): reset_tiles() start_time = time.time() break_fully = False output = '' debug_images = [] print "Blur:" + str(blur) print "Erode:" + str(erode) print "Iterations:" + str(iterations) try: debug_images, output = frameProcessor.process_image( blur, threshold, adjustment, erode, iterations) if '.' in output and len(output) == 4: output = remove_duplicate_chars(output) elif '.' not in output and len(output) == 3: output = remove_duplicate_chars(output) if output != '' and ( (len(output) == 2 and '.' not in output) or (len(output) == 3 and '.' in output)) and (check_instance( output, float) or check_instance(output, int)): print("Output:" + output) except: output = output for image in debug_images: show_img(image[0], image[1]) print(output) print("Processed image in %s seconds" % (time.time() - start_time)) cv2.imshow(window_name, frameProcessor.img) cv2.moveWindow(window_name, 600, 600)
def process_image(path, show=True, write=False): print path img = cv2.imread(path) if show: show_img('orig', img) file_folder, full_file = os.path.split(path) file_name = full_file.split('.')[0] # erode_img(img, file_name, file_folder, show, write) dilate_img(img, file_name, file_folder, show, write)
def erode_img(img, file_name, file_folder, show, write): for iterations in range(1, 3): for erode in range(1, 4, 2): kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (erode, erode)) eroded = cv2.erode(img, kernel, iterations=iterations) for rot in range(-2, 3, 2): dst = rotate_image(eroded, rot) title = 'eroded-r-' + str(rot) + '-e-' + str(erode) + '-i-' + str(iterations) if show: show_img(title, dst) if write: cv2.imwrite(file_folder + '/' + file_name + title + '.png', dst)
def process_image(): reset_tiles() start_time = time.time() debug_images, output = frameProcessor.process_image(blur, threshold, adjustment, erode, iterations) for image in debug_images: show_img(image[0], image[1]) print("Processed image in %s seconds" % (time.time() - start_time)) cv2.imshow(window_name, frameProcessor.img) cv2.moveWindow(window_name, 600, 600)
def dilate_img(img, file_name, file_folder, show, write): for iterations in range(1, 4, 2): for dilate in range(1, 4, 2): kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (dilate, dilate)) dilated = cv2.dilate(img, kernel, iterations=iterations) for rot in range(-2, 3, 2): dst = rotate_image(dilated, rot) title = 'dilated-r-' + str(rot) + '-d-' + str(dilate) + '-i-' + str(iterations) if show: show_img(title, dst) if write: print 'Writing ' + file_folder + '/' + file_name + title + '.png' cv2.imwrite(file_folder + '/' + file_name + title + '.png', dst)