capture.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:Monitoring 作者: Skydes 项目源码 文件源码
def run(self):
        self._stop.clear()
        with self._conf_lock:
            conf = self._conf.copy() # Create thread-safe local copy

        sleep(float(conf["capture-warmup"])) # Camera warm-up wait

        while True :
            if self._stop.is_set():
                break
            if self._new_conf.is_set():
                with self._conf_lock:
                    conf = self._conf.copy()
                self._new_conf.clear()
                logging.debug("New configuration set: {conf}".format(conf=conf))

            if conf["capture"]:
                if self._stream is None:
                    if self.tryOpenStream() is FAIL:
                        continue
                try:
                    select.select((self._stream,), (), ())
                    raw = self._stream.read_and_queue()
                except IOError as err_first:
                    self._stream.close()
                    self.tryOpenStream()
                    continue

                if raw is None:
                    logging.warning("Grabbed frame is empty.")

                while True:
                    try:
                        self._out_queue.put(cv2.imdecode(np.fromstring(raw, dtype=np.byte), flags=cv2.IMREAD_COLOR), block=False)
                    except Full:
                        self._out_queue.get()
                    else:
                        break
            else:
                sleep(1) # Reduce CPU consumption

        if self._stream is not None:
            self._stream.close()
        logging.info("Thread stopped.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号