网络编程
位置:首页>> 网络编程>> Python编程>> Python 实现opencv所使用的图片格式与 base64 转换

Python 实现opencv所使用的图片格式与 base64 转换

作者:Andy Wang  发布时间:2021-02-28 11:59:09 

标签:Python,opencv,图片格式,base64

将np图片(imread后的图片)转码为base64格式


def image_to_base64(image_np):

image = cv2.imencode('.jpg',image_np)[1]
image_code = str(base64.b64encode(image))[2:-1]

return image_code

将base64编码解析成opencv可用图片


def base64_to_image(base64_code):

# base64解码
img_data = base64.b64decode(base64_code)
# 转换为np数组
img_array = np.fromstring(img_data, np.uint8)
# 转换成opencv可用格式
img = cv2.imdecode(img_array, cv2.COLOR_RGB2BGR)

return img

来源:https://blog.csdn.net/qq_24502469/article/details/82495252

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com