[英]cv2.VideoCapture(url) livestream not working 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.