【问题标题】:IP Camera Python 3 ErrorIP 摄像机 Python 3 错误
【发布时间】:2015-12-29 16:28:00
【问题描述】:

我正在使用 Python 3 获取 IP 网络摄像头的流并将其显示在我的计算机上。以下代码仅适用于 python 2.7

import cv2
import urllib 
import numpy as np

stream=urllib.urlopen('http://192.168.0.90/mjpg/video.mjpg')
bytes=''
while True:
    bytes+=stream.read(16384)
    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:]
        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.IMREAD_COLOR)
        cv2.imshow('i',i)
        if cv2.waitKey(1) ==27:
            exit(0)

但是,当我在 Python 3 上尝试时,出现以下错误

stream=urllib.urlopen('http://192.168.0.90/mjpg/video.mjpg') AttributeError: 'module' 对象没有属性 'urlopen'

有什么解决办法吗?我尝试制作自己的缓冲区,但没有太多关于这些东西的信息

【问题讨论】:

标签: python python-2.7 opencv python-3.x ip-camera


【解决方案1】:

对于 python3 你需要import urllib.request:

import urllib.request

stream = urllib.request.urlopen('http://192.168.0.90/mjpg/video.mjpg')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 2014-03-10
    • 2017-02-24
    • 2013-03-13
    • 1970-01-01
    • 2022-10-01
    相关资源
    最近更新 更多