Realtime Ruby/Tk image display?

T

Tom Nakamura

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
 
I

Ilmari Heikkinen

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
 
H

Hidetoshi NAGAI

From: "Tom Nakamura" <[email protected]>
Subject: Realtime Ruby/Tk image display?
Date: Sat, 30 Apr 2005 04:16:28 +0900
Message-ID: said:
ideas strongly appreciated,

If you have a video library which can be embedded into the
window specified by its window id, "container" option of
Toplevel or Frame widget maybe useful.

# A few years ago, I tried and succeeded to run a Ruby/SDL's
# base window in a Ruby/Tk's frame widget.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,473
Latest member
pioneertraining

Latest Threads

Top