def get_ratio(img, x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, last_ratio, column_factor, row_factor, correction): image = im.load_image(str(img)) height = len(image) width = len(image[0]) intersections = convert_to_pairs(image, height, width, column_factor, row_factor) print intersection for intersection in intersections: new_intersection = [] if is_odd(len(intersection)): return last_ratio left_white_lines = [] for i in xrange(0,len(intersections[0])/2): new_point = (intersections[0][2*i], intersections[0][2*i+1]) left_white_lines.append(new_point) top_white_lines = [] for i in xrange(len(intersections[2])/2): new_point = (intersections[2][2*i], intersections[2][2*i+1]) top_white_lines.append(new_point) right_white_lines = [] for i in xrange(len(intersections[1])/2): new_point = (intersections[1][-2*i-1], intersections[1][-2*i]) right_white_lines.append(new_point) bottom_white_lines = [] for i in xrange(0,len(intersections[3])/2): new_point = (intersections[3][-2*i-1], intersections[3][-2*i]) bottom_white_lines.append(new_point) # + top_white_lines white_lines = left_white_lines + right_white_lines + bottom_white_lines destination = choose_path(white_lines) x_right = destination[0][0] y_right = destination[0][1] x_left = destination[1][0] y_left = destination[1][1] left_distance = np.sqrt((x_left - x_wheel_left)**2 + (y_left - y_wheel_left)**2) right_distance= np.sqrt((x_right - x_wheel_right)**2 + (y_right - y_wheel_right)**2) ratio = right_distance/left_distance last_ratio = correction*ratio #print 'Ratio: ' + str(correction*ratio) return correction*ratio
def get_ratio(img, x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, last_ratio, column_factor, row_factor, correction): image = im.load_image(str(img)) height = len(image) width = len(image[0]) intersections = convert_to_pairs(image, height, width, column_factor, row_factor) print intersection for intersection in intersections: new_intersection = [] if is_odd(len(intersection)): return last_ratio left_white_lines = [] for i in xrange(0, len(intersections[0]) / 2): new_point = (intersections[0][2 * i], intersections[0][2 * i + 1]) left_white_lines.append(new_point) top_white_lines = [] for i in xrange(len(intersections[2]) / 2): new_point = (intersections[2][2 * i], intersections[2][2 * i + 1]) top_white_lines.append(new_point) right_white_lines = [] for i in xrange(len(intersections[1]) / 2): new_point = (intersections[1][-2 * i - 1], intersections[1][-2 * i]) right_white_lines.append(new_point) bottom_white_lines = [] for i in xrange(0, len(intersections[3]) / 2): new_point = (intersections[3][-2 * i - 1], intersections[3][-2 * i]) bottom_white_lines.append(new_point) # + top_white_lines white_lines = left_white_lines + right_white_lines + bottom_white_lines destination = choose_path(white_lines) x_right = destination[0][0] y_right = destination[0][1] x_left = destination[1][0] y_left = destination[1][1] left_distance = np.sqrt((x_left - x_wheel_left)**2 + (y_left - y_wheel_left)**2) right_distance = np.sqrt((x_right - x_wheel_right)**2 + (y_right - y_wheel_right)**2) ratio = right_distance / left_distance last_ratio = correction * ratio #print 'Ratio: ' + str(correction*ratio) return correction * ratio
def is_redundant_point(tuple1, tuple2): return (fuzzyequal(tuple1[0], tuple2[0], group_factor) or fuzzyequal(tuple1[1], tuple2[1], group_factor)) def fuzzyequal(x, y, epsilon): return (abs(x - y) < epsilon) def choose_path(white_lines): return white_lines[0] start = time.time() for k in xrange(1, 10): t0 = time.time() image = im.load_image('picture_' + str(k) + '.jpg') height = len(image) width = len(image[0]) t1 = time.time() a = Image.open('picture_' + str(k) + '.jpg') t2 = time.time() get_ratio(image, x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, last_ratio, column_factor, row_factor, correction, k, a) t3 = time.time() print t3 - t2 + t1 - t0 end = time.time()
top_row_intersections = im.fast_check_row(top_row, image, left_column, right_column) bottom_row_intersections = im.fast_check_row(bottom_row, image, left_column, right_column) return (left_column_intersections, right_column_intersections, top_row_intersections, bottom_row_intersections) def is_redundant_point(tuple1, tuple2): return (fuzzyequal (tuple1[0], tuple2[0], group_factor) or fuzzyequal (tuple1[1], tuple2[1], group_factor)) def fuzzyequal(x, y, epsilon): return (abs(x-y) < epsilon) def choose_path(white_lines): return white_lines[0] start = time.time() for k in xrange(1,10): t0 = time.time() image = im.load_image('picture_' + str(k) + '.jpg') height = len(image) width = len(image[0]) t1 = time.time() a = Image.open('picture_' + str(k) + '.jpg') t2 = time.time() get_ratio(image, x_wheel_left, y_wheel_left, x_wheel_right, y_wheel_right, last_ratio, column_factor, row_factor, correction, k, a) t3 = time.time() print t3-t2+t1-t0 end = time.time()