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,
OpenGL should do pretty well here I think.
Set up the texture, then use glTexSubImage2D to update it with the video
Something like this (may contain bugs):
# set up ortho projection and window here...
tex = GL::GenTextures(1).first
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
pixels = get_frame_from_grabber_as_rgb
0, 0, 640, 480,
GL::RGB, GL::UNSIGNED_BYTE, pixels)
# 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)
I'm getting around 100fps flipping between two 512x512 RGB images and
30fps flipping between two 1024x1024 RGB images on my GFFX5700.