def test_start_should_start_cv_videoCapture(self, mock_VideoCapture): expected_image = Mock() expected_image.shape = (10, 20, 3) camera = Camera() mock_video_capture = mock_VideoCapture.return_value mock_video_capture.read.return_value = (True, expected_image) camera.start() mock_VideoCapture.assert_called_once_with(0)
def __init__(self): self.camera = Camera() self.camera.start() self._default_roi = ROI(0.0, 0.0, 1.0, 1.0) self._default_encoder = Encoder((0.2, 0.2), 382, 100, 20, 200) self._default_laser_detector = LaserDetector2(225, 'red') self.encoder = self._default_encoder self.roi = self._default_roi self.laser_detector = self._default_laser_detector self.video_processor = VideoProcessor(self.camera, self.encoder, self.roi, self.laser_detector)
def test_get_settings_should_exclude_dict_settings_when_less_then_0( self, mock_VideoCapture): mock_video_capture = mock_VideoCapture.return_value mock_video_capture.get.return_value = -1.0 expected_image = Mock() expected_image.shape = (10, 20, 3) mock_video_capture.read.return_value = (True, expected_image) expected = [] camera = Camera() camera.start() results = camera.get_settings() self.assertListEqual(expected, results)
def main(): config = configparser.ConfigParser() config.read('config') gpio = config['gpio'] photobooth_config = config['photobooth'] with Screen() as screen, \ Cluster(config['cluster.co']) as cluster, \ Button(int(gpio['take_picture']), Actions.TAKE_PICTURES) as picture_button, \ Button(int(gpio['self_destruct']), Actions.SELF_DESTRUCT) as destruction_button, \ Relay(int(gpio['ioniser'])) as ioniser, \ Relay(int(gpio['fan'])) as fan, \ Relay(int(gpio['flash'])) as flash, \ Camera(IMAGE_FOLDER, flash) as camera: screen.update_display(message='Folder Check...', size=100, duration=0) os.makedirs(IMAGE_FOLDER, exist_ok=True) speakers = Speaker() actionables = Actionables( [picture_button, destruction_button, Keyboard()]) self_destruction = SelfDestruction(screen, camera, speakers, ioniser, fan) normal_mode = NoTrap(screen, camera) traps = [ SlowTrap(screen, camera), SpeedTrap(screen, camera), DoubleTrap(screen, camera, time.sleep), HornTrap(screen, camera, time.sleep, speakers) ] Photobooth( screen, actionables, normal_mode, traps, self_destruction, cluster, MyRandom(int(photobooth_config['trap_percentage']))).start()
def test_shape_raises_exception_if_camera_not_started( self, mock_VideoCapture): expected_image = Mock() expected_image.shape = (10, 20, 3) camera = Camera() mock_video_capture = mock_VideoCapture.return_value mock_video_capture.read.return_value = (True, expected_image) with self.assertRaises(Exception): camera.shape
def main(): config = configparser.ConfigParser() config.read('config') gpio = config['gpio'] with Screen() as screen, \ Relay(int(gpio['flash'])) as flash, \ Camera('Photos', flash) as camera: actionables = Actionables([Keyboard()]) camera.start_preview() action = Actions.TAKE_PICTURES while action != Actions.QUIT: action = actionables.wait_for_event()
def test_get_setting_should_returns_dict_of_settings_when_started( self, mock_VideoCapture): mock_video_capture = mock_VideoCapture.return_value mock_video_capture.get.return_value = 1.0 expected_image = Mock() expected_image.shape = (10, 20, 3) mock_video_capture.read.return_value = (True, expected_image) expected = [ { 'name': 'Brightness', 'value': 1.0, }, { 'name': 'Contrast', 'value': 1.0, }, { 'name': 'Saturation', 'value': 1.0, }, { 'name': 'Hue', 'value': 1.0, }, { 'name': 'Gain', 'value': 1.0, }, { 'name': 'Exposure', 'value': 1.0, }, ] camera = Camera() camera.start() results = camera.get_settings() self.assertListEqual(expected, results)
def test_read_should_return_image_when_camera_running( self, mock_VideoCapture): expected_image = Mock() expected_image.shape = (10, 20, 3) camera = Camera() mock_video_capture = mock_VideoCapture.return_value mock_video_capture.read.return_value = (True, expected_image) camera.start() actual_image = camera.read() camera.stop() self.assertEqual(expected_image, actual_image)
def test_set_setting_should_raise_exception_if_setting_not_in_list( self, mock_VideoCapture): mock_video_capture = mock_VideoCapture.return_value mock_video_capture.get.return_value = 1.0 expected_image = Mock() expected_image.shape = (10, 20, 3) mock_video_capture.read.return_value = (True, expected_image) camera = Camera() camera.start() with self.assertRaises(Exception): camera.set_setting('Pizza', 1.0)
def test_set_setting_should_set_setting(self, mock_VideoCapture): mock_video_capture = mock_VideoCapture.return_value mock_video_capture.get.return_value = 1.0 expected_image = Mock() expected_image.shape = (10, 20, 3) mock_video_capture.read.return_value = (True, expected_image) camera = Camera() camera.start() camera.set_setting('Hue', 1.0) mock_video_capture.set.assert_called_once_with(cv2.CAP_PROP_HUE, 1.0)
class ScannerAPI(object): def __init__(self): self.camera = Camera() self.camera.start() self._default_roi = ROI(0.0, 0.0, 1.0, 1.0) self._default_encoder = Encoder((0.2, 0.2), 382, 100, 20, 200) self._default_laser_detector = LaserDetector2(225, 'red') self.encoder = self._default_encoder self.roi = self._default_roi self.laser_detector = self._default_laser_detector self.video_processor = VideoProcessor(self.camera, self.encoder, self.roi, self.laser_detector) def set_region_of_interest_from_abs_points(self, point1, point2, frame_shape_xy): self.roi = ROI.set_from_abs_points( point1, point2, [frame_shape_xy[1], frame_shape_xy[0], 3]) self.video_processor.roi = self.roi def set_region_of_interest_from_rel_points(self, x_rel, y_rel, w_rel, h_rel): self.roi = ROI(x_rel, y_rel, w_rel, h_rel) self.video_processor.roi = self.roi def capture_image(self, call_back=None, section_offset=0): if call_back: self.video_processor.subscribe( ImageCapture(self.encoder.sections, section_offset), call_back) else: self.video_processor.subscribe( ImageCapture(self.encoder.sections, section_offset)) def capture_points_xyz(self, laser_theta, points=None, call_back=None): if call_back: self.video_processor.subscribe( PointCaptureXYZ(self.encoder.sections, self.img2points, laser_theta, points), call_back) else: self.video_processor.subscribe( PointCaptureXYZ(self.encoder.sections, self.img2points, laser_theta, points)) def get_feed_image(self, size): return self.video_processor.get_bounded_image(*size) def configure_encoder(self, point, threshold, null_zone, sections): self.encoder = Encoder(point, threshold, null_zone, 20, sections) self.video_processor.encoder = self.encoder def configure_laser_detector(self, low_rbg_float, high_rgb_float): self.laser_detector = LaserDetector.from_rgb_float( low_rbg_float, high_rgb_float) self.video_processor.laser_detector = self.laser_detector def configure_laser_detector2(self, threshold, color): self.laser_detector = LaserDetector2(threshold, color) self.video_processor.laser_detector = self.laser_detector def configure(self, hardware, callback): self._hardware = hardware self.img2points = Image2Points(self._hardware, self.camera.shape) callback() def get_scanner_posisitions(self): if not hasattr(self, '_hardware'): raise Exception() return [rad for (rad, pos) in self._hardware.intersections_rad_mm] def start(self): self.video_processor.start() def stop(self): self.video_processor.stop() self.camera.stop()
class ScannerAPI(object): def __init__(self): self.camera = Camera() self.camera.start() self._default_roi = ROI(0.0, 0.0, 1.0, 1.0) self._default_encoder = Encoder((0.2, 0.2), 382, 100, 20, 200) self._default_laser_detector = LaserDetector2(225, 'red') self.encoder = self._default_encoder self.roi = self._default_roi self.laser_detector = self._default_laser_detector self.video_processor = VideoProcessor(self.camera, self.encoder, self.roi, self.laser_detector) def set_region_of_interest_from_abs_points(self, point1, point2, frame_shape_xy): self.roi = ROI.set_from_abs_points(point1, point2, [frame_shape_xy[1], frame_shape_xy[0], 3]) self.video_processor.roi = self.roi def set_region_of_interest_from_rel_points(self, x_rel, y_rel, w_rel, h_rel): self.roi = ROI(x_rel, y_rel, w_rel, h_rel) self.video_processor.roi = self.roi def capture_image(self, call_back=None, section_offset=0): if call_back: self.video_processor.subscribe(ImageCapture(self.encoder.sections, section_offset), call_back) else: self.video_processor.subscribe(ImageCapture(self.encoder.sections, section_offset)) def capture_points_xyz(self, laser_theta, points=None, call_back=None): if call_back: self.video_processor.subscribe(PointCaptureXYZ(self.encoder.sections, self.img2points, laser_theta, points), call_back) else: self.video_processor.subscribe(PointCaptureXYZ(self.encoder.sections, self.img2points, laser_theta, points)) def get_feed_image(self, size): return self.video_processor.get_bounded_image(*size) def configure_encoder(self, point, threshold, null_zone, sections): self.encoder = Encoder(point, threshold, null_zone, 20, sections) self.video_processor.encoder = self.encoder def configure_laser_detector(self, low_rbg_float, high_rgb_float): self.laser_detector = LaserDetector.from_rgb_float(low_rbg_float, high_rgb_float) self.video_processor.laser_detector = self.laser_detector def configure_laser_detector2(self, threshold, color): self.laser_detector = LaserDetector2(threshold, color) self.video_processor.laser_detector = self.laser_detector def configure(self, hardware, callback): self._hardware = hardware self.img2points = Image2Points(self._hardware, self.camera.shape) callback() def get_scanner_posisitions(self): if not hasattr(self, '_hardware'): raise Exception() return [rad for (rad, pos) in self._hardware.intersections_rad_mm] def start(self): self.video_processor.start() def stop(self): self.video_processor.stop() self.camera.stop()
def test_get_settings_raises_exception_if_camera_not_started( self, mock_VideoCapture): camera = Camera() with self.assertRaises(Exception): camera.get_settings()
def test_set_setting_should_raise_exception_if_camera_not_started( self, mock_VideoCapture): camera = Camera() with self.assertRaises(Exception): camera.set_setting('Hue', '1.0')