import cv2
import numpy as np
img1 = cv2.imread("img.jpg", 1)
#retval, buffer = cv2.imencode('.png', img1)
# img1_bytes = np.array(buffer).tostring()
with open("img.jpg", "rb") as fid:
img1_bytes = fid.read()
# Decoding CV2
decoded = cv2.imdecode(np.frombuffer(img1_bytes, np.uint8), 1)
cv2.imwrite("cv2.png", decoded)
基于opencv对图片的二进制流进行编解码
于 2020-09-07 15:41:34 首次发布
本文介绍如何利用Python中的OpenCV库读取图片文件,并将其编码为字节流,再从字节流中解码回图片的过程。通过使用numpy和OpenCV的imdecode与imencode函数,可以实现图片的高效编码与解码。

1388

被折叠的 条评论
为什么被折叠?



