3

我尝试使用 MPI scatter 将 cv2 Video Capture 源发送到不同的进程。这样,每个进程都会有一个句柄来检索帧。

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

4

1 回答 1

2

cv2.VideoCapture不是所有向量的列表。相反,它是指向视频中某个帧的句柄。这样,将这样的对象分散到一堆其他进程是没有意义的。相反,我建议在每个进程中打开一个句柄,然后让每个进程从不同的帧开始:

source.set(cv.CV_CAP_PROP_POS_FRAMES, start_frame)
于 2013-11-18T16:57:33.620 回答