python opencv 读取url路径的图片

import cv2
import numpy as np
import urllib.request


def fetchImageFromHttp(image_url, timeout_s=1):
    try:
        if image_url:
            resp = urllib.request.urlopen(image_url, timeout=timeout_s)
            image = np.asarray(bytearray(resp.read()), dtype="uint8")
            image = cv2.imdecode(image, cv2.IMREAD_COLOR)
            return image
        else:
            return []
    except Exception as error:
        print('获取图片失败', error)
        return []


img = fetchImageFromHttp('http://i5.qhimg.com/t019c3e49c9c9319c33.jpg')
cv2.imshow('img', img)
cv2.waitKey()

参考文章链接:Opencv之通过url抓取图片并通过opencv可视化_ancy_i_cv的博客-CSDN博客_opencv读取url图片 

你可能感兴趣的:(python,opencv,计算机视觉)