cv2.VideoCapture(url)实时流无法在Ubuntu上运行

问题描述 投票:0回答:1

预期结果:

我想在直播中进行对象检测。

我的代码:


    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个回答
0
投票

根据Opencv cap.open(),打开视频文件或捕获设备或IP视频流以进行视频捕获。我希望下面的代码可以使用numpy和请求库解决问题。

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)
© www.soinside.com 2019 - 2024. All rights reserved.