我需要使用 Streamlink 对从 Twitch 提取的实时流运行 OpenCV-Python 图像识别,而无需将流写入磁盘。我已经对所有图像识别进行了测试并准备就绪(我使用 win32api 屏幕截图进行了测试),并且我还使用 Streamlink 提供的 cli 命令成功地提取了流,但我需要能够分析流一帧一次在 Python 脚本中使用 OpenCV。
我的问题是:我将如何使用 OpenCV 分析 Streamlink 流的每一帧?
我需要使用 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()