Drunk_Duck
YaBB Newbies
Offline
Posts: 4
openCV - display an image while analyzing a copy
May 23rd , 2009, 6:22am
Hello everybody! I'm stuck with something I thought it had to be very simple. I wanted to use openCV to detect my face and display the image at the same time. Since face detection gets very slow at 640*480 my idea was to: -> grab a full res frame from the webcam -> display it -> resize it to half the size -> do the face detection My last attempt was to grab the video with the standard library and than pass it to openCV. It seems to works, cause i get a smaller image on which the opecv.contrast and opencv.brightness functions work. It's just the detect one that does not, damn it! Any help is greatly appreciated! import processing.video.*; import hypermedia.video.*; Capture cam; OpenCV opencv; // contrast/brightness values int contrast_value = 0; int brightness_value = 0; void setup() { size( 800, 600 ); cam = new Capture(this, 640, 480); opencv = new OpenCV( this ); opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml" // 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" ); } public void stop() { opencv.stop(); super.stop(); } void draw() { if (cam.available() == true) { cam.read(); image(cam, 0, 0); } // ////////////////// HERE IS THE IMPORTANT PART opencv.allocate(320,240); // create the buffer opencv.copy(cam,0,0,640,480,0,0,320,240); opencv.convert( GRAY ); opencv.flip( OpenCV.FLIP_HORIZONTAL ); // flip horizontally opencv.contrast( contrast_value ); opencv.brightness( brightness_value ); // proceed detection Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 ); image( opencv.image(), 0, 0 ); // draw face area(s) noFill(); stroke(255,0,0); // rect(30,18,88,333); for( int i=0; i<faces.length; i++ ) { rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); println("DDD"); } } void mouseDragged() { contrast_value = (int) map( mouseX, 0, width, -128, 128 ); brightness_value = (int) map( mouseY, 0, width, -128, 128 ); } Thanks again in advance folks!