将numpy数组另存为jpg格式的io.BytesIO [英] saving a numpy array as a io.BytesIO with jpg format

查看:258
本文介绍了将numpy数组另存为jpg格式的io.BytesIO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我在opencv处理后有了图像数据(numpy数组).我想将此图像数据插入到excel中.但是xlswriter仅支持io.BytesIO流.

Now, I had image data(numpy array) after opencv process. I would like insert this image data to excel. But xlswriter only support io.BytesIO stream.

问题:我不知道如何将numpy数组转换为 io .bytesIO (具有jpg格式).

question: I don't know how to convert numpy array to io.BytesIO with jpg format.

我尝试使用numpy.tostring但没有jpg格式.

I have trying numpy.tostring but without jpg format.

下面的代码运行良好: _f = open('test.jpg') # I would like to insert test.jpg worksheet.insert_image('E2', 'abc.jpg', {'image_data': _f.read()})

the code working well in below: _f = open('test.jpg') # I would like to insert test.jpg worksheet.insert_image('E2', 'abc.jpg', {'image_data': _f.read()})

有人可以帮助我吗?非常感谢.

Anybody can help me ? thank you so much.

推荐答案

使用 cv2.imencode 函数将numpy数组转换为jpg格式.

Use the cv2.imencode function to convert a numpy array to jpg format.

这篇关于将numpy数组另存为jpg格式的io.BytesIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆