Skip to content

Instantly share code, notes, and snippets.

@soh335
Created December 30, 2009 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soh335/265893 to your computer and use it in GitHub Desktop.
Save soh335/265893 to your computer and use it in GitHub Desktop.
import processing.core.*;
import processing.xml.*;
import processing.video.*;
import java.applet.*;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.event.FocusEvent;
import java.awt.Image;
import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import java.util.zip.*;
import java.util.regex.*;
public class GloveLight extends PApplet {
/****************************************/
/* White Glove Tracking */
/* Video w/ Data Example */
/* whiteglovetracking.com */
/* Started 05.21.2007 */
/* Evan Roth evan@ni9e.com */
/****************************************/
/****************************************/
/* forked by soh kitahara */
/* GloveLight */
/* 12.30.2009 */
/****************************************/
//make vars
frame FM;
frame FMS[];
int comma;
String temp_f, temp_x, temp_y, temp_w, temp_h;
int f, x, y, w, h;
int fnum;
float t, inc;
Movie myMovie;
float count = 1;
public void setup(){
size(320, 240, P2D);
colorMode(RGB, 255, 255, 255, 100);
//load movie
myMovie = new Movie(this, "whiteglove.mov");
myMovie.loop();
//init time vars
t = 0.0f;
inc = 1.0f / 30.0f;
//load in data from text file
//String lines[] = loadStrings("median_degap_smooth.txt");
String lines[] = loadStrings("wgt_data_v1.txt");
println("there are " + lines.length + " lines");
//make room for all objs
FMS = new frame[lines.length];
//loop through text file, save data into frame objects
for (int i=0; i < lines.length; i++) {
//intit vars
comma = 0;
temp_f = "";
temp_x = "";
temp_y = "";
temp_w = "";
temp_h = "";
//loop through all chars on the line
for (int j=0; j < lines[i].length(); j++) {
char c = lines[i].charAt(j); //this is the char we are looking at
if(c == ','){ //which comma are we on
comma++;
}
if(comma == 0){ //break into multiple strings
temp_f += c;
}
else if(comma == 1){
if(c != ','){
temp_x += c;
}
}else if(comma == 2){
if(c != ','){
temp_y += c;
}
}else if(comma == 3){
if(c != ','){
temp_w += c;
}
}else if(comma == 4){
if(c != ','){
temp_h += c;
}
}
}
//convert strings to ints
f = PApplet.parseInt(temp_f);
x = PApplet.parseInt(temp_x);
y = PApplet.parseInt(temp_y);
w = PApplet.parseInt(temp_w);
h = PApplet.parseInt(temp_h);
t += inc;
//load data into object
FM = new frame(f, x, y, w, h, t);
FMS[i] = FM;
//FMS[i].print();
}
}
//load movie data
public void movieEvent(Movie myMovie) {
myMovie.read();
}
public void draw(){
myMovie.loadPixels();
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
int loc = i + j*width;
float r = red(myMovie.pixels[loc]);
float g = green(myMovie.pixels[loc]);
float b = blue(myMovie.pixels[loc]);
float a = alpha(myMovie.pixels[loc]);
set(i, j, color(r/count, g/count, b/count, a/count));
}
}
if (fnum > 1) {
if (FMS[fnum-1].w * FMS[fnum-1].h < 1500 && FMS[fnum].w * FMS[fnum].h > 0) {
count = 1;
} else {
count += 0.05f;
}
}
//figure out frame # based on time from .mov
fnum = PApplet.parseInt(myMovie.time()*29.96f);
}
class frame{
int f, x, y, w, h;
float t;
frame(int frame, int xpos, int ypos, int wth, int hgt, float time){
f = frame;
x = xpos;
y = ypos;
w = wth;
h = hgt;
t = time;
}
public void print(){
println("f=" + f + ", x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ", t=" + t);
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "--bgcolor=#ffffff", "GloveLight" });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment