opencv图像存储内存
np不支持存储内存,需转字节流进行存储,因此需要将np转base64以及bytes进行存储图像np格式转base64:```pythondef image_to_base64(image_np):image = cv2.imencode('.jpg',image_np)[1].tostring()image_code = base64.b64encode(image)return image_co
·
np不支持存储内存,需转字节流进行存储,因此需要将np转base64以及bytes进行存储
图像np格式转base64:
```python
def image_to_base64(image_np):
image = cv2.imencode('.jpg',image_np)[1].tostring()
image_code = base64.b64encode(image)
return image_code
图像np格式转bytes:
def numpy_to_bytes(image_np):
data = cv2.imencode('.jpg', image_np)[1]
image_bytes = data.tobytes()
return image_bytes
同一张图片bytes长度小于base64:
ok 0
img_b64 <class 'bytes'>
426684
img_byt <class 'bytes'>
320011
-------------------------------
ok 1
img_b64 <class 'bytes'>
427368
img_byt <class 'bytes'>
320525
更多推荐
已为社区贡献1条内容
所有评论(0)