Exemplo n.º 1
0
 def test_set_region_of_interest_rel_points_should_replace_the_roi_on_the_video_processor_with_new_roi(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.set_region_of_interest_from_rel_points(0.0, 0.0, 0.5, 0.9)
     self.assertNotEquals(api._default_roi, api.video_processor.roi)
     self.assertEquals(api.roi, api.video_processor.roi)
Exemplo n.º 2
0
    def test_start_starts_the_camera_first(self, mock_video_processor,
                                           mock_camera):
        global start_time_camera
        global start_time_video
        start_time_camera = 0
        start_time_video = 0

        def start_camera():
            global start_time_camera
            start_time_camera = time.time()
            time.sleep(0.01)

        def start_video():
            global start_time_video
            start_time_video = time.time()
            time.sleep(0.01)

        cam = mock_camera.return_value
        cam.shape = [300, 100]
        cam.start.side_effect = start_camera
        video = mock_video_processor.return_value
        video.start.side_effect = start_video
        api = ScannerAPI()
        api.start()
        self.assertTrue(start_time_video > start_time_camera,
                        '{} !> {}'.format(start_time_video, start_time_camera))
Exemplo n.º 3
0
 def test_configure_encoder_should_replace_the_encoder_on_the_video_processor_with_new_encoder(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_encoder((50, 50), 500, 100, 200)
     self.assertNotEquals(api._default_encoder, api.video_processor.encoder)
     self.assertEquals(api.encoder, api.video_processor.encoder)
Exemplo n.º 4
0
 def test_configure_laser_detector_should_create_an_laser_detector_with_the_given_config(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector((0.0, 0.0, 0.0), (0.0, 0.0, 0.5))
     self.assertEquals((0, 0, 0), api.laser_detector.low_bgr)
     self.assertEquals((127, 0, 0), api.laser_detector.high_bgr)
Exemplo n.º 5
0
 def test_configure_laser_detector2_should_replace_the_laser_detector_on_the_video_processor_with_new_laser_detector(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector2(255, 'red')
     self.assertNotEquals(api._default_laser_detector, api.video_processor.laser_detector)
     self.assertEquals(api.laser_detector, api.video_processor.laser_detector)
Exemplo n.º 6
0
 def test_capture_points_xyz_should_raise_exception_if_img2points_not_configured(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     with self.assertRaises(Exception):
         api.capture_points_xyz()
Exemplo n.º 7
0
 def test_configure_laser_detector_should_create_an_laser_detector_with_the_given_config(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector2(255, 'red')
     self.assertEquals(255, api.laser_detector.threshold)
     self.assertEquals('red', api.laser_detector.color)
Exemplo n.º 8
0
    def test_get_scanner_posisitions_raises_exception_if_not_configured(self, mock_Image2Points, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]

        api = ScannerAPI()

        with self.assertRaises(Exception):
            api.get_scanner_posisitions()
Exemplo n.º 9
0
 def test_set_region_of_interest_rel_points_should_replace_the_roi_on_the_video_processor_with_new_roi(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.set_region_of_interest_from_rel_points(0.0, 0.0, 0.5, 0.9)
     self.assertNotEquals(api._default_roi, api.video_processor.roi)
     self.assertEquals(api.roi, api.video_processor.roi)
Exemplo n.º 10
0
 def test_get_feed_image_gets_image_from_feed(self, mock_video_processor, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     video = mock_video_processor.return_value
     video.get_bounded_image.return_value = 'Expected Image'
     api = ScannerAPI()
     result = api.get_feed_image((200, 100))
     self.assertEqual('Expected Image', result)
Exemplo n.º 11
0
 def test_configure_encoder_should_replace_the_encoder_on_the_video_processor_with_new_encoder(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_encoder((50, 50), 500, 100, 200)
     self.assertNotEquals(api._default_encoder, api.video_processor.encoder)
     self.assertEquals(api.encoder, api.video_processor.encoder)
Exemplo n.º 12
0
 def test_start_starts_the_camera_and_video_processor(self, mock_video_processor, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     video = mock_video_processor.return_value
     api = ScannerAPI()
     api.start()
     cam.start.assert_called_once_with()
     video.start.assert_called_once_with()
Exemplo n.º 13
0
 def test_configure_laser_detector_should_create_an_laser_detector_with_the_given_config(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector((0.0, 0.0, 0.0), (0.0, 0.0, 0.5))
     self.assertEquals((0, 0, 0), api.laser_detector.low_bgr)
     self.assertEquals((127, 0, 0), api.laser_detector.high_bgr)
Exemplo n.º 14
0
 def test_capture_image_should_create_an_image_handler_and_subscribe_it_to_video_processor(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.capture_image()
     self.assertTrue(len(api.video_processor.handlers) > 0)
     self.assertEquals(ImageCapture, type(api.video_processor.handlers[0][0]))
     self.assertTrue(hasattr(api.video_processor.handlers[0][0], 'handle'))
Exemplo n.º 15
0
 def test_configure_laser_detector_should_create_an_laser_detector_with_the_given_config(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector2(255, 'red')
     self.assertEquals(255, api.laser_detector.threshold)
     self.assertEquals('red', api.laser_detector.color)
Exemplo n.º 16
0
 def test_configure_laser_detector2_should_replace_the_existing_laser_detector_with_new_laser_detector(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector2(255, 'red')
     initial = api.laser_detector
     api.configure_laser_detector2(225, 'blue')
     self.assertNotEquals(api.laser_detector, initial)
Exemplo n.º 17
0
 def test_configure_laser_detector_should_replace_the_existing_laser_detector_with_new_laser_detector(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector((0.0, 0.0, 0.0), (0.0, 0.0, 0.5))
     initial = api.laser_detector
     api.configure_laser_detector((0.5, 0.5, 0.5), (1.0, 1.0, 1.0))
     self.assertNotEquals(api.laser_detector, initial)
Exemplo n.º 18
0
 def test_configure_encoder_should_replace_the_existing_encoder_with_new_encoder(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_encoder((50, 50), 500, 100, 200)
     initial = api.encoder
     api.configure_encoder((51, 51), 500, 100, 200)
     self.assertNotEquals(api.encoder, initial)
Exemplo n.º 19
0
    def test_get_scanner_posisitions_raises_exception_if_not_configured(
            self, mock_Image2Points, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]

        api = ScannerAPI()

        with self.assertRaises(Exception):
            api.get_scanner_posisitions()
Exemplo n.º 20
0
 def test_capture_image_should_subscribe_with_expected_callback(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     callback = Mock()
     api.capture_image(callback)
     self.assertTrue(len(api.video_processor.handlers) > 0)
     self.assertEquals(ImageCapture, type(api.video_processor.handlers[0][0]))
     self.assertEqual(api.video_processor.handlers[0][1], callback)
Exemplo n.º 21
0
    def test_set_region_of_interest_from_abs_points_should_create_expected_roi(self, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]
        api = ScannerAPI()
        expected_roi = ROI.set_from_abs_points((0, 0), (151, 90), [100, 300, 3])

        api.set_region_of_interest_from_abs_points((0, 0), (151, 90), [300, 100])

        self.assertROIEquals(expected_roi, api.roi)
Exemplo n.º 22
0
 def test_configure_encoder_should_create_an_encoder_with_the_given_config(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_encoder((0.5, 0.5), 500, 100, 200)
     self.assertEquals((0.5, 0.5), api.encoder.relitive_point_xy)
     self.assertEquals(500, api.encoder.threshold)
     self.assertEquals(100, api.encoder.null_zone)
     self.assertEquals(200, api.encoder.sections)
Exemplo n.º 23
0
 def test_get_feed_image_gets_image_from_feed(self, mock_video_processor,
                                              mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     video = mock_video_processor.return_value
     video.get_bounded_image.return_value = 'Expected Image'
     api = ScannerAPI()
     result = api.get_feed_image((200, 100))
     self.assertEqual('Expected Image', result)
Exemplo n.º 24
0
 def test_start_starts_the_camera_and_video_processor(
         self, mock_video_processor, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     video = mock_video_processor.return_value
     api = ScannerAPI()
     api.start()
     cam.start.assert_called_once_with()
     video.start.assert_called_once_with()
Exemplo n.º 25
0
    def test_set_region_of_interest_rel_points_should_create_expected_roi(self, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]
        api = ScannerAPI()
        expected_roi = ROI(0.0, 0.0, 0.5, 0.9)

        api.set_region_of_interest_from_rel_points(0, 0, 0.5, 0.9)

        self.assertROIEquals(expected_roi, api.roi)
Exemplo n.º 26
0
 def test_capture_points_xyz_should_subscribe_with_expected_callback(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.img2points = True
     callback = Mock()
     api.capture_points_xyz(.45, call_back=callback)
     self.assertTrue(len(api.video_processor.handlers) > 0)
     self.assertEquals(PointCaptureXYZ, type(api.video_processor.handlers[0][0]))
     self.assertEqual(api.video_processor.handlers[0][1], callback)
Exemplo n.º 27
0
 def test_capture_image_should_create_an_image_handler_and_subscribe_it_to_video_processor(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.capture_image()
     self.assertTrue(len(api.video_processor.handlers) > 0)
     self.assertEquals(ImageCapture,
                       type(api.video_processor.handlers[0][0]))
     self.assertTrue(hasattr(api.video_processor.handlers[0][0], 'handle'))
Exemplo n.º 28
0
    def test_configure_configures_point_collection_and_calls_back(self, mock_Image2Points, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]

        callback = Mock()
        api = ScannerAPI()
        api.configure("bla", callback)

        mock_Image2Points.assert_called_once_with("bla", cam.shape)
        callback.assert_called_with()
Exemplo n.º 29
0
 def test_configure_laser_detector2_should_replace_the_laser_detector_on_the_video_processor_with_new_laser_detector(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector2(255, 'red')
     self.assertNotEquals(api._default_laser_detector,
                          api.video_processor.laser_detector)
     self.assertEquals(api.laser_detector,
                       api.video_processor.laser_detector)
Exemplo n.º 30
0
    def test_set_region_of_interest_rel_points_should_create_expected_roi(
            self, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]
        api = ScannerAPI()
        expected_roi = ROI(0.0, 0.0, 0.5, 0.9)

        api.set_region_of_interest_from_rel_points(0, 0, 0.5, 0.9)

        self.assertROIEquals(expected_roi, api.roi)
Exemplo n.º 31
0
 def test_configure_encoder_should_create_an_encoder_with_the_given_config(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_encoder((0.5, 0.5), 500, 100, 200)
     self.assertEquals((0.5, 0.5), api.encoder.relitive_point_xy)
     self.assertEquals(500, api.encoder.threshold)
     self.assertEquals(100, api.encoder.null_zone)
     self.assertEquals(200, api.encoder.sections)
Exemplo n.º 32
0
 def test_capture_image_should_subscribe_with_expected_callback(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     callback = Mock()
     api.capture_image(callback)
     self.assertTrue(len(api.video_processor.handlers) > 0)
     self.assertEquals(ImageCapture,
                       type(api.video_processor.handlers[0][0]))
     self.assertEqual(api.video_processor.handlers[0][1], callback)
Exemplo n.º 33
0
    def test_configure_configures_point_collection_and_calls_back(
            self, mock_Image2Points, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]

        callback = Mock()
        api = ScannerAPI()
        api.configure("bla", callback)

        mock_Image2Points.assert_called_once_with("bla", cam.shape)
        callback.assert_called_with()
Exemplo n.º 34
0
 def test_capture_points_xyz_should_subscribe_with_expected_callback(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.img2points = True
     callback = Mock()
     api.capture_points_xyz(.45, call_back=callback)
     self.assertTrue(len(api.video_processor.handlers) > 0)
     self.assertEquals(PointCaptureXYZ,
                       type(api.video_processor.handlers[0][0]))
     self.assertEqual(api.video_processor.handlers[0][1], callback)
Exemplo n.º 35
0
    def test_set_region_of_interest_from_abs_points_should_create_expected_roi(
            self, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]
        api = ScannerAPI()
        expected_roi = ROI.set_from_abs_points((0, 0), (151, 90),
                                               [100, 300, 3])

        api.set_region_of_interest_from_abs_points((0, 0), (151, 90),
                                                   [300, 100])

        self.assertROIEquals(expected_roi, api.roi)
Exemplo n.º 36
0
    def test_get_scanner_posisitions_get_list_of_configured_laser_posisitions(self, mock_Image2Points, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]

        callback = Mock()
        api = ScannerAPI()
        mock_hardware = Mock()
        mock_hardware.intersections_rad_mm = [(1, "bla"), (2, "bla")]
        expected = [1, 2]

        api.configure(mock_hardware, callback)
        results = api.get_scanner_posisitions()

        self.assertEquals(expected, results)
Exemplo n.º 37
0
    def test_get_scanner_posisitions_get_list_of_configured_laser_posisitions(
            self, mock_Image2Points, mock_camera):
        cam = mock_camera.return_value
        cam.shape = [300, 100]

        callback = Mock()
        api = ScannerAPI()
        mock_hardware = Mock()
        mock_hardware.intersections_rad_mm = [(1, "bla"), (2, "bla")]
        expected = [1, 2]

        api.configure(mock_hardware, callback)
        results = api.get_scanner_posisitions()

        self.assertEquals(expected, results)
Exemplo n.º 38
0
 def test_init_should_construct_a_video_processor(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     self.assertTrue(api.video_processor is not None)
     self.assertEquals(api._default_encoder, api.video_processor.encoder)
     self.assertEquals(api._default_roi, api.video_processor.roi)
     self.assertEquals(api._default_laser_detector,
                       api.video_processor.laser_detector)
Exemplo n.º 39
0
 def test_configure_laser_detector_should_replace_the_existing_laser_detector_with_new_laser_detector(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector((0.0, 0.0, 0.0), (0.0, 0.0, 0.5))
     initial = api.laser_detector
     api.configure_laser_detector((0.5, 0.5, 0.5), (1.0, 1.0, 1.0))
     self.assertNotEquals(api.laser_detector, initial)
Exemplo n.º 40
0
 def test_configure_laser_detector2_should_replace_the_existing_laser_detector_with_new_laser_detector(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_laser_detector2(255, 'red')
     initial = api.laser_detector
     api.configure_laser_detector2(225, 'blue')
     self.assertNotEquals(api.laser_detector, initial)
Exemplo n.º 41
0
 def test_configure_encoder_should_replace_the_existing_encoder_with_new_encoder(
         self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     api.configure_encoder((50, 50), 500, 100, 200)
     initial = api.encoder
     api.configure_encoder((51, 51), 500, 100, 200)
     self.assertNotEquals(api.encoder, initial)
Exemplo n.º 42
0
    def test_start_starts_the_camera_first(self, mock_video_processor, mock_camera):
        global start_time_camera
        global start_time_video
        start_time_camera = 0
        start_time_video = 0

        def start_camera():
            global start_time_camera
            start_time_camera = time.time()
            time.sleep(0.01)

        def start_video():
            global start_time_video
            start_time_video = time.time()
            time.sleep(0.01)

        cam = mock_camera.return_value
        cam.shape = [300, 100]
        cam.start.side_effect = start_camera
        video = mock_video_processor.return_value
        video.start.side_effect = start_video
        api = ScannerAPI()
        api.start()
        self.assertTrue(start_time_video > start_time_camera, '{} !> {}'.format(start_time_video, start_time_camera))
Exemplo n.º 43
0
class Goer(object):
    def __init__(self):
        self.api = ScannerAPI()
        self.image = None
        self.api.capture_image(self.callback)

    def callback(self, image):
        self.image = image.image

    def run(self):
        try:
            self.api.start()
            key = 'a'
            while(key != 'q'):
                if self.image is not None:
                    print('running')
                    cv2.imshow('frame', self.image)
                    key = chr(cv2.waitKey(1) & 0xFF)
        finally:
            cv2.destroyAllWindows()
            self.api.stop()
Exemplo n.º 44
0
class Goer(object):
    def __init__(self):
        self.api = ScannerAPI()
        self.image = None
        self.api.capture_image(self.callback)

    def callback(self, image):
        self.image = image.image

    def run(self):
        try:
            self.api.start()
            key = 'a'
            while (key != 'q'):
                if self.image is not None:
                    print('running')
                    cv2.imshow('frame', self.image)
                    key = chr(cv2.waitKey(1) & 0xFF)
        finally:
            cv2.destroyAllWindows()
            self.api.stop()
Exemplo n.º 45
0
    parser.add_argument('-l', '--log',     dest='loglevel', action='store',      required=False, default="WARNING", help="Enter the loglevel [DEBUG|INFO|WARNING|ERROR] default: WARNING")
    parser.add_argument('-t', '--console', dest='console',  action='store_true', required=False, help="Logs to console not file")
    parser.add_argument('-m', '--module', dest='mod',  action='store', required=False, help='Activate a module (use "list" to get a list of available modules).')
    args, unknown = parser.parse_known_args()

    path = os.path.dirname(os.path.realpath(__file__))

    import config

    if not os.path.exists(config.PEACHY_PATH):
        os.makedirs(config.PEACHY_PATH)
    setup_logging(args)

    sys.argv = [sys.argv[0]]
    if args.mod:
        sys.argv.append("-m")
        sys.argv.append(args.mod)

    scanner = ScannerAPI()
    scanner.start()
    try:
        from gui import PeachyScannerApp
        PeachyScannerApp(scanner).run()
    except Exception as ex:
        import traceback
        traceback.print_exc()
    finally:
        print("Shutting Down Api")
        scanner.stop()
        exit()
Exemplo n.º 46
0
 def __init__(self):
     self.api = ScannerAPI()
     self.image = None
     self.api.capture_image(self.callback)
Exemplo n.º 47
0
        required=False,
        help=
        'Activate a module (use "list" to get a list of available modules).')
    args, unknown = parser.parse_known_args()

    path = os.path.dirname(os.path.realpath(__file__))

    import config

    if not os.path.exists(config.PEACHY_PATH):
        os.makedirs(config.PEACHY_PATH)
    setup_logging(args)

    sys.argv = [sys.argv[0]]
    if args.mod:
        sys.argv.append("-m")
        sys.argv.append(args.mod)

    scanner = ScannerAPI()
    scanner.start()
    try:
        from gui import PeachyScannerApp
        PeachyScannerApp(scanner).run()
    except Exception as ex:
        import traceback
        traceback.print_exc()
    finally:
        print("Shutting Down Api")
        scanner.stop()
        exit()
Exemplo n.º 48
0
 def __init__(self):
     self.api = ScannerAPI()
     self.image = None
     self.api.capture_image(self.callback)
Exemplo n.º 49
0
 def test_capture_points_xyz_should_raise_exception_if_img2points_not_configured(self, mock_camera):
     cam = mock_camera.return_value
     cam.shape = [300, 100]
     api = ScannerAPI()
     with self.assertRaises(Exception):
         api.capture_points_xyz()