def convert_to_pairs(image, height, width, column_factor, row_factor): left_column = int(width*column_factor) right_column = width - left_column bottom_row = int(height*row_factor) top_row = height - bottom_row left_column_intersections = im.fast_check_column(left_column, image, bottom_row, top_row) right_column_intersections = im.fast_check_column(right_column, image, bottom_row, top_row) bottom_row_intersections = im.fast_check_row(bottom_row, image, left_column, right_column) top_row_intersections = im.fast_check_row(top_row, image, left_column, right_column) return (left_column_intersections, bottom_row_intersections, right_column_intersections, top_row_intersections)
def convert_to_pairs(image, height, width, column_factor, row_factor): left_column = int(width * column_factor) right_column = width - left_column bottom_row = int(height * row_factor) top_row = height - bottom_row left_column_intersections = im.fast_check_column(left_column, image, bottom_row, top_row) right_column_intersections = im.fast_check_column(right_column, image, bottom_row, top_row) bottom_row_intersections = im.fast_check_row(bottom_row, image, left_column, right_column) top_row_intersections = im.fast_check_row(top_row, image, left_column, right_column) return (left_column_intersections, bottom_row_intersections, right_column_intersections, top_row_intersections)
def get_ratio(img, x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, last_ratio, column_factor, row_factor, ratio_queue, layout_queue, direction_list): image = im.load_image(str(img)) height = image.size[1] width = image.size[0] intersections = convert_to_pairs(image, height, width, column_factor, row_factor) lengths = [] intersection_points = [] for intersection in intersections: lengths.append(len(intersection)) left = intersections[0] top = intersections[1] right = intersections[2] bottom = intersections[3] left, top, right = get_points(left, right, bottom, top) points = left + top + right if len(left) == 0 and len(right) == 0 and len(top) == 0: return last_ratio elif ((len(left) == 0 and len(right) == 0 and len(top) > 0)): return choose_path(ratio_queue, layout_queue, direction_list, [cog_y(points)], 'normal_straight', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif (len(left) == 0 and len(right) > 0 and len(top) == 0): return choose_path(ratio_queue, layout_queue, direction_list, [cog_x(points)], 'normal_right', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif (len(left) > 0 and len(right) == 0 and len(top) == 0) : return choose_path(ratio_queue, layout_queue, direction_list, [cog_x(points)], 'normal_left', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif len(left) > 0 and len(right) > 0 and len(top) == 0: left_des = cog_y(left) right_des = cog_y(right) return choose_path(ratio_queue, layout_queue, direction_list, [left_des, right_des], 'T_flat', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif len(left) > 0 and len(right) == 0 and len(top) > 0: left_des = cog_y(left) top_des = cog_x(top) return choose_path(ratio_queue, layout_queue, direction_list, [left_des, top_des], 'T_left', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif len(left) == 0 and len(right) > 0 and len(top) > 0: right_des = cog_y(right) top_des = cog_x(top) return choose_path(ratio_queue, layout_queue, direction_list, [top_des, right_des], 'T_right', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) else: left_des = cog_x(top) right_des = cog_y(right) top_des = cog_x(top) return choose_path(ratio_queue, layout_queue, direction_list, [left_des, top_des, right_des], 'crossroads', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height)
def get_ratio(img, x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, last_ratio, column_factor, row_factor, ratio_queue, layout_queue, direction_list): image = im.load_image(str(img)) height = image.size[1] width = image.size[0] intersections = convert_to_pairs(image, height, width, column_factor, row_factor) lengths = [] intersection_points = [] for intersection in intersections: lengths.append(len(intersection)) left = intersections[0] top = intersections[1] right = intersections[2] bottom = intersections[3] left, top, right = get_points(left, right, bottom, top) points = left + top + right if len(left) == 0 and len(right) == 0 and len(top) == 0: return last_ratio elif ((len(left) == 0 and len(right) == 0 and len(top) > 0)): return choose_path(ratio_queue, layout_queue, direction_list, [cog_y(points)], 'normal_straight', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif (len(left) == 0 and len(right) > 0 and len(top) == 0): return choose_path(ratio_queue, layout_queue, direction_list, [cog_x(points)], 'normal_right', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif (len(left) > 0 and len(right) == 0 and len(top) == 0): return choose_path(ratio_queue, layout_queue, direction_list, [cog_x(points)], 'normal_left', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif len(left) > 0 and len(right) > 0 and len(top) == 0: left_des = cog_y(left) right_des = cog_y(right) return choose_path(ratio_queue, layout_queue, direction_list, [left_des, right_des], 'T_flat', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif len(left) > 0 and len(right) == 0 and len(top) > 0: left_des = cog_y(left) top_des = cog_x(top) return choose_path(ratio_queue, layout_queue, direction_list, [left_des, top_des], 'T_left', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) elif len(left) == 0 and len(right) > 0 and len(top) > 0: right_des = cog_y(right) top_des = cog_x(top) return choose_path(ratio_queue, layout_queue, direction_list, [top_des, right_des], 'T_right', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height) else: left_des = cog_x(top) right_des = cog_y(right) top_des = cog_x(top) return choose_path(ratio_queue, layout_queue, direction_list, [left_des, top_des, right_des], 'crossroads', x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, width, height)
import Image_2 import time for i in range(0,30): start = time.time() im = Image_2.load_image() c1 = Image_2.fast_check_column(5,im) c2 = Image_2.fast_check_column(10,im) r1 = Image_2.fast_check_row(5,im) r2 = Image_2.fast_check_row(10,im) end = time.time() print end-start
import Image_2 import time for i in range(0, 30): start = time.time() im = Image_2.load_image() c1 = Image_2.fast_check_column(5, im) c2 = Image_2.fast_check_column(10, im) r1 = Image_2.fast_check_row(5, im) r2 = Image_2.fast_check_row(10, im) end = time.time() print end - start