Пример #1
0
    def process_and_publish(self):
        # TODO add check timestamps for dropped frames
        H, W, _ = self.data[0]['rgb'].shape
        n = len(self.data)
        dtype = [
            ('timestamp', 'float'),
            ('rgb', 'uint8', (H, W, 3)),
        ]
        images = np.zeros((n, ), dtype=dtype)
        for i, v in enumerate(self.data):
            images[i]['timestamp'] = v['timestamp']
            images[i]['rgb'][:] = v['rgb']

        det = LEDDetector(False, False, False, self.pub_debug)
        rgb0 = self.data[0]['rgb']
        #mask = np.ones(dtype='bool', shape=rgb0.shape)
        tic = time.time()
        result = det.detect_led(images, self.frequencies, self.cell_size,
                                self.crop_rect_normalized)
        self.pub_detections.publish(result)

        toc = time.time() - tic
        tac = time.time() - self.tinit
        rospy.loginfo('[%s] Detection done. Processing Time: %.2f' %
                      (self.node_name, toc))
        print('[%s] Total Time taken: %.2f' % (self.node_name, tac))

        if (self.continuous):
            self.trigger = True
            self.sub_cam = rospy.Subscriber("camera_node/image/compressed",
                                            CompressedImage,
                                            self.camera_callback)
Пример #2
0
    def process_and_publish(self):
        # TODO add check timestamps for dropped frames
        H, W, _ = self.data[0]['rgb'].shape
        n = len(self.data)
        dtype = [
            ('timestamp', 'float'),
            ('rgb', 'uint8', (H, W, 3)),
        ]
        images = np.zeros((n,), dtype=dtype)
        for i, v in enumerate(self.data):
            images[i]['timestamp'] = v['timestamp']
            images[i]['rgb'][:] = v['rgb']
        
        det = LEDDetector(False, False, False, self.pub_debug)
        rgb0 = self.data[0]['rgb']
        #mask = np.ones(dtype='bool', shape=rgb0.shape)
        tic = time.time()
        result = det.detect_led(images, self.frequencies, self.cell_size, self.crop_rect_normalized)
        self.pub_detections.publish(result)

        toc = time.time()-tic
        tac = time.time()-self.tinit
        rospy.loginfo('[%s] Detection done. Processing Time: %.2f'%(self.node_name, toc))
        print('[%s] Total Time taken: %.2f'%(self.node_name, tac))

        if(self.continuous):
            self.trigger = True
            self.sub_cam = rospy.Subscriber("camera_node/image/compressed",CompressedImage, self.camera_callback)
Пример #3
0
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = 'I need two arguments. Please see README.md for documentation.'
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    package_dir = get_ros_package_path('led_detection')
    logger.debug('Package dir: %r' % package_dir)

    # dirname = 'catkin_ws/src/f23-LED/led_detection/scripts/'
    #filename = 'all_tests.yaml'
    filename = os.path.join(package_dir, 'scripts', 'dp45_tests.yaml')

    alltests = load_tests(filename)
    estimators = {
        'baseline':
        LEDDetector(ploteverything=False, verbose=True, plotfinal=False),
        'LEDDetector_plots':
        LEDDetector(True, True, True)
    }
    #,'LEDDetector_forloops' : LEDDetector_forloops(True, True, True)}

    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' %
                (which_estimators0, which_estimators))

    # which tests to execute
    test_results = {}
    for id_test in which_tests:
        for id_estimator in which_estimators:
            result = run_test(id_test, alltests[id_test], id_estimator,
                              estimators[id_estimator])
            test_results[(id_test, id_estimator)] = result

    nfailed = list(test_results.values()).count(False)
    if not nfailed:
        logger.info('All tests passed')
    else:
        which = [k for k, v in test_results.items() if not v]
        logger.error('These tests failed: %s ' % which)
        sys.exit(3)
Пример #4
0
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = "I need two arguments. Please see README.md for documentation."
        dtu.logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    package_dir = get_ros_package_path("led_detection")
    dtu.logger.debug(f"Package dir: {package_dir!r}")

    # dirname = 'catkin_ws/src/f23-LED/led_detection/scripts/'
    # filename = 'all_tests.yaml'
    filename = os.path.join(package_dir, "scripts", "dp45_tests.yaml")

    alltests = load_tests(filename)
    estimators = {
        "baseline":
        LEDDetector(ploteverything=False, verbose=True, plotfinal=False),
        "LEDDetector_plots":
        LEDDetector(True, True, True),
    }
    # ,'LEDDetector_forloops' : LEDDetector_forloops(True, True, True)}

    which_tests = dtu.expand_string(which_tests0, list(alltests))
    which_estimators = dtu.expand_string(which_estimators0, list(estimators))

    logger.info(f"     tests: {which_tests0!r} |-> {which_tests}")
    logger.info(f"estimators: {which_estimators0!r} |-> {which_estimators}")

    # which tests to execute
    test_results = {}
    for id_test in which_tests:
        for id_estimator in which_estimators:
            result = run_test(id_test, alltests[id_test], id_estimator,
                              estimators[id_estimator])
            test_results[(id_test, id_estimator)] = result

    nfailed = list(test_results.values()).count(False)
    if not nfailed:
        logger.info("All tests passed")
    else:
        which = [k for k, v in list(test_results.items()) if not v]
        logger.error(f"These tests failed: {which} ")
        sys.exit(3)
Пример #5
0
 def process_and_publish(self):
     # TODO add check timestamps for dropped frames
     H, W, _ = self.data[0]['rgb'].shape
     n = len(self.data)
     dtype = [
         ('timestamp', 'float'),
         ('rgb', 'uint8', (H, W, 3)),
     ]
     images = np.zeros((n,), dtype=dtype)
     for i, v in enumerate(self.data):
         images[i]['timestamp'] = v['timestamp']
         images[i]['rgb'][:] = v['rgb']
     
     det = LEDDetector(False, False, False, self.pub_debug)
     rgb0 = self.data[0]['rgb']
     mask = np.ones(dtype='bool', shape=rgb0.shape)
     tic = time.time()
     result = det.detect_led(images, mask, [2.8, 4.1, 5.0], 5)
     self.pub_detections.publish(result)
     toc = time.time()-tic
     tac = time.time()-self.tinit
     print('Done. Processing Time: %.2f'%toc)
     print('Total Time taken: %.2f'%tac)
Пример #6
0
    def process_and_publish(self):
        # TODO add check timestamps for dropped frames
        H, W, _ = self.data[0]['rgb'].shape
        n = len(self.data)
        dtype = [
            ('timestamp', 'float'),
            ('rgb', 'uint8', (H, W, 3)),
        ]
        images = np.zeros((n, ), dtype=dtype)
        for i, v in enumerate(self.data):
            images[i]['timestamp'] = v['timestamp']
            images[i]['rgb'][:] = v['rgb']

        det = LEDDetector(False, False, False, self.pub_debug)
        rgb0 = self.data[0]['rgb']
        mask = np.ones(dtype='bool', shape=rgb0.shape)
        tic = time.time()
        result = det.detect_led(images, mask, [2.8, 4.1, 5.0], 5)
        self.pub_detections.publish(result)
        toc = time.time() - tic
        tac = time.time() - self.tinit
        print('Done. Processing Time: %.2f' % toc)
        print('Total Time taken: %.2f' % tac)
Пример #7
0
def main():
    script_name = os.path.basename(sys.argv[0])
    args = sys.argv[1:]
    if len(args) != 2:
        msg = """
Usage:

    rosrun led_detection <script> <tests> <algorithms>

where:

    <tests> = comma separated list of algorithms. May use "*".
    <algorithms> = comma separated list of algorithms. May use  "*".

For example, this runs all tests on all algorithms:


    rosrun led_detection <script> '*' '*'

The default algorithm is called "baseline", and the tests are invoked using:

    rosrun led_detection <script> '*' 'baseline'

"""

        msg = msg.replace('<script>', script_name)
        logger.error(msg)
        sys.exit(2)

    which_tests0 = sys.argv[1]
    which_estimators0 = sys.argv[2]

    root = os.environ['DUCKIETOWN_ROOT']
    dirname = 'catkin_ws/src/f23-LED/led_detection/scripts/'
    #filename = 'all_tests.yaml'
    filename = 'dp45_tests.yaml'
    filename = os.path.join(root, dirname, filename)

    alltests = load_tests(filename)
    estimators = {
        'baseline':
        LEDDetector(ploteverything=False, verbose=True, plotfinal=False),
        'LEDDetector_plots':
        LEDDetector(True, True, True)
    }
    #,'LEDDetector_forloops' : LEDDetector_forloops(True, True, True)}

    which_tests = expand_string(which_tests0, list(alltests))
    which_estimators = expand_string(which_estimators0, list(estimators))

    logger.info('     tests: %r |-> %s' % (which_tests0, which_tests))
    logger.info('estimators: %r |-> %s' %
                (which_estimators0, which_estimators))

    # which tests to execute
    test_results = {}
    for id_test in which_tests:
        for id_estimator in which_estimators:
            result = run_test(id_test, alltests[id_test], id_estimator,
                              estimators[id_estimator])
            test_results[(id_test, id_estimator)] = result

    nfailed = list(test_results.values()).count(False)
    if not nfailed:
        logger.info('All tests passed')
    else:
        which = [k for k, v in test_results.items() if not v]
        logger.error('These tests failed: %s ' % which)
        sys.exit(3)