python - 如何在处理实时 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 处理视频
解决方案
推荐阅读
- php - 带有 file_get_contents('php://input') 的 laravel 回调 url
- java - 更改每个循环中的数组值不起作用java
- sql - 通过多个/结束列值状态获取表格行
- python - 将输出多一维数组存储为数据文件
- here-api - Batch Geocoder API,如何获取额外的道路属性
- c# - 锁定以追加到 ASP.NET 中的文件
- asp.net - 无法从 Nuget 包管理器在 Asp.net MVC 4.5 版本中添加包 Microsoft.Owin.Host.SystemWeb
- symfony - 如何从第三个捆绑包中覆盖第三个捆绑包的配置
- django - 使用虚幻数据自动填充 Django 模型数据库表
- css - 渲染错误还是我的错误?:从 Flexbox 伸出的溢出隐藏零高度