基于opencv对图片的二进制流进行编解码

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跳坑攻略,opencv,图像识别,cv,计算机视觉,python)