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.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › Combining slit-scanning with motiontracking.
Page Index Toggle Pages: 1
Combining slit-scanning with motiontracking. (Read 550 times)
Combining slit-scanning with motiontracking.
May 12th, 2010, 8:21am
 
Hi, basically i am new to this, and am doing a study into capturing movement in unusual ways, looking to implement an installation at my degree show in june. I basically want to combine these two codes, or know if it's even possible i have tried, but to no avail. Any help/advice would be greatly appriciated.



Motion tracking source code:

import processing.video.*;

/*
* @author andrewwright
* andrew@snepo.com
*/

int W = 640;
int H = 480;

color pColor;
Capture cam;

int res = 2;
int thresh = 20;

color[] buffer;

void setup()
{
 size ( W, H );
 background(0);
 
 buffer = new color[W * H];
 cam = new Capture(this, W, H);
 
}

void captureEvent(Capture cam)
{
 cam.read();
}

void draw()
{
 sampleAndPaint();
 swapBuffer();
}

void sampleAndPaint()
{
 fill(0, 10);
 rect(0, 0, W, H);
 for ( int i = 0; i < W; i+= res )
 {
   for ( int j = 0; j < H; j+=res )
   {
     int offset = i + j * W;
     color c = cam.pixels[offset];
     color r = buffer[offset];
     
     float cB = brightness(c);
     float rB = brightness(r);
     
     float delta = abs ( cB - rB );
     
     if ( delta > thresh )
     {
       fill ( 0, 255, 0 );
       noStroke();
       rect ( i, j, res, res );
     }
   }
 }
}
     
void swapBuffer()
{
 arrayCopy(cam.pixels, buffer);
}



Slit-Scanning code:

import processing.video.*;
MovieMaker movie;

boolean rec;
int n;
int varZero;
int prevN;
int prevZero;
int numPixels;
int prevPixels;
int[] prevLines;
Capture video;

void setup(){
 size(320, 240);
 frameRate = 30;
 video = new Capture(this, width, height, 72);
 numPixels = video.width * video.height;
 //Sets the number of pixels to be stored using
 //an algebric progression formula related
 //to the number of lines to be stored.
 prevPixels = ((numPixels*(height+1))/2);
 //Sets the array to store these pixels.
 prevLines = new int[prevPixels];
 movie = new MovieMaker(this, width, height, "rybczynski.mov",
 72, MovieMaker.ANIMATION, MovieMaker.LOSSLESS);
 //Sets the movie recording function off by default.
 rec=false;
 loadPixels();
 noStroke();
}


void draw(){
 if (video.available()){
   video.read();
   video.loadPixels();
   //For each line of the image:
   for (int y=1; y<height; y++){
     //Declares the value of 'n', which will be used to index
     //to which of the "lines" stored for line 'y' shall the software
     //access to store current frame's line 'y'.
     n=(frameCount%y);
     //Indexes to the begining of the "line" in which to store
     //the current frame's line 'y' using an algebric progression
     //formula based on 'y' var and the indexing gave by 'n' var.
     varZero= round((n*width)+(((sq(y)+y)*width)/2));
     //Declares the value of 'prevN'. This var will
     //index to stored "line" the software shall
     //read to display at current frame's line 'y'.
     prevN=((frameCount-(y-1))%y);
     //Indexes to the begining of the "line" that the software
     //shall read to display currently at line 'y'. Uses the
     //same process of varZero expression, but with other vars.
     prevZero=round((prevN*width) +(((sq(y)+y)*width)/2));
     //For each pixel in line 'y':
     for (int i=1; i<width; i++){
       //Declares a 'ind' var based on 'y' and 'i'
       //to index the displayed pixels.
       int ind=((y*width)+i);
       //Stores each pixel of line 'y' of current frame
       //captured from real-time video.
       prevLines[varZero+i]= video.pixels[ind];
       //Reads and displays the proper line of pixels from
       //the data stored.
       pixels[ind]=prevLines[prevZero+i];
     }
   }
   updatePixels();
   if (rec==true){
     movie.addFrame();
   }
 }
}

void keyPressed (){
 //If SPACE key is pressed and recording is off, turn it on.
 if (key==' ' && rec==false){
   rec=true;
   println("REC");
 }
 //If SPACE key is pressed and recording is on, turn it off.
 else if (key==' ' && rec==true){
   rec=false;
   println("PAUSE");
 }
 //If ESCAPE key is pressed, finish movie.
 else if (key==ESC){
   movie.finish();
   println("STOP");
 }
}
Page Index Toggle Pages: 1