Quantcast
Channel: Python multiprocess can't pickle opencv videocapture object - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Python multiprocess can't pickle opencv videocapture object

$
0
0

I am trying to create a independent process to handle my image acquire from camera. But multiprocessing seems to have difficulty pickling videocapture module from opencv. Can anyone suggest a work around ? I am using python 3.7.1

from multiprocessing import Processimport multiprocessing as mpimport timeimport loggingimport logging.handlersimport sysimport loggingfrom enum import Enumimport cv2class 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())) 

The return error specific said it videocapture object can't be pickled.

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj)

TypeError: can't pickle cv2.VideoCapture objects


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>