How can I get text and images to scale with facial detection?
in
Contributed Library Questions
•
1 year ago
Hello All!!
I want to use the simple, attached facial detection code to scale images on my screen up and down. When someone
moves their head in, the red facial detection box gets larger as a face gets larger in the camera causing the image to get smaller or moving a face away from the camera (causing the red box to get smaller) the image would get larger. I do not know how to make this happen, still new to processing!
please help! I hope someone out there can spread some light on the subject.
best regards
Peter
- import hypermedia.video.*;
- import java.awt.Rectangle;
- import processing.serial.*;
- int gx = 15;
- int gy = 35;
- int spos=90;
- Serial port;
- OpenCV opencv;
- // contrast/brightness values
- int contrast_value = 0;
- int brightness_value = 0;
- void setup() {
- size( 640, 480 );
- 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() {
- // grab a new frame
- // and convert to gray
- opencv.read();
- opencv.convert( RGB );
- opencv.contrast( contrast_value );
- opencv.brightness( brightness_value );
- // 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++ ) {
- rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height );
- }
- }
1