img_tools.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:visualize-tsne 作者: YontiLevin 项目源码 文件源码
def url_to_img_array(url):
    if not isinstance(url, basestring):
        logging.warning("input is neither an ndarray nor a string, so I don't know what to do")
        return None

    # replace_https_with_http:
    if 'http' in url and 'https' not in url:
        url = url.replace("https", "http")
    try:
        headers = {'User-Agent': USER_AGENT}
        response = requests.get(url, headers=headers)
        img_array = cv2.imdecode(np.asarray(bytearray(response.content)), 1)
    except requests.ConnectionError:
        logging.warning("connection error - check url or connection")
        return None
    except:
        logging.warning(" error other than connection error - check something other than connection")
        return None

    return img_array
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号