首页 > 解决方案 > 如何在处理实时 IP 摄像机视频时使用多线程

问题描述

import cv2
import numpy as np
from multiprocessing import Process

dark = np.full((720,1280,3),255,dtype = np.uint8)

cap = cv2.VideoCapture('IPCameraVideoLinkHere')

def compute_image(frame,dark):
    dark = np.where(frame<dark,frame,dark)
    dark = np.where(dark<254,dark+1,255)
    return dark

while(True):

    ret, frame = cap.read()
    dark = compute_image(frame,dark)
    cv2.imshow('frame',dark)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

这是我的代码。我想在 compute_image 中添加 10 倍以上的功能。目前,它使用了我 12% 的 CPU。我希望它使用所有它,所有核心。

但是我还想以序列中的正常帧实时显示视频。在这种情况下如何应用多线程?我想以 25 FPS 处理视频

标签: pythonopencv

解决方案


推荐阅读