from io import BytesIO
import cv2
import matplotlib.pyplot as plt
import requests
import numpy as np
from PIL import Image
re = requests.request('GET', "https:/29036669.jpg")
print(re.content)
# filename = '1.png'
# with open(filename, 'wb') as fp:
# fp.write(re.content)
# fp.close()
# cv2.
response_byte = re.content
# 用Image的方法读取
# bytes_stream = BytesIO(response_byte)
# img = Image.open(bytes_stream)
img = cv2.imdecode(np.frombuffer(re.content, np.uint8), cv2.IMREAD_COLOR)
print(img)
plt.imshow(img)
plt.show()
cv2与Image读取字节流中的图片
于 2021-10-08 11:38:18 首次发布