-
-
Save treeherder/2888d80c1a85e4587950 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python import cv2 | |
import numpy as np | |
import cv2 | |
import multiprocessing as mp | |
class Eye(object): | |
def __init__(self, n): | |
self.n = n | |
self.cap = cv2.VideoCapture(self.n) | |
def cam_eye(self): | |
ret, frame = self.cap.read() | |
cv2.imshow("{0} camera {1}".format(mp.current_process.name, self.n),frame) | |
def close(self): | |
self.cap.release() | |
def worker(q): | |
obj = q.get() | |
obj.cam_eye() | |
if __name__ == '__main__': | |
queue = mp.Queue() | |
p = mp.Process(target=worker, args=(queue,)) | |
p.start() | |
queue.put(Eye(0)) | |
# Wait for the worker to finish | |
queue.close() | |
queue.join_thread() | |
p.join() | |
#!/usr/bin/env python import cv2 | |
import numpy as np | |
import cv2 | |
class Eye(): | |
def __init__(self, n): | |
self.n = n | |
self.cap = cv2.VideoCapture(self.n) | |
def cam_eye(self): | |
ret, frame = self.cap.read() | |
cv2.imshow("{0}".format(self.n),frame) | |
def close(self): | |
self.cap.release() | |
if __name__ == "__main__": | |
left =Eye(0) | |
right=Eye(1) | |
while(True): | |
left.cam_eye() | |
right.cam_eye() | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
left.close() | |
right.close() | |
Traceback (most recent call last):
File "/usr/lib/python3.5/multiprocessing/queues.py", line 241, in _feed
obj = ForkingPickler.dumps(obj)
File "/usr/lib/python3.5/multiprocessing/reduction.py", line 50, in dumps
cls(buf, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'cv2.VideoCapture'>: it's not the same object as cv2.VideoCapture
^X^@^CTraceback (most recent call last):
File "m.py", line 34, in
Process Process-1:
p.join()
File "/usr/lib/python3.5/multiprocessing/process.py", line 121, in join
res = self._popen.wait(timeout)
File "/usr/lib/python3.5/multiprocessing/popen_fork.py", line 51, in wait
return self.poll(os.WNOHANG if timeout == 0.0 else 0)
File "/usr/lib/python3.5/multiprocessing/popen_fork.py", line 29, in poll
pid, sts = os.waitpid(self.pid, flag)
KeyboardInterrupt
progress so far on multiprocsessing: http://paste.click/IiVVhs