python ndarray 与 base64 互转 post接口传递ndarry

1.ndarray转base64
print(ndarray.dtype)
retval,img_buffer = cv2.imencode('.jpg', ndarray)
img_str = base64.b64encode(img_buffer)
requests.post("http://127.0.0.1:8879/infer", {"image": img_str})
2.base64转ndarray
image = request.form.get("image")
img_str = base64.b64decode(image)
image_np = np.fromstring(img_str, dtype=np.uint8)
image_np = cv2.imdecode(image_np, cv2.IMREAD_COLOR)
Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐