json、base64编码、图片数组转二进制流

关于Python base64编码 和 json格式的数据处理 url串
参考网址
http://tool.chinaz.com/tools/imgtobase/

def img_tobyte(roi):
# 类型转换 数组转为 图片格式的二进制流  
    img_pil = Image.fromarray(roi)
    img_byte=io.BytesIO()
    img_pil.save(img_byte,format='PNG')
    binary_str2=img_byte.getvalue()
    return binary_str2
    
    
def img_tobyte(roi):
    ret,buf=cv.imencode('.jpg',roi)
    img_bin=Image.fromarray(np.uint8(buf)).tobytes()
    return img_bin

https://zhuanlan.zhihu.com/p/27134323?group_id=857418148977184768
https://www.iteye.com/blog/panyongzheng-1952444

https://www.jb51.net/article/183643.htm

https://www.cnblogs.com/duyupeng/p/13198775.html

https://blog.csdn.net/sunt2018/article/details/95351884


```python
from PIL import Image
img = Image.open("lena.jpg")
print type(img)
img = np.array(img)
print type(img)

<class 'PIL.JpegImagePlugin.JpegImageFile'>
<type 'numpy.ndarray'>
由于PIL也是基于numpy的,因此可以很容易的通过使用numpy中的函数来进行类型的转换。

img_tr = Image.fromarray(tr_img)
print type(img_tr)

<class 'PIL.Image.Image'>


https://www.cnblogs.com/andyniu/p/7574129.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值