Go Down

Topic: Facial Tracking... Infamous black screen (Read 577 times) previous topic - next topic

steinklatre

Heres what I am attemptiing to do. Take my eyes and get them to pan and track to someones face when they walk up or by.

These will be used in a halloween prop and while I think I am on the right track I wanted to reach out to the group to garner thoughts and opionins as to the process and if there is a better way by all means I am open.

Currently my plan is to use Windows 7 64bit OS: Webcam input to Processing + OpenCV talking to Arduino.

      Later I will attempt to:
Implement a IR Webcam
Transmit via WiFi or Ethernet
Expand to Audio too.
Last night I spent some time installing everything and ran into a problem (which I have read about) where I get a black screen from my webcam and a haarcascade file location issue. This is where I am stuck right now.

Thanks in advance!
Patience.....

steinklatre

I have gotten the haarcascade issue fixed but now am left with the black screen issue.


Tested on processing 2 64 and 32 bit and same result. I tried the v1.5 and it had library issues so wrote that off.

Screenshot included....

Here is the code:

Processing:

Code: [Select]
import processing.video.*;
import hypermedia.video.*; //import the necessary libraries
import java.awt.Rectangle;
import processing.serial.*;
import cc.arduino.*;


Capture myCapture;
OpenCV opencv;   //create the library object

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;

// The arduino object:
Arduino arduino;   


/*********************************************************

  setup

*********************************************************/
void setup() {

   
 
    size( 320, 240 ); //set window size
   
    //windows fix addition   
    myCapture = myCapture = new Capture(this, width, height, 30);

    opencv = new OpenCV( this ); //setup openCV
   
    //windows fix addition
    opencv.allocate(width, height);
   
    //opencv.capture( width, height );   // open video stream
   
    //the arduino serial setup
    arduino = new Arduino(this, Arduino.list()[0], 57600);
   
    //list of available detection types: http://ubaa.net/shared/processing/opencv/opencv_cascade.html
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
    //opencv.cascade( OpenCV.CASCADE_PROFILEFACE);
    //opencv.cascade( OpenCV.CASCADE_FULLBODY);

    // print usage
    println( "Drag mouse on X-axis inside this sketch window to change contrast" );
    println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

}

/*********************************************************

  draw

*********************************************************/
void draw() {

    //windows fix addition
    myCapture.read();
    opencv.copy(myCapture);
   
    opencv.read(); //read a new camera frame
    opencv.convert( GRAY ); //convert frame to gray scale
    opencv.contrast( contrast_value ); //apply contrast filter
    opencv.brightness( brightness_value ); //apply brightness filter

    // detect faces and put them in an array
    Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

    // display gray image
    image( opencv.image(), 0, 0 );

    // draw face detection rectangles
    noFill();
    stroke(255,0,0);
   
    if(faces.length > 0)
    {
      //the RC servo only follows the first face found.
      int mappedValue = (int) map(faces[0].x,0,width, 0, 255); //map from screen width to 255
      arduino.analogWrite(3, mappedValue); //send data to the arduino
    }
   
    for( int i=0; i<faces.length; i++ ) {
        rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );             
    }
}



/*********************************************************

  mouseDragged
 
  change brightness and contrast values

*********************************************************/
void mouseDragged() {
    contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
    brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}

/*********************************************************

  stop

*********************************************************/
public void stop() {
    opencv.stop(); //shutdown opencv on exit
    super.stop();
}



And the Arduino code is just the firmata:

Code: [Select]
#include <Servo.h>
#include <Firmata.h>

Servo servos[MAX_SERVOS];

void analogWriteCallback(byte pin, int value)
{
    if (IS_PIN_SERVO(pin)) {
        servos[PIN_TO_SERVO(pin)].write(value);
    }
}

void setup()
{
    byte pin;

    Firmata.setFirmwareVersion(0, 2);
    Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);

    for (pin=0; pin < TOTAL_PINS; pin++) {
        if (IS_PIN_SERVO(pin)) {
    servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
        }
    }
   
    Firmata.begin(57600);
}

void loop()
{
    while(Firmata.available())
        Firmata.processInput();
}


Any ideas?
Patience.....

Go Up