我尝试使用MPI分散将cv2视频捕获源发送到不同的进程。这样,每个进程都有一个句柄来检索帧。
if rank == 0:
video_source = cv2.VideoCapture('my_video.avi')
source_list = [video_source] * world_communicator.Get_size()
else:
source_list = None
data = world_communicator.scatter(source_list, root=0)
# Do stuff with access to the video source...
但是,此代码出现以下错误。
[dfaux@ubiquitous mpi_practice]$ mpirun -n 2 python cv2_video_practice.py
Traceback (most recent call last):
File "cv2_video_practice.py", line 93, in <module>
process_video(source, destination, kernel)
File "cv2_video_practice.py", line 58, in process_video
data = comm.scatter(frame_counts, root=0)
File "Comm.pyx", line 874, in mpi4py.MPI.Comm.scatter (src/mpi4py.MPI.c:68023)
File "pickled.pxi", line 656, in mpi4py.MPI.PyMPI_scatter (src/mpi4py.MPI.c:32402)
File "pickled.pxi", line 131, in mpi4py.MPI._p_Pickle.dumpv (src/mpi4py.MPI.c:26847)
File "pickled.pxi", line 81, in mpi4py.MPI._p_Pickle.dump (src/mpi4py.MPI.c:26188)
cPickle.PicklingError: Can't pickle <type 'cv2.VideoCapture'>: it's not the same object as cv2.VideoCapture
为什么我不能腌制视频源?为什么<type 'cv2.VideoCapture'>
与cv2.VideoCapture
不是同一个对象?
答案 0 :(得分:2)
cv2.VideoCapture
不是所有向量的列表。相反,它是一个指向视频中某个帧的句柄。这样,将这样的对象分散到一堆其他进程是没有意义的。相反,我建议在每个进程中打开一个句柄,然后让每个进程从不同的框架开始:
source.set(cv.CV_CAP_PROP_POS_FRAMES, start_frame)