Python OpenCV multiprocessing cv2.VideoCapture mp4



我想在一个过程中运行一些mp4视频,但只有相机馈送有效。软件卡住了,没有错误信息。我已经试过了,我发现这不能运行。打印是代码卡住的地方。

import cv2
import multiprocessing
dispW=640
dispH=480
# Camera inputs 
cap=cv2.VideoCapture('/home/kc/Downloads/darknet/1.mp4')
cap.set(cv2.CAP_PROP_FRAME_WIDTH, dispW)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, dispH)
#cv2.namedWindow("Window")
def c1():
global cap
while True:
print('here')
success, img = cap.read()
#ret, frame1 = cap1.read()
#frame2 = numpy.hstack((frame,frame1))
print('here')
cv2.imshow("Window2", img)
#This breaks on 'q' key
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
tCap1 = multiprocessing.Process(target=c1)
tCap1.start()

运行。

import cv2
import multiprocessing
dispW=640
dispH=480
# Camera inputs 
cap=cv2.VideoCapture('/dev/video0')
cap.set(cv2.CAP_PROP_FRAME_WIDTH, dispW)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, dispH)

#cv2.namedWindow("Window")
def c1():
global cap
while True:
success, img = cap.read()
#ret, frame1 = cap1.read()
#frame2 = numpy.hstack((frame,frame1))
print('here')
cv2.imshow("Window2", img)
#This breaks on 'q' key
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
tCap1 = multiprocessing.Process(target=c1)
tCap1.start()

我需要一个mp4文件以多处理方式运行的例子。

这是一个带有可选FPS控制的最小工作示例。如果你需要从进程中提取帧回主程序,你可以使用multiprocessing.Queue()来传输帧,因为多进程有一个独立的内存堆栈。

import multiprocessing as mp
import cv2, time
def capture_frames():
src = 'test.mp4'
capture = cv2.VideoCapture(src)
capture.set(cv2.CAP_PROP_BUFFERSIZE, 2)
# FPS = 1/X, X = desired FPS
FPS = 1/120
FPS_MS = int(FPS * 1000)
while True:
# Ensure camera is connected
if capture.isOpened():
(status, frame) = capture.read()

# Ensure valid frame
if status:
cv2.imshow('frame', frame)
else:
break
if cv2.waitKey(1) & 0xFF == ord('q'):
break
time.sleep(FPS)
capture.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
print('Starting video stream')
capture_process = mp.Process(target=capture_frames, args=())
capture_process.start()

相关的camera/IP/RTSP/streaming, FPS, video, threading, and multiprocessing posts

  1. Python OpenCV流从相机-多线程,时间戳

  2. 使用OpenCV cv2的Python IP摄像机视频流。VideoCapture

  3. 如何使用OpenCV捕获多个摄像机流?

  4. OpenCV实时流媒体视频捕获缓慢。如何删除帧或与实时同步?

  5. 使用OpenCV VideoWriter将RTSP流存储为视频文件

  6. OpenCV视频保存

  7. Python OpenCV多处理cv2。VideoCapture mp4

相关内容

  • 没有找到相关文章

最新更新