Monday, February 17, 2014

High Magnitude FPS Camera Using a WebCam and Parrallel Processing


High speed cameras are ussually very expensive; right around 7,000 dollars. This home-made method costs only $30

Before beginning please note that image files will be dumped into the directory of where the processing sketch is, therefore place it in a folder to avoid overloading you're desktop.
 
import processing.video.*;
float a=-2;
Capture dacam;

void setup() {
  size (320,240);
  dacam= new Capture(this, 320, 240, 30);
  dacam.start();

}
void draw(){

  if(dacam.available()) {
    dacam.read();
  }
  a=a+2;
  image(dacam,0,0);
} 

The above code only captures the video and does not store it. For storage the successive images will be stored 0 through X as .png(Portable Network Graphics) files since these available for screen images in processing. The camera library takes a little while for the camera application to load, 2 frames, so changing the code by setting a to -2 will make all blank files negative and easily deleted. Once implemented, the new code reads:

import processing.video.*;
float a=-2;
Capture dacam;

void setup() {
  size (320,240);
  dacam= new Capture(this, 320, 240, 30);
  dacam.start();

}
void draw(){

  if(dacam.available()) {
    dacam.read();
  }
  a=a+2;
  image(dacam,0,0);
  save(a+".png");

}

 
 Now to complete the setup multiple cameras need to be involved, and adding more computers makes this easier. The reason can be explained through a simple experiment. Say there is a camera with an fps of 60. Now there is an identical camera with 60 fps. Combining the two by slightly offsetting their start times allows you to double you're fps. The more cameras, the more fps, Aiming them at the same region and keeping the close together provides higher fps on a specific region and a simple cropping algorithm crops only that region.



The cameras used had capture rates of 30 fps. To offset them take 1000milliseconds/30fps and offset the code by that which arrives at:
import processing.video.*;
float a=-2;
Capture dacam;

void setup() {
  size (320,240);
  dacam= new Capture(this, 320, 240, 30);
  dacam.start();

}
void draw(){
if (millis()>(1000/30)) {
  if(dacam.available()) {
    dacam.read();
  }
  a=a+2;
  image(dacam,0,0);
  save(a+".png");
}
}



Now the two peices of code for the two different cameras:

import processing.video.*;
float a=-2;
Capture dacam;

void setup() {
  size (320,240);
  dacam= new Capture(this, 320, 240, 30);
  dacam.start();

}
void draw(){
if (millis()>(1/30)) {
  if(dacam.available()) {
    dacam.read();
  }
  a=a+2;
  image(dacam,0,0);
  save(a+".png");
}
} 
 
And:
import processing.video.*;
float a=-2;
Capture dacam;

void setup() {
  size (320,240);
  dacam= new Capture(this, 320, 240, 30);
  dacam.start();

}
void draw(){

  if(dacam.available()) {
    dacam.read();
  }
  a=a+3;
  image(dacam,0,0);
  save(a+".png");
} 
This shows the two folders comparatively. Combining them doubles the frame rate. Sort the folder by file name and the images will be in order.
   


No comments:

Post a Comment