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.
Page Index Toggle Pages: 1
different v3ga edges (Read 1479 times)
different v3ga edges
May 1st, 2005, 10:21pm
 
I've been asked to help create a code project that responds to a timelapse video of a building being constructed at my university. I showed my project team-mates my simple difference code and v3ga's edge detection code. They reckoned a combination of the two would be good.

So I've just quickly stitched the two together and modified v3ga's code for the new API as a start.

http://www.robotacid.com/misc/timetest.mov  (4mb, a bit  choppy owing to cheap cature software)

http://www.robotacid.com/misc/difference3.pde

If anyone could offer some constructive criticism I'd be glad to hear it. There's at least six weeks of timelapse photography to go yet.

For v3ga; just do this to your code for P85:
Code:

//find and replace BImage with PImage, plus:

// copyToImg()
// ------------------
void copyRenderTargetToImg(PImage imgToCopy)
{
System.arraycopy(imgToCopy.pixels, 0, img.pixels,0, imgToCopy.width*imgToCopy.height);
img.updatePixels();//Add this line
}


My problem is that I'm going to be working from a quicktime movie as opposed to web-cam. My initial tries with the movie object were exceedingly choppy and horrible. I'm going to need to export the frames to re-assemble a new movie. I'll want to step through the movie frame by frame and save the code-image-response for each frame.

The movie object doesn't seem to have a step by step, frame by frame method. Is there a trick I can employ to achieve this? It would make me feel a little more secure about rendering the new version of the movie frame by frame.

Update:
Bear with me, I'll post a piece of code illustrating that last question. I'll be likely for a more succinct answer. Any suggestions on the project would be welcome though.
Re: different v3ga edges
Reply #1 - May 2nd, 2005, 5:39am
 
Hypothetically, if you know the framerate of your video, you can simply use the jump() method to go to the desired frame.

You might want to use something like the following (obvious hack):

Code:
float framerate = 29.97; // (for example)
float frameDuration = 1/framerate;

//...
myCapture.jump(framecount++ * frameDuration);
//...


Does that look anything like what you'd want? Perhaps a stepForward and stepBack method are in order?
Re: different v3ga edges
Reply #2 - May 2nd, 2005, 8:19pm
 
Thanks very much. The logic seems fairly foolproof, even though Processing gets uppity about big .movs it should slow the operation down enough for it to catch up. I'll give it a try.
Re: different v3ga edges
Reply #3 - May 7th, 2005, 4:31pm
 
I've got the idea working to a degree. A frame advance only code works fine with just my code:

Code:

import processing.video.*;
Movie myMovie;
float frameDuration = 1.0/24;
float playhead = 0.0;
boolean newFrame = false;
PImage swap,display;

void setup() {
size(320, 240);
swap = loadImage("a.gif"); //blank .gif the size of video
display = loadImage("a.gif");
myMovie = new Movie(this, "test.mov");
//myMovie.framerate(2);
myMovie.loop();
println(myMovie.duration());
}

void draw(){
if (newFrame){
difference();
swap.copy(myMovie,0,0,myMovie.width,myMovie.height,0,0,swap.width,swap.height);
image(display, 0, 0);
newFrame = false;
myMovie.pause();
}
}

void movieEvent(Movie myMovie) {
myMovie.read();
newFrame = true;
}
void difference(){
for (int iy = 0; iy < myMovie.height; iy++){
for (int ix = 0; ix < myMovie.width; ix++){
color c1 = myMovie.pixels[ix + iy * swap.width];
color c2 = swap.pixels[ix + iy * swap.width];
int r1=c1>>16&0xff;
int g1=c1>>8&0xff;
int b1=c1&0xff;
int r2=c2>>16&0xff;
int g2=c2>>8&0xff;
int b2=c2&0xff;
display.pixels[ix + iy * display.width] = color (255-abs(r1-r2),255-abs(g1-g2),255-abs(b1-b2));
}
}
display.updatePixels();
}
void keyPressed(){
switch(key){
case 'm':
case 'M':
myMovie.play();
playhead = (playhead+frameDuration)%myMovie.duration();
myMovie.jump(playhead);
println(playhead);
break;
}
}

But when I tack v3ga's edge detection code on the end, some of the frames come out blank.

http://www.robotacid.com/PBeta/edgeMov2.pde

Does anyone know why?
Page Index Toggle Pages: 1