Esempio n. 1
0
 def test_read_should_raise_exception_when_camera_not_started(
         self, mock_VideoCapture):
     camera = Camera()
     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.read()
Esempio n. 2
0
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()
Esempio n. 3
0
 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)
Esempio n. 4
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)
Esempio n. 5
0
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()
Esempio n. 6
0
    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)
Esempio n. 7
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)
Esempio n. 8
0
    def test_shape_returns_frame_shape_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_shape = camera.shape
        camera.stop()

        self.assertEqual((10, 20, 3), actual_image_shape)
Esempio n. 9
0
    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)
Esempio n. 10
0
    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)
Esempio n. 11
0
 def test_get_settings_raises_exception_if_camera_not_started(
         self, mock_VideoCapture):
     camera = Camera()
     with self.assertRaises(Exception):
         camera.get_settings()
Esempio n. 12
0
 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')