def annotate_image(self, im, current_center, mean_center, distance, centers): im = im.copy() if images.depth(im) != 3: im = images.gray_to_bgr(im) im = images.draw_circle(im, current_center[0], current_center[1], 5, color=images.ORANGE, thickness=-1) im = images.draw_circle(im, self.center[0], self.center[1], 5, images.RED) im = images.draw_circle(im, mean_center[0], mean_center[1], 5, images.BLUE) font = cv2.FONT_HERSHEY_SIMPLEX im = cv2.putText(im, 'Tray Center', (10, 30), font, .5, images.RED, 2, cv2.LINE_AA) im = cv2.putText(im, 'Current Center', (10, 60), font, .5, images.ORANGE, 2, cv2.LINE_AA) im = cv2.putText(im, 'Mean Center', (10, 90), font, .5, images.BLUE, 2, cv2.LINE_AA) im = cv2.putText(im, 'Pixel distance : {:.3f}'.format(distance), (10, 120), font, .5, images.GREEN, 2, cv2.LINE_AA) im = cv2.putText(im, 'Repeat: {}'.format(self.f), (10, 150), font, .5, images.GREEN, 2, cv2.LINE_AA) for center in centers: im = images.draw_circle(im, center[0], center[1], 5, images.YELLOW) im = cv2.putText(im, 'Old Centers', (10, 180), font, .5, images.YELLOW, 2, cv2.LINE_AA) return im
def find_center(self, im): im0 = im.copy() im = images.threshold(im, 80) im = images.opening(im, (6, 6)) center = images.center_of_mass(im) im0 = images.gray_to_bgr(im0) im0 = images.draw_circle(im0, center[0], center[1], 5) im = images.gray_to_bgr(im) im = images.draw_circle(im, center[0], center[1], 5) images.save(images.hstack(im, im0), self.log_direc + '{}.png'.format(self.i)) self.i += 1 return center
def __init__(self, start, end, rate, step_size=50): self.start = start self.end = end self.rate = rate now = datetime.datetime.now() self.log_direc = "/media/data/Data/Logs/{}_{}_{}_{}_{}/".format( now.year, now.month, now.day, now.hour, now.minute) try: os.mkdir(self.log_direc) except FileExistsError as e: print(e) self.i = 0 self.shaker = shaker.Shaker() self.shaker.change_duty(self.start) self.step_size = step_size cam_num = camera.guess_camera_number() port = STEPPER_CONTROL self.ard = arduino.Arduino(port) self.motors = stepper.Stepper(self.ard) self.motors.move_motor(1, 100, '+') self.motors.move_motor(2, 100, '+') self.motors.move_motor(1, 100, '-') self.motors.move_motor(2, 100, '-') self.cam = camera.Camera(cam_num=cam_num) im = self.cam.get_frame() self.hex, self.center, self.crop, self.mask = self.find_hexagon(im) im = images.crop_and_mask(im, self.crop, self.mask) self.im_shape = im.shape im = images.draw_polygon(im, self.hex) im = images.draw_circle(im, self.center[0], self.center[1], 3) images.display(im)
def find_center(self, im): im0 = im.copy() im = images.gaussian_blur(im, (5, 5)) circles = trackpy.locate(im, 5) center = circles[['x', 'y']].values.mean(axis=0) im0 = images.gray_to_bgr(im0) im0 = images.draw_circle(im0, center[0], center[1], 5) im1 = images.gray_to_bgr(im) im1 = images.draw_circle(im1, center[0], center[1], 5) im2 = images.gray_to_bgr(im) im2 = images.draw_circles(im2, circles[['x', 'y', 'size']].values) images.save(images.hstack(im1, im0, im2), self.log_direc + '{}.png'.format(self.i)) self.i += 1 return center
def __init__(self): self.shaker = shaker.Shaker() self.shaker.change_duty(600) port = STEPPER_CONTROL self.ard = arduino.Arduino(port) self.motors = stepper.Stepper(self.ard) cam_num = camera.guess_camera_number() self.cam = camera.Camera(cam_num=cam_num) im = self.cam.get_frame() self.hex, self.center, self.crop, self.mask = self.find_hexagon(im) im = images.crop_and_mask(im, self.crop, self.mask) self.im_shape = im.shape im = images.draw_polygon(im, self.hex) im = images.draw_circle(im, self.center[0], self.center[1], 3) images.display(im)