Пример #1
0
    def testCreate(self):
        cfg = {'name': 'Test', 'type': 'TestSubsystem'}
        cfg = core.ConfigNode.fromString(str(cfg))
        deps = core.SubsystemList()

        cam1 = vision.Camera(640, 480)
        cam2 = vision.Camera(640, 480)
        visionSystem = vision.VisionSystem(cam1, cam2, cfg, deps)
Пример #2
0
        def testBuoyDetector(self):
            # Create a vision system with two mock cameras and an EventHub

            cfg = {
                'testing': 1,
                'BuoyDetector': {
                    'filtRedLMin': 0,
                    'filtRedLMax': 255,
                    'filtRedCMin': 0,
                    'filtRedCMax': 255,
                    'filtRedHMin': 230,
                    'filtRedHMax': 20
                }
            }
            cfg = core.ConfigNode.fromString(str(cfg))

            forwardCamera = vision.Camera(640, 480)
            backwardCamera = vision.Camera(640, 480)

            eventHub = core.EventHub()
            deps = core.SubsystemList()
            deps.append(eventHub)
            visionSystem = vision.VisionSystem(forwardCamera, backwardCamera,
                                               cfg, deps)

            # Subscribe to our events about the red light
            eventHub.subscribeToType(vision.EventType.BUOY_FOUND,
                                     self.buoyFoundHandler)
            eventHub.subscribeToType(vision.EventType.BUOY_LOST,
                                     self.buoyLostHandler)

            # Load our test image (really upper right)
            image = vision.Image.loadFromFile(
                os.path.join(getConfigRoot(), 'red_light_upper_left.png'))

            # Start detector then unbackground it
            visionSystem.buoyDetectorOn()
            visionSystem.unbackground(True)

            forwardCamera.capturedImage(image)
            forwardCamera.background(0)

            # This stops the background thread
            visionSystem.update(0)
            visionSystem.buoyDetectorOff()

            # Check the event
            self.assert_(self.found)
            self.assert_(self.event)
Пример #3
0
    def __init__(self, config, deps_):
        # Initialize super class with fake cameras
        cfg = core.ConfigNode.fromString(str(config))
        deps = core.SubsystemList()
        for d in deps_:
            deps.append(d)

        cam1 = vision.Camera(640, 480)
        cam2 = vision.Camera(640, 480)
        vision.VisionSystem.__init__(self, cam1, cam2, cfg, deps)

        self._currentTime = 0
        self._sendEvents = False
        if 1 == config.get('sendEvents', 1):
            self._sendEvents = True
Пример #4
0
        def testRedLightDetector(self):
            # Create a vision system with two mock cameras and an EventHub
            cfg = {'testing': 1}
            cfg = core.ConfigNode.fromString(str(cfg))

            forwardCamera = vision.Camera(640, 480)
            backwardCamera = vision.Camera(640, 480)

            eventHub = core.EventHub()
            deps = core.SubsystemList()
            deps.append(eventHub)
            visionSystem = vision.VisionSystem(forwardCamera, backwardCamera,
                                               cfg, deps)

            # Subscribe to our events about the red light
            eventHub.subscribeToType(vision.EventType.LIGHT_FOUND,
                                     self.redFoundHandler)
            eventHub.subscribeToType(vision.EventType.LIGHT_LOST,
                                     self.redLostHandler)

            # Load our test image (really upper right)
            image = vision.Image.loadFromFile(
                os.path.join(getConfigRoot(), 'red_light_upper_left.png'))

            # Start detector then unbackground it
            visionSystem.redLightDetectorOn()
            visionSystem.unbackground(True)

            forwardCamera.capturedImage(image)
            forwardCamera.background(0)

            # This stops the background thread
            visionSystem.update(0)
            visionSystem.redLightDetectorOff()

            # Check the event
            self.assert_(self.found)
            self.assert_(self.event)
            self.assertAlmostEqual(0.5 * 4.0 / 3.0, self.event.x, 2)
            self.assertAlmostEqual(0.5, self.event.y, 2)
            self.assertAlmostEqual(3, self.event.range, 1)
            self.assertAlmostEqual(-78.0 / 4,
                                   self.event.azimuth.valueDegrees(), 2)
            self.assertAlmostEqual(105.0 / 4,
                                   self.event.elevation.valueDegrees(), 0)