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 __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)
from particletracking import dataframes from labvision import video, images import numpy as np import filehandling file_store = "/media/data/Data/FirstOrder/Hysterisis/FlatPlate/Trial2/0.2_up_1.hdf5" file_vid = "/media/data/Data/FirstOrder/Hysterisis/FlatPlate/Trial2/0.2_up_1.MP4" metadata = dataframes.load_metadata(file_store) vid = video.ReadVideo(file_vid) box = metadata['crop'] frame = vid.read_frame(vid.num_frames - 1) frame = images.crop(frame, box) xmin = 750 xmax = 1250 ymin = 750 ymax = 1250 vertices = np.array([[xmin, ymin], [xmin, ymax], [xmax, ymax], [xmax, ymin]]) frame = images.draw_polygon(frame, vertices, thickness=3) images.save( frame, "/media/data/Data/FirstOrder/Hysterisis/FlatPlate/Trial2/HexagonFigures/box_end.png" ) images.display(frame)
frame = up_video.read_next_frame() frame = images.crop(frame, up_data.metadata['crop']) result = images.crop_polygon(frame) bbox = result.bbox with open(save_direc + 'bbox.txt', 'w') as f: f.writelines([ 'BBOX xmin, xmax, ymin, ymax', str(bbox.xmin), str(bbox.xmax), str(bbox.ymin), str(bbox.ymax) ]) frame = images.draw_polygon( frame, np.array([[bbox.xmin, bbox.ymin], [bbox.xmin, bbox.ymax], [bbox.xmax, bbox.ymax], [bbox.xmax, bbox.ymin]], dtype=np.float32), color=images.RED, thickness=2) images.save(frame, save_direc + 'im.png') down_df = down_data.df[down_data.df.x.between(bbox.xmin, bbox.xmax)] down_df = down_df[down_df.y.between(bbox.ymin, bbox.ymax)] up_df = up_data.df[up_data.df.x.between(bbox.xmin, bbox.xmax)] up_df = up_df[up_df.y.between(bbox.ymin, bbox.ymax)] # down_duty, down_density = density_duty_mapped(down_df) # up_duty, up_density = density_duty_mapped(up_df) down_duty, down_density = density_duty_mapped(down_df)