开发者

unsigned char* image to 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 fun开发者_运维技巧ctions. 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.


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


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.


I'd assume those unsigned chars are the actual image bytes, so you could store those directly via:

with open('filename', mode='wb') as file:
    file.write(image_bytes)

(As long as you already have a file named filename in the current working directory.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜