如何使用多线程处理实时IP摄像机视频

2024-04-26 03:48:38 发布

您现在位置:Python中文网/ 问答频道 /正文

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()

这是我的密码。我想增加10倍以上的功能在计算机图像。目前,它占用了我12%的CPU。我要它使用所有的核心

但我也希望以正常帧的顺序实时显示视频。在这种情况下如何应用多线程?我想以每秒25帧的速度处理视频


Tags: fromimageimportnumpy视频asnpwhere