Bonjour,
avec nos petits amis du tetalab, nous avons réalisé quelques chose dans l'esprit,
nous avons équipé un masque réalisé par un artiste (Elie Cinqpeyres) avec des yeux motorisés par un servo qui suivent la position d'un visage repéré par une webcam et processing,
il y a des led dans les yeux dont la luminosité augmente avec la distance du visage
c'est surement très perfectible, mais peut être que cela peux te servir de base
http://git.tetalab.org/index.php/p/eyesbot/source/tree/master/
Code Arduino (dérivé du code sweep en exemple)
// Sweep
// by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int val1 = 0; // variable to store the servo position or led brightness
int val2 = 0;
int L=0;
void setup()
{
Serial.begin(115200);
myservo.attach(11); // attaches the servo on pin 9 to the servo object
}
void loop()
{
/**/
if (Serial.available() > 0) {
// read the incoming byte:
val1 = int(Serial.read());
val2 = int(Serial.read());
Serial.print("I received: ");
Serial.print(val1);
//Serial.println(pos, DEC);
}
/**/
//val1=240;
if (val1<181){
myservo.write(val1);
L = map(val2, 181, 255, 0, 255);
analogWrite(3, L);
//analogWrite(10, L);
}else{
myservo.write(val2);
L = map(val1, 181, 255, 0, 255);
analogWrite(3, L);
//analogWrite(10, L);
//Serial.println(L);
}
// tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Code Processing
import processing.serial.*;
import hypermedia.video.*;
import java.awt.Rectangle;
OpenCV opencv;
int contrast_value = 0;
int brightness_value = 0;
int eyesX;
int eyesL;
float pupilX = map(mouseX, 0, width, 215, 265);
float pupilY = map(mouseY, 0, height, 200, 240);
float pupilA = map(mouseX, 0, width, 375, 425);
//serial
Serial myPort;
void setup() {
size( 320, 240 );
myPort=new Serial(this,"/dev/ttyUSB0",115200);
opencv = new OpenCV(this);
opencv.capture( width, height );
opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load the FRONTALFACE description file
}
void draw() {
opencv.read();
opencv.contrast( contrast_value );
opencv.brightness( brightness_value );
image( opencv.image(), 0, 0 );
// detect anything ressembling a FRONTALFACE
Rectangle[] faces = opencv.detect(1.2,2,OpenCV.HAAR_DO_CANNY_PRUNING,40,40);
// draw detected face area(s)
noFill();
stroke(255,0,0);
//for( int i=0; i<faces.length; i++ ) {
if (faces.length>0) {
int i=0;
rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
pupilX = map((faces[i].x), 0, width, 215, 265);
pupilY = map((faces[i].y), 0, height, 205, 240);
eyesX = round(map((faces[i].x), 0, width, 180, 20));
eyesL = round(map((faces[i].width), 40, 200,181, 254));
//println((faces[i].width));
}
fill(255);
ellipse(240, 225, 80, 80); //left eye
ellipse(400, 225, 80, 80); //right eye
fill(0);
println(eyesX);
//println(eyesL);
ellipse(pupilX, pupilY, 20, 20); //left pupil
ellipse(pupilA, pupilY, 20, 20); //right pupil
myPort.write(eyesX);
myPort.write(eyesL);
}
void mouseDragged() {
contrast_value = (int) map( mouseX, 0, width, -128, 128 );
brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}
Bon courage,
Lionel