Aar*_*ron 12 python youtube video opencv
这个链接有一个很简单的例子,说明如何使用python的OpenCV库,cv2将数据从摄像头传输到你的python shell.我希望做一些实验,并想用以下YouTube视频输入:https://www.youtube.com/watch?v=oCUqsPLvYBQ.
我尝试过如下调整示例:
import numpy as np
import cv2
cap = cv2.VideoCapture('https://www.youtube.com/watch?v=oCUqsPLvYBQ')
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Run Code Online (Sandbox Code Playgroud)
哪会产生错误:
WARNING: Couldn't read movie file https://www.youtube.com/watch?v=oCUqsPLvYBQ
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /tmp/opencv20160107-29960-t5glvv/opencv-2.4.12/modules/highgui/src/window.cpp, line 261
Run Code Online (Sandbox Code Playgroud)
是否有一个简单的修复程序,允许我通过这个视频源流到我的python shell cv2?cv2如果有其他库可以达到同样的目的,也不是绝对致力于.
Vai*_*v K 12
你需要安装2件东西
安装这两个软件包后,您可以使用youtube网址播放流媒体视频.请参考下面的代码
url = 'https://youtu.be/W1yKqFZ34y4'
vPafy = pafy.new(url)
play = vPafy.getbest(preftype="webm")
#start the video
cap = cv2.VideoCapture(play.url)
while (True):
ret,frame = cap.read()
"""
your code here
"""
cv2.imshow('frame',frame)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11720 次 |
| 最近记录: |