You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.3 KiB

4 years ago
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
import processing.serial.*;
Serial myPort;
int xpos = 0;
Capture video;
OpenCV opencv;
void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
myPort = new Serial(this, "/dev/ttyACM0", 9600);
video.start();
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 );
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
if(faces.length > 0) {
println("Faces detected: " + faces.length);
for(int i = 0; i < faces.length; i++) {
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
if(faces[i].x > 1) {
xpos = (int) faces[0].x;//int(map(faces[i].x, 0, 320, 0, 100));
if(xpos < 60){
myPort.write('A');
} else if(xpos >= 60 && xpos < 120){
myPort.write('B');
} else if(xpos >= 120 && xpos < 180){
myPort.write('C');
} else if(xpos >= 180 && xpos < 240){
myPort.write('D');
} else if(xpos > 240){
myPort.write('E');
}
//println(faces[0].x + " - " + xpos);
}
}
}
delay(100);
}
void captureEvent(Capture c) {
c.read();
}