How to pass the address of the buffer to Image.frombuffer()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to pass the address of the buffer to Image.frombuffer()

Веселин
I want to display captured frames from a webcam. I am using
video4linux2, v4l2 bindings for python and ctypes.

I am also using Tk. In the main loop of my v4l2 app, after Q_BUF,
STREAM_ON, DQ_BUF I call method that looks something like that:


window = Tkinter.Tk()
image = ImageTk.PhotoImage(pixelfmt, (320, 240))
label = Tkinter.Label(window, image=image)
label.pack()

im = Image.frombuffer(pixelfmt, (320, 240),
ctypes.string_at(buf.userptr, buf.length), 'raw', pixelfmt, 0, 1)

image.paste(im)
window.update()


Now, how is buf.userptr supposed to look like? A ctypes.c_void_p?
In my case buf.userptr is long. Something like 170692608.

I don't know how addresses in python should look like.
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: How to pass the address of the buffer to Image.frombuffer()

Fredrik Lundh
2010/1/26 Веселин <[hidden email]>:

> I want to display captured frames from a webcam. I am using
> video4linux2, v4l2 bindings for python and ctypes.
>
> I am also using Tk. In the main loop of my v4l2 app, after Q_BUF,
> STREAM_ON, DQ_BUF I call method that looks something like that:
>
>
> window = Tkinter.Tk()
> image = ImageTk.PhotoImage(pixelfmt, (320, 240))
> label = Tkinter.Label(window, image=image)
> label.pack()
>
> im = Image.frombuffer(pixelfmt, (320, 240),
> ctypes.string_at(buf.userptr, buf.length), 'raw', pixelfmt, 0, 1)
>
> image.paste(im)
> window.update()
>
> Now, how is buf.userptr supposed to look like? A ctypes.c_void_p?
> In my case buf.userptr is long. Something like 170692608.
>
> I don't know how addresses in python should look like.

Did you figure this out?  I think this is more of a ctypes question
than a PIL question, so you might want to repost this to a more
general Python forum, such as python-list at python.org (but feel free
to follow up here with the solution if you have it).

Cheers /F
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig