Eye Iterate

Eye Iterate detects the eye of the user and captures the pixels within that bounding box. Those pixels are then translated and scaled to iterate across the screen until the user disappears behind the eye. The pixels will continue to update as long as the user remains in front of the camera. I haven’t been able to figure out yet how  to make this happen. Instead of using translate and scale, I think I’ll create a 2D array of pixels and see if that gets me closer to what I want to see or use the createImage()?

Here’s my current code:

import hypermedia.video.*;
import java.awt.Rectangle;
OpenCV opencv;

Rectangle bestRect = new Rectangle(0, 0, 0, 0);

PImage eye;

float scaleX;
float scaleY;
float transX;
float transY;

int counter = 0;

void setup() {
size( 640, 480 );

opencv = new OpenCV( this );
opencv.capture( width, height );
opencv.interpolation(OpenCV.INTER_NN); // set the interpolation method
// open video stream
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : “haarcascade_frontalface_alt.xml”

eye = loadImage(“suren.jpg”);
eye.resize(20, 20);

}
public void stop() {
opencv.stop();
super.stop();
}
void draw() {
//rectMode(CORNER);
//scale(11);
//translate(transX+10, transY+10);
opencv.read();

// proceed detection
Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

// display the image
imageMode(CORNER);
pushMatrix();
//imageMode(CENTER);
// translate(transX, transY);
print(transX+” ” +transY);
println();

// scale(3);
image( opencv.image(), 0, 0 );
popMatrix();

// if (faces.length== 2){ //switch faces
// PImage firstFace = bigImage.get(faces[0].x,faces[0].y,faces[0].width,faces[0].height);
// PImage secondFace = bigImage.get(faces[1].x,faces[1].y,faces[1].width,faces[1].height);
// image(firstFace,faces[1].x,faces[1].y,faces[1].width,faces[1].height);
// image(secondFace,faces[0].x,faces[0].y,faces[0].width,faces[0].height);
// }

 

// draw face area(s)
noFill();
stroke(255, 0, 0);
for ( int i=0; i<faces.length; i++ ) {
if (i == 0) bestRect = new Rectangle(faces[i]);
rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
}
stroke(0, 255, 0);
rect(bestRect.x, bestRect.y, bestRect.width, bestRect.height);
fill(255, 0, 0);
imageMode(CENTER);
//image(eye, bestRect.x + 50, bestRect.y + 50);
noFill();
transX = (bestRect.x + .25 * bestRect.width) * -1;
transY = (bestRect.y + .35 * bestRect.height) * -1;
rect(bestRect.x + .25 * bestRect.width, bestRect.y + .35 * bestRect.height, 20, 20);

opencv.copy(opencv.image(), int(bestRect.x + .25 * bestRect.width), int(bestRect.y + .35 * bestRect.height), 20, 20, 0, 0, width, height);
image( opencv.image(), 0, 0 );
}

void keyPressed() {
if (key == ‘ ‘) {
save(“data/eye_” + counter + “.png”);
counter++;
}
}

Comments are closed.