1

我正在尝试运行一个函数,该函数从各种相机馈送中获取帧并将它们保存到磁盘。

我将三个摄像头连接到我的笔记本电脑 USB 端口,并尝试一次启动所有摄像头并尝试对那些捕获的图像/帧执行一些操作。为简单起见,我只是将它们保存到磁盘。这是下面的代码:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from multiprocessing import Process

import cv2
#from scipy.stats import math
import datetime
count = 0
def saving_frame(frame):
    count = 0
    date_string = datetime.datetime.now().strftime("%Y-%m-%d-%H:%M")
    count = count +1 
    cv2.imwrite('Frame_'+str(count)+date_string+'.png',frame)
    return

def runInParallel(*fns):
      proc = []
      for fn in fns:
        p = Process(target=fn)
        p.start()
        proc.append(p)
      for p in proc:
        p.join()


video_capture_1 = cv2.VideoCapture(0)

video_capture_2 = cv2.VideoCapture(1)

video_capture_3 = cv2.VideoCapture(2)

print ('Start Rec')

while True:
    ret_1, frame_1 = video_capture_1.read()
    ret_2, frame_2 = video_capture_2.read()
    ret_3, frame_3 = video_capture_3.read()

    runInParallel(saving_frame(frame_1),saving_frame(frame_2),saving_frame(frame_3))

    cv2.imshow('frame1', frame_1)
    cv2.imshow('frame2', frame_2)
    cv2.imshow('frame3', frame_3)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
video_capture_1.release()
video_capture_2.release()
video_capture_3.release()

cv2.destroyAllWindows()

但是,上面的代码没有保存任何帧。你能帮我解决这个问题吗?

4

0 回答 0