无符号 char* 图像到 Python
我能够使用 SWIG 为相机库生成 python 绑定,并且能够使用该库的内置函数捕获和保存图像。 我正在尝试将相机中的数据获取为Python图像库格式,该库提供了以 unsigned char* 形式返回相机数据的函数。 有谁知道如何将 unsigned char* 图像数据转换为我可以在 Python 中使用的某种数据格式? 基本上我正在尝试将 unsigned char* 图像数据转换为 Python 图像库格式。
谢谢。
I was able to generate python bindings for a camera library using SWIG and I am able to capture and save image using the library's inbuilt functions.
I am trying to obtain data from the camera into Python Image Library format, the library provides functions to return camera data as unsigned char* .
Does anyone know how to convert unsigned char* image data into some data format that I can use in Python?
Basically am trying to convert unsigned char* image data to Python Image Library format.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信您应该使用
fromstring
方法,如下所述:如何使用 PIL 读取原始图像?
另外,还有一篇关于使用 python 和 opencv 从相机捕获数据的好文章,值得一读:http://www.jperla.com/blog/post/capturing-frames-from-a- Linux 上的网络摄像头
I believe you should use the
fromstring
method, as described here:How to read a raw image using PIL?
Also, there's a good article on capturing data from the camera using python and opencv which is worth reading: http://www.jperla.com/blog/post/capturing-frames-from-a-webcam-on-linux
好吧,伙计们,经过长时间的斗争(也许是因为我是 python 新手),我终于解决了它。
我编写了一个 python 可以理解的数据结构,并将 unsigned char* 图像转换为该结构。在编写了自定义数据结构的接口后,我能够将图像转换为Python图像库图像格式。
我想将代码粘贴到此处,但它不允许超过 500 个字符。
这是我的代码的链接
http://www.optionsbender.com/technologybending/python/unsignedcharimagedatatopilimage< /a>
我还附上了文件,以便您可以使用它。
Okay Guys, so finally after a long fight (maybe because am a newbie in python), I solved it.
I wrote a data structure that could be understood by python and converted the unsigned char* image to that structure. After writing the interface for the custom data structure, I was able to get the image into Python Image Library image format.
I wanted to paste the code here but it wont allow more tha 500 chars.
Here's a link to my code
http://www.optionsbender.com/technologybending/python/unsignedcharimagedatatopilimage
I've also attached files so that you can use it.
我假设这些
unsigned char
是实际的图像字节,因此您可以直接通过以下方式存储它们:(只要您在当前文件中已经有一个名为
filename
的文件工作目录。)I'd assume those
unsigned char
s are the actual image bytes, so you could store those directly via:(As long as you already have a file named
filename
in the current working directory.)