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:
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:
#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?