python-3.x - 在 Streamlink 直播流上使用 OpenCV-Python?
问题描述
我需要使用 Streamlink 对从 Twitch 提取的实时流运行 OpenCV-Python 图像识别,而无需将流写入磁盘。我已经对所有图像识别进行了测试并准备就绪(我使用 win32api 屏幕截图进行了测试),并且我还使用 Streamlink 提供的 cli 命令成功地提取了流,但我需要能够分析流一帧一次在 Python 脚本中使用 OpenCV。
我的问题是:我将如何使用 OpenCV 分析 Streamlink 流的每一帧?
解决方案
我认为这段代码给了你一个想法。您只需要通过streamlink获取流并通过openCV捕获
def stream_to_url(url, quality='best'):
streams = streamlink.streams(url)
if streams:
return streams[quality].to_url()
else:
raise ValueError("No steams were available")
主要的
def main(url, quality='best', fps=30.0):
stream_url = stream_to_url(url, quality)
cap = cv2.VideoCapture(stream_url)
frame_time = int((1.0 / fps) * 1000.0)
while True:
try:
ret, frame = cap.read()
推荐阅读
- python-3.x - 从多个字典创建多个新列
- vue.js - 单击编辑按钮后如何使禁用的输入可编辑
- android - 尝试将图像从 Android 上传到 AWS Lambda
- string - 是否可以“直接”将短字符串值加载到 GNU-as (ARM) 中的寄存器中?
- azure - 使用 Azure 数据工厂检索 CRM D365 选项集字段数据的问题
- flutter - 可视化任何尺寸的图像而不会出现失真抖动
- latex - 在嵌套 \itemize 环境中的某些幻灯片后更改 \itemize 项目符号点
- deep-linking - 当用户安装应用程序并打开 FireTV 时,Deeplink 无法正常工作
- ios - 如何防止 VoiceOver 自动滚动 UICollectionView?
- reactjs - 如何在先前组件更改后动态呈现新组件?