easiest way to zoom on a camera image?

I’m pulling in a camera image in the style of movieGrabberExample and I want to (simulate) a zoom in and out of the image. I had thought I could do it just by altering the origin and width/height values I put in ofVideoGrabber.draw(), e.g.:

void testApp::draw() {

vidGrabber.draw(originX,originY,screenW,screenH);

}

and then update the values of originX/Y and screenW/H as necessary. This does mean that origin values will go negative (in order to keep image centered) and the W/H values will be larger than the original sometimes.

In other words, I’m trying to scale the image just by drawing it larger and shifting its origin.

However, I started getting strange behavior, including an ERROR: SampleCB().

What’s the easiest way to do this? I’m coming from Processing and this is my first oF proj. I’m guessing I need to, on each frame:

-copy a frame from the camera,
-scale it to the size I need
-draw it centered on the screen

but I don’t know how to do that.

thanks!

your idea of modifying the parameters in draw() should work, maybe your pushing in weird values?

another way would be using opengl like this:

  
  
int w = img.width;  
int h = img.height;  
float zoom = mouseX; //or whatever zoom value you need  
glPushMatrix();  
glTranslatef(ofGetWidth()/2,ofGetHeight()/2,0);  
glScalef(zoom,zoom,0);  
img.draw(-w/2,-h/2);  
glPopMatrix();  
  

1 Like