[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Realtime Ruby/Tk image display?

Tom Nakamura

4/29/2005 7:16:00 PM

Here's what I'm trying to do:

I have a matrox frame grabber, from which I can grab a 640x480x24bit
image from, 30 times per second.

I want to make a gui where I can grab a frame, do some simple
calculations, add a rectangle or two, and blit it on to a canvas, in
real time (30 times per second).

The grabbing part, I think I can do with the ruby-v4l; I want to know
how I can update a canvas with this relatively large image at 30 times
per second. I'm trying to use Tk's photo class, but I think since it was
designed for static images, it can't reach that level of performance.

ideas strongly appreciated,
Tom N


2 Answers

Ilmari Heikkinen

4/29/2005 10:16:00 PM

0

pe, 2005-04-29 kello 22:16, Tom Nakamura kirjoitti:
> Here's what I'm trying to do:
>
> I have a matrox frame grabber, from which I can grab a 640x480x24bit
> image from, 30 times per second.
>
> I want to make a gui where I can grab a frame, do some simple
> calculations, add a rectangle or two, and blit it on to a canvas, in
> real time (30 times per second).
>
> The grabbing part, I think I can do with the ruby-v4l; I want to know
> how I can update a canvas with this relatively large image at 30 times
> per second. I'm trying to use Tk's photo class, but I think since it was
> designed for static images, it can't reach that level of performance.
>
> ideas strongly appreciated,
> Tom N
>

OpenGL should do pretty well here I think.
Set up the texture, then use glTexSubImage2D to update it with the video
frames.

Something like this (may contain bugs):

# set up ortho projection and window here...

GL::Enable(GL::TEXTURE_2D)
tex = GL::GenTextures(1).first
GL::BindTexture(GL::TEXTURE_2D, tex)
GL::TexImage2D(TEXTURE_2D, 0, GL::RGBA,
1024, 1024, 0,
GL::RGB, GL::UNSIGNED_BYTE, "\000"*(3*1024**2))

# whether to use RGB or BGR or BGRA or whatever depends on your
# OpenGL's native pixel format

w = 640.0/1024
h = 480.0/1024
loop{
pixels = get_frame_from_grabber_as_rgb
GL::TexSubImage2D(TEXTURE_2D, 0,
0, 0, 640, 480,
GL::RGB, GL::UNSIGNED_BYTE, pixels)
GL::Begin(GL::QUADS)
# Note the y-flip:
# GL uses an y-axis that points up but
# video usually uses an y-axis that points down
GL::TexCoord(0, 0); GL::Vertex(0, 480, 0)
GL::TexCoord(w, 0); GL::Vertex(640, 480, 0)
GL::TexCoord(w, h); GL::Vertex(640, 0, 0)
GL::TexCoord(0, h); GL::Vertex(0, 0, 0)
GL::End()
GL::SwapBuffers()
}

I'm getting around 100fps flipping between two 512x512 RGB images and
30fps flipping between two 1024x1024 RGB images on my GFFX5700.

Cheers,
Ilmari





Hidetoshi NAGAI

5/1/2005 2:05:00 PM

0