【python】 np转base64, base64转np

def numpy_to_base64(image_np):
    data = cv2.imencode('.jpg', image_np)[1]
    image_bytes = data.tobytes()
    image_base4 = base64.b64encode(image_bytes).decode('utf8')
    return image_base4

def base64_to_numpy(img_bs64):
	img_bs64 = base64.b64decode(img_bs64)
    img_array = np.frombuffer(img_bs64, np.uint8)
    cv2_img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)
    return cv2_img

你可能感兴趣的:(python,python)