【问题标题】:cv2.VideoCapture(url) livestream not working Ubuntucv2.VideoCapture(url) 直播不工作 Ubuntu
【发布时间】:2019-12-05 21:01:22
【问题描述】:
预期结果:
我想在直播中进行对象检测。
我的代码:
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'
我能做什么?我什么都试过了
【问题讨论】:
标签:
python
opencv
tensorflow
object-detection
video-capture
【解决方案1】:
根据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)