Exemplo n.º 1
0
def main():
    """ 
    Parses arguments; initialises logger; initialises camera driver if
    necessary; loads single image from disk if necessary; and runs desired parts
    of pipeline, or loads output from previous execution for printout.
    
    """

    options, args = argparse.run()
    loginit.run(options.verbosity)
    logger = logging.getLogger('main')

    logger.info(' '.join(sys.argv[1:]))

    if options.simulate == 0:
        options.simulate = None
        l = DC1394Library()
    elif options.simulate > 0:
        options.simulate -= 1
    elif options.simtime is None:
        options.simtime = 36000

    global pipeline
    pipeline = Pipeline(options)

    if options.disk:
        logger.info('using poses from disk')
        pipe = Pipeline()
        pipe.options = options
        printer = Printer(pipe=pipe)
        printer.final()
        logger.info('done. exiting')
        sys.exit(0)

    if args:
        try:
            image = cv2.imread('images/' + args[0],
                               cv2.CV_LOAD_IMAGE_GRAYSCALE)
            pipeline.set_image(image)
            logger.info('opening image file %s from disk' % args[0])
        except IOError:
            logger.error('image file not found: %s' % args[0])
            exit(1)
    elif options.simulate is not None:
        logger.info('running in simulation mode')
    else:
        try:
            fwcam = handle_common_options(options, l)
            pipeline.set_fwcam(fwcam)
            logger.info('init. pydc1394 camera object')
            logger.info('camera: %s' % fwcam.model)
            logger.info('mode: %s' % fwcam.mode)
            logger.info('framerate: %d' % fwcam.framerate.val)
        except:
            logger.error('unable to open camera capture')
            exit(1)

    pipeline.run()
Exemplo n.º 2
0
def main():
    """ 
    Parses arguments; initialises logger; initialises camera driver if
    necessary; loads single image from disk if necessary; and runs desired parts
    of pipeline, or loads output from previous execution for printout.
    
    """

    options, args = argparse.run()
    loginit.run(options.verbosity)
    logger = logging.getLogger('main')

    logger.info(' '.join(sys.argv[1:]))

    if options.simulate == 0:
        options.simulate = None
        l = DC1394Library()
    elif options.simulate > 0:
        options.simulate -= 1
    elif options.simtime is None:
        options.simtime = 36000

    global pipeline
    pipeline = Pipeline(options)

    if options.disk:
        logger.info('using poses from disk')
        pipe = Pipeline()
        pipe.options = options
        printer = Printer(pipe=pipe)
        printer.final()
        logger.info('done. exiting')
        sys.exit(0)

    if args:
        try:
            image = cv2.imread('images/'+args[0], cv2.CV_LOAD_IMAGE_GRAYSCALE)
            pipeline.set_image(image)
            logger.info('opening image file %s from disk' % args[0])
        except IOError:
            logger.error('image file not found: %s' % args[0])
            exit(1)
    elif options.simulate is not None:
        logger.info('running in simulation mode')
    else:
        try:
            fwcam = handle_common_options(options, l)
            pipeline.set_fwcam(fwcam)
            logger.info('init. pydc1394 camera object')
            logger.info('camera: %s' % fwcam.model)
            logger.info('mode: %s' % fwcam.mode)
            logger.info('framerate: %d' % fwcam.framerate.val)
        except:
            logger.error('unable to open camera capture')
            exit(1)

    pipeline.run()
Exemplo n.º 3
0
    def shutdown(self):
        """ main exit routine with logging tasks; runs printer if required """

        self.stop()
        if self.already_shutting_down:
            self.logger.error('multiple shutdown attempts')
            sys.exit(0)
        self.already_shutting_down = True
        duration = self.end - self.start
        if self.modules:
            self.logger.info('processed %d images' % self.loops)
            self.logger.info('avg rate: %f fps' % (self.loops / duration))
        else:
            self.logger.info('loops: %d' % self.loops)
            self.logger.info('avg rate: %f loops /sec' %
                             (self.loops / duration))
        avcts = 0.0
        avels = 0.0
        avmels = 0.0
        if self.modules:
            if (len(self.modules) > 0) and self.loops > 0:
                avcts = self.modules[0].nr_conts / self.loops
                self.modules[0].logger.info('avg contours /img: %f' % avcts)
            if (len(self.modules) > 1) and self.loops > 0:
                avels = self.modules[1].nr_ellipses / (self.loops * 1.0)
                avmels = self.modules[1].nr_candidates / (self.loops * 1.0)
                self.modules[1].logger.info('pre-filter ellipses /img: %f' %
                                            avels)
                self.modules[1].logger.info('post-filter ellipses /img: %f' %
                                            avmels)
            if len(self.modules) > 2:
                msg = 'used lopt1 %d times' % self.modules[2].nrlopt1
                self.modules[2].logger.info(msg)
                msg = 'used lopt2 %d times' % self.modules[2].nrlopt2
                self.modules[2].logger.info(msg)
                msg = 'used lopt3 %d times' % self.modules[2].nrlopt3
                self.modules[2].logger.info(msg)
        self.cleanup()
        printer = Printer(pipe=self)
        printer.final(outputs=self.outputs)
        self.logger.info('shutdown completed')
        sys.exit(0)
Exemplo n.º 4
0
    def shutdown(self):
        """ main exit routine with logging tasks; runs printer if required """

        self.stop()
        if self.already_shutting_down:
            self.logger.error('multiple shutdown attempts')
            sys.exit(0)
        self.already_shutting_down = True
        duration = self.end - self.start
        if self.modules:
            self.logger.info('processed %d images' % self.loops)
            self.logger.info('avg rate: %f fps' % (self.loops / duration))
        else:
            self.logger.info('loops: %d' % self.loops)
            self.logger.info('avg rate: %f loops /sec' % (self.loops / duration))
        avcts = 0.0
        avels = 0.0
        avmels = 0.0
        if self.modules:
            if (len(self.modules) > 0) and self.loops > 0:
                avcts = self.modules[0].nr_conts / self.loops
                self.modules[0].logger.info('avg contours /img: %f' % avcts)
            if (len(self.modules) > 1) and self.loops > 0:
                avels = self.modules[1].nr_ellipses / (self.loops * 1.0)
                avmels = self.modules[1].nr_candidates / (self.loops * 1.0)
                self.modules[1].logger.info('pre-filter ellipses /img: %f' % avels)
                self.modules[1].logger.info('post-filter ellipses /img: %f' % avmels)
            if len(self.modules) > 2:
                msg = 'used lopt1 %d times' % self.modules[2].nrlopt1
                self.modules[2].logger.info(msg)
                msg = 'used lopt2 %d times' % self.modules[2].nrlopt2
                self.modules[2].logger.info(msg)
                msg = 'used lopt3 %d times' % self.modules[2].nrlopt3
                self.modules[2].logger.info(msg)
        self.cleanup()
        printer = Printer(pipe = self)
        printer.final(outputs = self.outputs)
        self.logger.info('shutdown completed')
        sys.exit(0)