A problem rebuild face detect program with new OpenCV library not 2007 faceDetect library.
in
Contributed Library Questions
•
2 years ago
Hi am really stuck rebuilding this program i created at university as I cannot get this library to work, was designed for processing 1.1 so that may be the issue.
I have been able to get face detection to work using the Open CV Library
The code creates a stylized image of the live webcam feed only when faces are detected, otherwise it displays the last image generated with a face.
But am having trouble integrating this into my original code. As the open CV example code does not use capture cam, when I try to put the two codes together I am asking two different libraries to create an image.
Here is my original code if anyone can help me out I would be very grateful its been driving me up the wall.
- /*
- title: interactive pop art screen
- description: veiwer portrait in pop art style, tiled filtered images
- created: 9th Januarry 2009
- By: Sean Doyle
- */
- //import libraries
- import fullscreen.*;
- import processing.video.*;
- import FaceDetect.*;
- //call libraries
- FaceDetect fd;
- Capture cam;
- FullScreen fs;
- //int for face detection
- int MAX = 10;
- int[][] Faces = new int[MAX][3];
- void setup(){
- size(1280,800,P3D); //set size to screen resolution
- fs = new FullScreen(this);
- fs.enter(); //set sketch to full screen mode
- cam = new Capture(this, 640, 480); //capture camera image
- fd = new FaceDetect(this);
- fd.start("haarcascade_frontalface_alt.xml", width,height,30);
- noFill();
- }
- void draw(){ //begin draw loop
- if (cam.available()) {
- cam.read();
- Faces = fd.face(cam);
- int count = Faces.length; //int stores number of faces detected
- // println(count);
- if (count>0){ //if count is greater than zero loop is used
- /*This section of code copies the image from the camera
- and tiles it into a variable number of rows and colums
- these numbers can be changed to create more rows and colums
- the code will still work. Then adds effects to the image*/
- int cols = 5; //numbr of colums
- int rows = 4; //number of rows
- int w = width/cols; //width of image is the screen widh devided by number of colums
- int h = height/rows;//hight of image is the screen with devided by the number of rows
- for (int i =0; i<height; i+=h){
- for (int j=0; j<width; j+=w){
- tint(map(i, 0, height, 10, 100), map(j, 0, width, 10, 255), 100); //adds a varying tint to each part of the image
- image(cam, j, i, w, h);
- }
- }
- filter (POSTERIZE, 4);//add a poster style effect to the image
- }
- }
- }
- import hypermedia.video.*;
- import java.awt.Rectangle;
- import processing.video.*;
- //call libraries
- OpenCV opencv;
- Capture myCapture;
- // contrast/brightness values
- void setup() {
- size(1280,800,P3D); //set size to screen resolution
- opencv = new OpenCV( this );
- opencv.capture( width, height ); // open video stream
- opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"
- }
- public void stop() {
- opencv.stop();
- super.stop();
- }
- void draw() {
- opencv.read();
- // proceed detection
- Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );
- // display the image
- image( opencv.image(), 0, 0 );
- // draw face area(s)
- noFill();
- stroke(255,0,0);
- for( int i=0; i<faces.length; i++ ) {
- //my modification
- if (!faces[i].isEmpty()) //if face is detected do this
- {
- println("there is a face");
- filter (POSTERIZE, 4);//add a poster style effect to the image
- }
- }
- }
- /**
- * Changes contrast/brigthness values
- */
1