Python多进程可以拾取OpenCV视频捕获对象

编程入门 行业动态 更新时间:2024-10-10 02:20:36
本文介绍了Python多进程可以拾取OpenCV视频捕获对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试创建一个独立的进程来处理从相机获取的图像。但多处理器似乎很难从OpenCV中提取视频捕获模块。有没有人能推荐一种解决办法?我使用的是python3.7.1

from multiprocessing import Process import multiprocessing as mp import time import logging import logging.handlers import sys import logging from enum import Enum import cv2 class Logger(): @property def logger(self): component = "{}.{}".format(type(self).__module__, type(self).__name__) #default log handler to dump output to console return logging.getLogger(component) class MyProcess(Logger): def __init__(self, ): self.process = Process(target = self.run, args=()) self.exit = mp.Event() self.logger.info("initialize class") self.capture = cv2.VideoCapture(0) def run(self): while not self.exit.is_set(): pass print("You exited!") def shutdown(self): print("Shutdown initiated") self.exit.set() if __name__ == "__main__": p = MyProcess() p.process.start() print( "Waiting for a while") time.sleep(3) p.shutdown() time.sleep(3) print("Child process state: {}".format(p.process.is_alive()))

返回错误说明无法对视频捕获对象进行酸洗。

文件"C:Program Files(X86)Microsoft Visual StudioSharedAnaconda3_64lib多处理Education tion.py",第60行,转储中 ForkingPickler(文件,协议).转储(Obj)

TypeError:无法Pickle cv2。视频捕获对象

推荐答案

我不是专家,但我遇到了同样的问题,我以这种方式解决了问题。

在init函数中不使用cv2.VideoCapture(0)

def __init__(self, ): self.process = Process(target = self.run, args=()) self.exit = mp.Event() self.logger.info("initialize class") self.capture = cv2.VideoCapture(0)

我移动了初始化以运行函数

def run(self): self.capture = cv2.VideoCapture(0) while not self.exit.is_set():

它对我很管用。 也许它对你也有帮助

更多推荐

Python多进程可以拾取OpenCV视频捕获对象

本文发布于:2023-06-06 00:04:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/529894.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   对象   视频   Python   OpenCV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!