#!/usr/bin/env python # -*- coding: utf-8 -*- import requests from io import BytesIO import cv2 import numpy as np from PIL import Image from fake_useragent import UserAgent def imread_from_url(url, seek_index=0, debug=False): image = None # URLから画像を取得 ua = UserAgent() header = {'User-Agent': str(ua.chrome)} response = requests.get(url, headers=header) # PILでURLの画像を読み込み try: image = Image.open(BytesIO(response.content)) except Exception as e: print(e) return None if debug: print(image) print(image.size) print(dir(image)) # アニメーションGIF等の複数枚ある画像はシーク if 'n_frames' in dir(image): if debug: print('n_frames', image.n_frames) print('seek_index', seek_index) if 0 <= seek_index < image.n_frames: image.seek(seek_index) elif seek_index < 0: print(
从指定 URL 读取图像并以 OpenCV 格式返回的函数(从指定 URL 读取图像并使其可由 OpenCV 处理。)
最新推荐文章于 2024-06-26 23:28:21 发布