我设法解决了。感谢@Matt和@Yamaneko。基本上,我将读取图像的块移到了worker函数中。因此,如果 池大小= 6,
并且有六个边界框,则每个帧将被读取六次(在每个工作程序中)。那是我发现使其工作的唯一方法。
当前版本可以在这里找到。
import cv2 as cvimport multiprocessing as mpimport timedef worker(folder_path, list_name, top_left, bot_right, index): frame_path = folder_path + '/' + list_name[0] image_0 = cv.imread(frame_path) gray_0 = cv.cvtColor(image_0, cv.COLOR_BGR2GRAY) cmt = VARtracker.CMT() cmt.initialise(gray_0, top_left, bot_right) box_queue = mp.Queue() for name in list_name: frame_path = folder_path + '/' + name image_now = cv.imread(frame_path) gray_now = cv.cvtColor(image_now, cv.COLOR_BGR2GRAY) cmt.process_frame(gray_now) if cmt.has_result: print index, name, zip(cmt.tl, cmt.br) output.put((index, name, zip(cmt.tl, cmt.br))) print 'Process {} finished'.format(index)def VARmethod(folder_path, final_frame, top_left, bot_right): tic = time.time() if len(top_left) == len(bot_right): list_frame = [index for index in range(1, final_frame + 1)] list_name = [str(index) + '.jpg' for index in list_frame] pool = mp.Pool(5) for index in range(0, len(top_left)): pool.apply_async(worker, args=(folder_path, list_name, top_left[index], bot_right[index], index)) pool.close() pool.join() print 'Finished with the script' toc = time.time() print output.qsize() print (toc - tic)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)