コード例 #1
0
 def __init__(self):
     self.set_logger()
     self.framecount = 0
     self.detector = Detector(Monitor.CASCADE_FILE)
     # FIXME: change default to camera name after adding support of
     # multiple cameras
     self.output_path_template = "./img/default/%Y/%m/%d/"
     self.output_file_template = "%H%M%S_%%s.jpg"
コード例 #2
0
ファイル: project2.py プロジェクト: bashwork/school
def main():
    """ The following is the actual implementation of the project.
    We simply take an image, classify it, and show the results.
    """
    args = build_options()

    # Setup and train our detector
    _start = time.time()
    images = ImageManager(valid="images/faces/faces/", invalid="images/faces/nonfaces/")
    classify = Detector()
    classify.train(images, 20)
    __log.debug("MAIN training run time: %s secs" % (time.time() - _start))

    process_image("images/example.jpg")
コード例 #3
0
def main():
    ''' The following is the actual implementation of the project.
    We simply take an image, classify it, and show the results.
    '''
    args = build_options()

    # Setup and train our detector
    _start = time.time()
    images = ImageManager(valid="images/faces/faces/",
                          invalid="images/faces/nonfaces/")
    classify = Detector()
    classify.train(images, 20)
    __log.debug("MAIN training run time: %s secs" % (time.time() - _start))

    process_image("images/example.jpg")
コード例 #4
0
def main():
    # get configuration of gateway from passed arguments
    parser = argparse.ArgumentParser(description="Atmosphere station")
    parser.add_argument("-e",
                        "--endpoint",
                        required=True,
                        help="Endpoint address")
    parser.add_argument("-t",
                        "--token",
                        required=True,
                        help="Authorization token")
    parser.add_argument("-d", "--daemon", default=False,\
        help="Whether it is daemon service (e.g. headless)")
    args = parser.parse_args()

    # forward stdout to log file when running headless
    if args.daemon:
        StdLogger.register_file()
    else:
        StdLogger.register_console()

    # start sub-services
    _queue = Queue.Queue()
    _services = []
    _services.append(Sender(args.endpoint, args.token, _queue, 3))
    _services.append(Detector(_queue, not args.daemon))

    signal.signal(signal.SIGTERM,
                  lambda signal, frame: _term_handler(_services))

    for service in _services:
        service.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        pass

    _term_handler(_services)
    return 0
コード例 #5
0
class Monitor(DefaultLogger):
    LOOP_SLEEP_SECONDS = 1
    ONE_MINUTE_NOF = 60.0 / LOOP_SLEEP_SECONDS
    CASCADE_FILE = "./haarcascade/haarcascade_frontalface.xml"

    def __init__(self):
        self.set_logger()
        self.framecount = 0
        self.detector = Detector(Monitor.CASCADE_FILE)
        # FIXME: change default to camera name after adding support of
        # multiple cameras
        self.output_path_template = "./img/default/%Y/%m/%d/"
        self.output_file_template = "%H%M%S_%%s.jpg"

    def run(self):
        self.log.info("Starting Monitor.run")
        while True:
            self.framecount += 1
            if self.framecount % Monitor.ONE_MINUTE_NOF == 0:
                self.log.info("Monitor.run: Framecount: %d" % self.framecount)

            self.log.debug("Capturing frame!")
            self.detector.capture()
            objects = self.detector.detect()
            if objects:
                self.log.debug("%d object(s) detected!" % len(objects))
                path = strftime(self.output_path_template)

                try:
                    os.makedirs(path)
                except OSError, e:
                    # Raised when path exists
                    if e.errno == 17:
                        self.log.info("os.mkdirs: Path exists - ignoring!")
                    else:
                        raise e

                filename = strftime(self.output_file_template)
                filename = filename % str(self.framecount)
                self.detector.mark(objects)
                self.detector.save_frame(path + filename)

            sleep(Monitor.LOOP_SLEEP_SECONDS)
コード例 #6
0
ファイル: viseron.py プロジェクト: zineos/viseron
    def __init__(self):
        config = ViseronConfig(CONFIG)

        log_settings(config)
        LOGGER.info("-------------------------------------------")
        LOGGER.info("Initializing...")

        schedule_cleanup(config)

        mqtt_queue = None
        mqtt = None
        if config.mqtt:
            mqtt_queue = Queue(maxsize=100)
            mqtt = MQTT(config)
            mqtt_publisher = Thread(target=mqtt.publisher, args=(mqtt_queue, ))
            mqtt_publisher.daemon = True

        detector_queue = Queue(maxsize=2)
        detector = Detector(config.object_detection)
        detector_thread = Thread(target=detector.object_detection,
                                 args=(detector_queue, ))
        detector_thread.daemon = True
        detector_thread.start()

        post_processors = {}
        for (
                post_processor_type,
                post_processor_config,
        ) in config.post_processors.post_processors.items():
            post_processors[post_processor_type] = PostProcessor(
                config, post_processor_type, post_processor_config, mqtt_queue)

        LOGGER.info("Initializing NVR threads")
        self.setup_threads = []
        self.nvr_threads = []
        for camera in config.cameras:
            setup_thread = Thread(
                target=self.setup_nvr,
                args=(
                    config,
                    camera,
                    detector,
                    detector_queue,
                    post_processors,
                    mqtt_queue,
                ),
            )
            setup_thread.start()
            self.setup_threads.append(setup_thread)
        for thread in self.setup_threads:
            thread.join()

        if mqtt:
            mqtt.connect()
            mqtt_publisher.start()

        for thread in self.nvr_threads:
            thread.start()

        LOGGER.info("Initialization complete")

        def signal_term(*_):
            LOGGER.info("Kill received! Sending kill to threads..")
            for thread in self.nvr_threads:
                thread.stop()
            for thread in self.nvr_threads:
                thread.join()

        # Listen to sigterm
        signal.signal(signal.SIGTERM, signal_term)

        try:
            for thread in self.nvr_threads:
                thread.join()
        except KeyboardInterrupt:
            LOGGER.info("Ctrl-C received! Sending kill to threads..")
            for thread in self.nvr_threads:
                thread.stop()
            for thread in self.nvr_threads:
                thread.join()

        LOGGER.info("Exiting")
コード例 #7
0
def main():
    config = ViseronConfig()

    log_settings(config)
    LOGGER.info("-------------------------------------------")
    LOGGER.info("Initializing...")

    schedule_cleanup(config)

    mqtt_queue = None
    mqtt = None
    if config.mqtt:
        mqtt_queue = Queue(maxsize=100)
        mqtt = MQTT(config)
        mqtt_publisher = Thread(target=mqtt.publisher, args=(mqtt_queue, ))
        mqtt_publisher.daemon = True

    detector_queue = Queue(maxsize=2)
    detector = Detector(config)
    detector_thread = Thread(target=detector.object_detection,
                             args=(detector_queue, ))
    detector_thread.daemon = True
    detector_thread.start()

    LOGGER.info("Initializing NVR threads")
    threads = []
    for camera in config.cameras:
        threads.append(
            FFMPEGNVR(
                ViseronConfig(camera=camera),
                detector,
                detector_queue,
                mqtt_queue=mqtt_queue,
            ))

    if mqtt:
        mqtt.connect()
        mqtt_publisher.start()

    for thread in threads:
        thread.start()

    LOGGER.info("Initialization complete")

    def signal_term(*_):
        LOGGER.info("Kill received! Sending kill to threads..")
        for thread in threads:
            thread.stop()
            thread.join()

    # Listen to sigterm
    signal.signal(signal.SIGTERM, signal_term)

    try:
        threads[0].join()
    except KeyboardInterrupt:
        LOGGER.info("Ctrl-C received! Sending kill to threads..")
        for thread in threads:
            thread.stop()
            thread.join()

    LOGGER.info("Exiting")