Tag Archives: video

It’s Raining, It’s Pouring (Brain Tracking)

So I was busy and just kept my program simple. I just took the color tracking program, made the ellipse into a bucket, and added falling raindrops. If you catch 20 raindrops “Winner!” shows up on the screen. I tried to add sound but I kept getting a NullPointerException so I just am using external sound. I also tried to have an image appear that said “Winner!” instead of just text but it gave the same error. As for the brain, well I just had it laying around and needed something colorful.

Here is the program in action.
Here is the program in action.

And here’s the code, I didn’t clean it up because I was busy, but it works!

//tracking the average pixel makes it shake less
//Sound and winning sign I wanted not working.
import processing.video.Capture;
Capture cam;// regular processing libary
int threshold = 20; //255 is white, 0 is black
int aveX, aveY; //this is what we are trying to find
float objectR =255;
float objectG = 0;
float objectB = 0;
boolean debug = true;
int lastTime, ellapsedTime; //for checking performance
//import ddf.minim.*;
//Minim m;
//AudioPlayer raindropFalling;
//PImage winning;

Raindrop[] rain = new Raindrop[20];
int howManyCaught = 0;
void setup() {
  size(640, 480);
  println(Capture.list());
  cam = new Capture(this, width, height);
  cam.start();

  //m = new Minim(this);
  //raindropFalling = m.loadFile("raindrops-processing.wav",1024);

  for (int i = 0; i<20; i++) {
    rain[i] = new Raindrop();
  }
  //winning = loadImage("http://bbsimg.ngfiles.com/1/24409000/ngbbs50e4c4e6e051d.jpg");
}
void draw() {
  //raindropFalling.play();
  //raindropFalling.rewind();
  if (cam.available()) {
    ellapsedTime = millis() - lastTime;  //find time since last time, only print it out if you press "t"
    lastTime = millis();  //reset timer for checking time next fram
    cam.read();
    int totalFoundPixels= 0;  //we are going to find the average location of change pixes so
    int sumX = 0;  //we will need the sum of all the x find, the sum of all the y find and the total finds
    int sumY = 0;
    //enter into the classic nested for statements of computer vision
    for (int row = 0; row < cam.height; row++) {
      for (int col = 0; col < cam.width; col++) {
        //the pixels file into the room long line you use this simple formula to find what row and column the sit in 

        int offset = row * cam.width + col;
        //pull out the same pixel from the current frame 
        int thisColor = cam.pixels[offset];

        //pull out the individual colors for both pixels
        float r = red(thisColor);
        float g = green(thisColor);
        float b = blue(thisColor);

        //in a color "space" you find the distance between color the same whay you would in a cartesian space, phythag or dist in processing
        float diff = dist(r, g, b, objectR, objectG, objectB);

        if (diff < threshold) {  //if it is close enough in size, add it to the average
          sumX = sumX + col;
          sumY= sumY + row;
          totalFoundPixels++;
          if (debug) cam.pixels[offset] = 0xff000000;//debugging
        }
      }
    }
    image(cam, 0, 0);
    if (totalFoundPixels > 0) {
      aveX = sumX/totalFoundPixels;
      aveY = sumY/totalFoundPixels;
      stroke(255);
      fill(100);
      quad(aveX, aveY, aveX+20, aveY+100, aveX+80, aveY+100, aveX+100, aveY);
    }
  }
  for (int i = 0; i<20; i++) {
    rain[i].drop();
    catchdrop(i);
  }
  if (howManyCaught >= 20) {
    textSize(160);
    fill(0,255,0);
    text("Winner!", 50, 200);
    //image(winning, 640, 480);
  }
}

void catchdrop(int tempNum) {
  if ( dist(aveX+55, aveY, rain[tempNum].x, rain[tempNum].y) <= 50) {
    rain[tempNum].y = -20;
    howManyCaught++;
  }
}

/*void stop() {
  raindropFalling.close();
  m.stop();
  super.stop();
}*/

void mousePressed() {
  //if they click, use that picture for the new thing to follow
  int offset = mouseY * cam.width + mouseX;
  //pull out the same pixel from the current frame 
  int thisColor = cam.pixels[offset];

  //pull out the individual colors for both pixels
  objectR = red(thisColor);
  objectG = green(thisColor);
  objectB = blue(thisColor);
  println("Chasing new color  " + objectR + " " + objectG + " " + objectB);
}
void keyPressed() {
  //for adjusting things on the fly
  if (key == '-') {
    threshold--;
    println("Threshold " + threshold);
  } 
  else if (key == '=') {
    threshold++;
    println("Threshold " + threshold);
  }
  else if (key == 'd') {
    background(255);
    debug = !debug;
    println("Debug " + debug);
  }
  else if (key == 't') {
    println("Time Between Frames " + ellapsedTime);
  }
  else if (key == 'r') {
    howManyCaught = 0;
  }
}

 

 

ASL to LED (AKA American Sign LED-uage)

For my project I wanted to combine American Sign Language and what we’ve been working on in class. So I decided to translate the sign language alphabet into Morse code (done through flashes on an LED). I used two flex sensors, one on my thumb and one on my forefinger to do so. For this project I only did the letters A through H because to go past that I would need another flex sensor as well as an accelerometer to accurately transmit the letters. However, for A through H only the thumb sensor would technically be needed, but for accuracy (and I bought the thing so I figured why not) I used the one on the forefinger as well. It took me a while to figure out exactly how to code it and I feel like there would be a way to shorten down the code, but I did not know how at this point. But the biggest time consumer was figuring out the sensor ranges needed to code. And here is the video explaining some of this and a demonstration.

//all the alphabet used to monitor my accuracy of handshapes
// to make sure it was picking up the right letter.
int A = 1;
int B = 2;
int C = 3;
int D = 4;
int E = 5;
int F = 6;
int G = 7;
int H = 8;
int dot = 500;
int dash = 1000;
int pause = 200;
void setup(){
  pinMode (8, OUTPUT);
  Serial.begin(9600);

}

void loop(){
  int input = analogRead(A1);
  int inputF = analogRead (A2);
  int flexFore = map (inputF, 320, 557, 0, 100);
  int flexNumbers = map(input, 360, 540, 0, 100);

  if (flexNumbers >= 90 && flexNumbers <=100){
    if (flexFore >= 25 && flexFore < 35){
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
      Serial.println(A);
    delay(3000);
    }
  }

   else if (flexNumbers >= 80 && flexNumbers <90){
     if (flexFore >=80 && flexFore <95) {
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
       Serial.println(H);
    delay(3000);
     }
  }
  else if (flexNumbers >=70 && flexNumbers <80) {
    if (flexFore >= 80 && flexFore <95){
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);  
    Serial.println(G);
    delay(3000);
    }
  }
  else if (flexNumbers >=60 && flexNumbers <70){
    if (flexFore >=50 && flexFore <60){
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);  
    Serial.println(C);
    delay(3000);
    }
  }
  else if (flexNumbers >=50 && flexNumbers <60) {
    if (flexFore >=30 && flexFore <40){
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
      Serial.println(F);
    delay(3000);
    }
  }
  else if (flexNumbers >=40 && flexNumbers <50) {
    if (flexFore >= 90 && flexFore <=100){
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
      Serial.println(D);
    delay(3000);
    }
  }
  else if (flexNumbers >=30 && flexNumbers <40){
    if (flexFore >=90 && flexFore <=100){
    digitalWrite (8, HIGH);
    delay (dash);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
    delay (pause);
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
      Serial.println(B);
    delay(3000);
    }
  }
  else if (flexNumbers <30){
    if (flexFore >= 0 && flexFore < 20){
    digitalWrite (8, HIGH);
    delay (dot);
    digitalWrite (8, LOW);
      Serial.println(E);
    delay(3000);
    }
  }

}