def edges_image(edge_sets): blank = Image.blank(image_original.width, image_original.height, 3, 255) for shape in edge_sets: for edge in shape: print(edge[1]) blank.draw_line(Point.from_array(edge[0]), Point.from_array(edge[1]), Color.Green(), 1) return blank
def _center_minimiser(center, dist): """ Used as the cost function in an optimisation routine. for a trial center point, we calculate an error that is the sum of the squares of the deviation of the distance of each slot from the mean distance of all the slots. """ errors = [] center = Point.from_array(center) distances = [p.distance_to_sq(center) for p in dist] mean = np.mean(distances) layer_errors = [(d - mean)**2 for d in distances] errors.extend(layer_errors) return sum(errors)
def _center_minimiser(center, layers): """ Used as the cost function in an optimisation routine. The puck consists of 2 layers of slots. Within a given layer, each slot is the same distance from the center point of the puck. Therefore for a trial center point, we calculate an error that is the sum of the squares of the deviation of the distance of each slot from the mean distance of all the slots in the layer. """ errors = [] center = Point.from_array(center) for layer in layers: distances = [p.distance_to_sq(center) for p in layer] mean = np.mean(distances) layer_errors = [(d - mean)**2 for d in distances] errors.extend(layer_errors) return sum(errors)
def _center_minimiser(center, layers): """ Used as the cost function in an optimisation routine. The puck consists of 2 layers of slots. Within a given layer, each slot is the same distance from the center point of the puck. Therefore for a trial center point, we calculate an error that is the sum of the squares of the deviation of the distance of each slot from the mean distance of all the slots in the layer. """ errors = [] center = Point.from_array(center) for layer in layers: distances = [p.distance_to_sq(center) for p in layer] mean = np.mean(distances) layer_errors = [(d-mean)**2 for d in distances] errors.extend(layer_errors) return sum(errors)
def _locate_finder_in_square(image, transform, size): """ For the located barcode in the image, identify which of the sides make up the finder pattern. """ radius = int(round(size/2)) center = transform.trans angle = transform.rot rotated = image.rotate(angle, center) sx1, sy1 = center.x-radius, center.y-radius sx2, sy2 = center.x+radius, center.y+radius thick = int(round(size / 14)) # Top x1, y1 = sx1, sy1 x2, y2 = sx2, sy1 + thick top = np.sum(rotated.img[y1:y2, x1:x2]) / (size * thick) # Left x1, y1 = sx1, sy1 x2, y2 = sx1 + thick, sy2 left = np.sum(rotated.img[y1:y2, x1:x2]) / (size * thick) # Bottom x1, y1 = sx1, sy2 - thick x2, y2 = sx2, sy2 bottom = np.sum(rotated.img[y1:y2, x1:x2]) / (size * thick) # Right x1, y1 = sx2 - thick, sy1 x2, y2 = sx2, sy2 right = np.sum(rotated.img[y1:y2, x1:x2]) / (size * thick) # Identify finder edges if top < bottom and left < right: c1 = [sx1, sy1] c2 = [sx1, sy2] c3 = [sx2, sy1] elif top < bottom and right < left: c1 = [sx2, sy1] c2 = [sx1, sy1] c3 = [sx2, sy2] elif bottom < top and left < right: c1 = [sx1, sy2] c2 = [sx2, sy2] c3 = [sx1, sy1] elif bottom < top and right < left: c1 = [sx2, sy2] c2 = [sx2, sy1] c3 = [sx1, sy2] else: return None # rotate points around center of square c1 = _rotate_around_point(Point.from_array(c1), angle, center) c2 = _rotate_around_point(Point.from_array(c2), angle, center) c3 = _rotate_around_point(Point.from_array(c3), angle, center) # Create finder pattern c1 = c1.intify() side1 = (c2 - c1).intify() side2 = (c3 - c1).intify() fp = FinderPattern(c1, side1, side2) return fp