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)
Exemple #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))
 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)
 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)
 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)
Exemple #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()
 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)
    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()
Exemple #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)
 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)
Exemple #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)
 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()
Exemple #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)
 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'))
Exemple #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)
 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)
 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)
 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)
Exemple #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()
 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)
    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)
 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)
Exemple #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)
Exemple #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()
    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)
 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)
Exemple #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'))
    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()
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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()
Exemple #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)
Exemple #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)
    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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
    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))
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()
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()
Exemple #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()
 def __init__(self):
     self.api = ScannerAPI()
     self.image = None
     self.api.capture_image(self.callback)
Exemple #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()
 def __init__(self):
     self.api = ScannerAPI()
     self.image = None
     self.api.capture_image(self.callback)
 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()