예제 #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 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)