예제 #1
0
    def balance(self, repeats=5, threshold=10):
        balanced = False
        window = images.Displayer('Levelling')
        center = (0, 0)
        distance = 0
        while balanced is False:
            centers = []
            for f in range(repeats):
                self.f = f
                self.shaker.change_duty(self.start)
                time.sleep(5)
                self.shaker.ramp(self.start, self.end, self.rate, record=False,
                                 stop_at_end=False)
                time.sleep(5)
                im = self.im()
                center = self.find_center(im)

                centers.append(center)
                mean_center = np.mean(centers, axis=0).astype(np.int32)
                annotated_im = self.annotate_image(im, center,
                                                   mean_center, distance,
                                                   centers)
                window.update_im(annotated_im)
            mean_center = np.mean(centers, axis=0).astype(np.int32)
            instruction, distance = self.find_instruction(mean_center)
            annotated_im = self.annotate_image(im, center, mean_center,
                                               distance, centers)
            window.update_im(annotated_im)
            if distance > threshold:
                self.run_instruction(instruction)
            else:
                balanced = True
                print('BALANCED')
                print(datetime.datetime.now())
                self.shaker.change_duty(0)
예제 #2
0
 def balance(self, repeats=5, threshold=10):
     balanced = False
     window = images.Displayer('Levelling')
     center = (0, 0)
     while balanced is False:
         centers = []
         self.shaker.ramp(630, 500, 0.5)
         for f in range(repeats):
             self.f = f
             time.sleep(0.1)
             im = self.get_frame()
             center = self.get_center(im)
             centers.append(center)
         mean_center = np.mean(centers, axis=0)
         instruction, distance = self.find_instruction(mean_center)
         annotated_im = self.annotate_image(im, center, mean_center,
                                            distance, centers)
         window.update_im(annotated_im)
         if distance > threshold:
             self.run_instruction(instruction)
             time.sleep(10)
         else:
             balanced = True
             print('BALANCED')
             print(datetime.datetime.now())
             self.shaker.change_duty(0)
N = min(NL, NS)


def get_crop_result(vid):
    frame = vid.read_next_frame()
    frame = ndimage.rotate(frame, -120, reshape=False)
    crop_result = images.crop_rectangle(frame)
    vid.set_frame(0)
    return crop_result


def fix_frame(frame):
    frame = ndimage.rotate(frame, -120, reshape=False)
    frame = images.crop_and_mask(frame, crop_result.bbox, crop_result.mask)
    return frame


crop_result = get_crop_result(liquid)

window = images.Displayer('frames')

for f in range(N):
    liquid_frame = liquid.read_next_frame()
    liquid_frame = fix_frame(liquid_frame)
    solid_frame = solid.read_next_frame()
    solid_frame = fix_frame(solid_frame)

    frames = images.vstack(liquid_frame, solid_frame)
    window.update_im(frames)