We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › QuadWarp: capture from isight and live warping
Page Index Toggle Pages: 1
QuadWarp: capture from isight and live warping (Read 1027 times)
QuadWarp: capture from isight and live warping
Jan 7th, 2009, 3:52pm
 
Hi. I wanted to be able to capture an image directly into a simple quadrant warper sketch I had made, so I looked up Tjerk Timan's time-image isight sketch and made this.

Here's a youtube preview: http://www.youtube.com/watch?v=nWTMrgV1CZk

Enjoy!

Code:

/* Hi,
This sketch lets you capture and warp an image from your camera!
I hacked the capture part of this out of Tjerk Timan's time-image isight sketch:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Exhibition;action=display;num=1181654099
It worked by default on my built-in macbook cam, but I'm not sure how universal it is.
Drop me a line if you like this / modify it into something cooler
Jack Perkins, jackaperkins@gmail.com [ January/7th/2009 ]
*/

import processing.video.*;
Capture myCapture; // our capture destination variable 'myCapture'
PImage a; // a-d represent the image quadrants that we'll chop myCapture into
PImage b;
PImage c;
PImage d;
float xx=240; //xx and yy specify the current centerpoint of our warp, which will seek to the mouse
float yy=180;
float speed=.1; // speed is our movement % for smoothing the warp centerpoint as it chases the mouse (set to 1 for instant tracking)
int mode=0; // mode specifies whether we are capturing (0) or warping (1), changed by clicking the mouse


void setup(){
size(480,360);
imageMode(CORNERS);
frameRate(60); // because 30 is boring
myCapture = new Capture(this, 480, 360, 25); // I'm not exactly sure...

//defines the four quadrant images as being the four quarters of myCapture
a = myCapture.get(0, 0, myCapture.width/2, myCapture.height/2);
b = myCapture.get(myCapture.width/2, 0, width, myCapture.height/2);
c = myCapture.get(0, myCapture.height/2, myCapture.width/2, myCapture.height);
d = myCapture.get(myCapture.width/2, myCapture.height/2, myCapture.width, myCapture.height);
}


// captureEvent runs everytime a new frame is availible rrom the cam
void captureEvent(Capture myCapture) {
// If a new frame is Availible and we're in mode zero, update our myCapture variable
if (mode==0){
myCapture.read();
}
}


void draw() {

// MODE=0 Aiming with crosshairs, constantly capturing
if (mode==0){

// draw the straight capture of the webcam on the screen
image(myCapture,0,0,width,height);

// draw the crosshairs with randomly black/white lines
stroke(250*random(1));
line(0,height/2,width,height/2);
line(width/2,0,width/2,height);

} else {
// MODE=1 Warping, following the mouse and not re-capturing

//xx and yy are adjusted to move towards the mouse based on a percentage of their current distance
xx=xx+speed*(mouseX-xx);
yy=yy+speed*(mouseY-yy);

// Draw out the four images so that their center corners lie at XX,YY
image(a,0,0,xx,yy);
image(b,xx,0,width,yy);
image(c,0,yy,xx,height+3);
image(d,xx,yy,width,height);
}

}

// If the mouse is pressed...
void mousePressed() {
if (mode==0) {
// ...and we're in mode 0, turn off the cursor, copy the last captured frame and split it into a-d, change to mode 1
noCursor();
a = myCapture.get(0, 0, myCapture.width/2, myCapture.height/2);
b = myCapture.get(myCapture.width/2, 0, width, myCapture.height/2);
c = myCapture.get(0, myCapture.height/2, myCapture.width/2, myCapture.height);
d = myCapture.get(myCapture.width/2, myCapture.height/2, myCapture.width, myCapture.height);
mode=1;
} else {
// ...and we're in mode 1, turn the cursor back on and change to mode 0
cursor();
mode=0;
}
}

Re: QuadWarp: capture from isight and live warping
Reply #1 - Jan 7th, 2009, 9:01pm
 
Hi very cool fx.
I've modified your code to make it realtime.

Code:
import processing.video.*; 
Capture myCapture; // our capture destination variable 'myCapture'
PImage a; // a-d represent the image quadrants that we'll chop myCapture into
PImage b;
PImage c;
PImage d;
float xx=240; //xx and yy specify the current centerpoint of our warp, which will seek to the mouse
float yy=180;
float speed=.1; // speed is our movement % for smoothing the warp centerpoint as it chases the mouse (set to 1 for instant tracking)


void setup(){
 size(480,360);
 imageMode(CORNERS);  
 frameRate(60); // because 30 is boring
 myCapture = new Capture(this, 480, 360, 25); // I'm not exactly sure...
 
 //defines the four quadrant images as being the four quarters of myCapture
 a = myCapture.get(0, 0, myCapture.width/2, myCapture.height/2);  
 b = myCapture.get(myCapture.width/2, 0, width, myCapture.height/2);  
 c = myCapture.get(0, myCapture.height/2, myCapture.width/2, myCapture.height);  
 d = myCapture.get(myCapture.width/2, myCapture.height/2, myCapture.width, myCapture.height);  
}


// captureEvent runs everytime a new frame is availible rrom the cam
void captureEvent(Capture myCapture) {
 myCapture.read();
}


void draw() {
   a = myCapture.get(0, 0, myCapture.width/2, myCapture.height/2);  
   b = myCapture.get(myCapture.width/2, 0, width, myCapture.height/2);  
   c = myCapture.get(0, myCapture.height/2, myCapture.width/2, myCapture.height);  
   d = myCapture.get(myCapture.width/2, myCapture.height/2, myCapture.width, myCapture.height);  

   //xx and yy are adjusted to move towards the mouse based on a percentage of their current distance
   xx=xx+speed*(mouseX-xx);
   yy=yy+speed*(mouseY-yy);
 
   // Draw out the four images so that their center corners lie at XX,YY
   image(a,0,0,xx,yy);
   image(b,xx,0,width,yy);
   image(c,0,yy,xx,height+3);
   image(d,xx,yy,width,height);
}
Re: QuadWarp: capture from isight and live warping
Reply #2 - Jan 10th, 2009, 8:33pm
 
Yeah, I realized I could do that pretty easily too, the only problem is it's hard to keep your face aligned with the center of the warp.

How would I go about finding libraries for real time image warping (closer to photoshop's liquify tool)?
Page Index Toggle Pages: 1