python - cv2.VideoCapture(url) 直播不工作 Ubuntu
问题描述
预期结果:
我想在直播中进行对象检测。
我的代码:
import cv2
cap=cv2.VideoCapture()
url='http://192.168.10.1/media/?action=stream'
cap.open(url)
返回错误:
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
我能做些什么?我已经尝试了一切
解决方案
根据Opencv , cap.open () ,打开视频文件或捕获设备或IP视频流进行视频捕获。我希望下面的代码将使用 numpy 和 requests 库解决问题。
import requests
import cv2
import numpy as np
url = ('http://192.168.10.1/media/?action=stream')
stream = requests.get(url, stream=True)
bytes=''
while(True):
bytes+=stream.raw.read(1024)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
if a!=-1 and b!=-1:
jpg = bytes[a:b+2]
bytes= bytes[b+2:]
img = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.IMREAD_COLOR)
cv2.imshow('Live',img)
if cv2.waitKey(1) ==27:
exit(0)
推荐阅读
- unity3d - 按钮单击时的 Unity 动画返回空闲动画
- sql-server - 在 SQL Server 中使用 INNERJOIN 从日期中删除时间戳
- vba - 如何使用命令按钮在文本框中的现有文本中在光标位置插入文本?
- python - 从服务器python向客户端发送连续数据
- r - 如何将变量传递给作为向量的函数?
- java - jvm什么时候加载instanceof操作符的导入类?
- flutter - 程序链接失败 -flutter
- react-native-navigation - 如何用 react-native-navigation v2 中的其他组件替换嵌套堆栈?
- python - 如何检查目录是否是有效的 Postgres 数据库
- ios - 企业分发 ios 应用程序 - 无法连接到服务器