コード例 #1
0
    def open(self, src, fps=DEFAULT_FPS, only_validate=False):
        logging.info("Opening video source: {}".format(src))
        if self._reader.isOpened():
            logging.error("Source is already opened")
            raise RuntimeError("Stream is already opened")

        error_message = "Can't open video stream {}".format(src)
        if not self._reader.open(src):
            raise ConnectionBrokenError(error_message)

        if only_validate:
            return

        success, image = self._reader.read()
        if not success:
            raise ConnectionBrokenError(error_message)
        height, width, _ = image.shape
        self._video_info["frame_size"] = (width, height)

        self._stop_event.clear()
        capture_interval = 1000.0 / fps

        logging.info("Starting reader thread")
        self._thread = StreamReaderThread(self._reader,
                                          self._queue,
                                          self._stop_event,
                                          capture_interval,
                                          _is_livestream(src))
        self._thread.daemon = True
        self._thread.start()
コード例 #2
0
ファイル: gpu_worker.py プロジェクト: uniray7/jagereye_ng
def init_worker(model_dir):
    worker = get_worker()
    if hasattr(worker, "name") and worker.name.startswith("GPU_WORKER"):
        logging.info("Initializing GPU worker: {}".format(worker.name))
        model_path = ModelPath(model_dir)

        from jagereye_ng import models
        worker.global_models = dict()
        worker.global_models["object_detection"] = models.ObjectDetection(
            model_path.get("object_detection",
                           "ssd_mobilenet_v1_coco_11_06_2017"),
            "ssd_mobilenet_v1_coco_11_06_2017")
        worker.global_models["object_detection"].load()
    return "OK"
コード例 #3
0
 def run(self):
     try:
         while not self._stop_event.is_set():
             success, image = self._reader.read()
             if not success:
                 if self._is_livestream:
                     raise ConnectionBrokenError()
                 else:
                     raise EndOfVideoError()
             timestamp = time.time()
             self._queue.appendleft(VideoFrame(image, timestamp))
             time.sleep(self._cap_interval)
         logging.info("Reader thread is terminated")
     except Exception as e:
         logging.error(str(e))
         self._exception = e
コード例 #4
0
 def run(self):
     try:
         while True:
             if self._queue.empty():
                 if self._stop_event.is_set():
                     break
                 else:
                     time.sleep(0.01)
                     continue
             frame = self._queue.get()
             self._writer.write(frame.image)
             self._queue.task_done()
         logging.info("Writer thread is terminated")
     except Exception as e:
         logging.error(str(e))
         self._exception = e
コード例 #5
0
    def open(self, filename, fps, size):
        if self._writer.isOpened():
            raise RuntimeError("Stream is already opened")

        gst_pipeline = ('appsrc ! autovideoconvert ! x264enc ! matroskamux !'
                        ' filesink location={}'.format(filename))
        if not self._writer.open(gst_pipeline, 0, fps, size):
            raise RuntimeError("Can't open video file {}"
                               .format(filename))

        self._stop_event.clear()

        logging.info("Starting writer thread")
        self._thread = StreamWriterThread(self._writer,
                                          self._queue,
                                          self._stop_event)
        self._thread.daemon = True
        self._thread.start()
コード例 #6
0
 async def _setup(self, ch_name, nats_hosts):
     options = {
         "servers": nats_hosts,
         "io_loop": self._io_loop,
         "max_reconnect_attempts": 60,
         "reconnect_time_wait": 2,
         "disconnected_cb": self._disconnected_cb,
         "reconnected_cb": self._reconnected_cb,
         "error_cb": self._error_cb,
         "closed_cb": self._closed_cb
     }
     try:
         await self._nats.connect(**options)
         logging.info("NATS connection for APIConnector '{}' is "
                      "established.".format(self.__class__.__name__))
     except ErrNoServers as e:
         logging.error(e)
         raise
     else:
         await self._nats.subscribe("api.{}".format(ch_name),
                                    cb=self._api_handler)
コード例 #7
0
 async def _closed_cb(self):
     logging.info("[NATS] connection is closed")
コード例 #8
0
 async def _reconnected_cb(self):
     logging.info("[NATS] reconnecting to {}".format(
         self._nats.connected_url.netloc))
コード例 #9
0
 async def _disconnected_cb(self):
     logging.info("[NATS] disconnected")