From 41821b5db8c7d1bc887264814e7cae4ad342422b Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 4 Jul 2010 11:45:01 +0200 Subject: [PATCH 1/5] faceblur made at hackmeeting 0x0D --- configure.ac | 1 + doc/html/Makefile.am | 32 +--- src/Makefile.am | 5 + src/filter/facebl0r/facebl0r.cpp | 251 +++++++++++++++++++++++++++++++ 4 files changed, 258 insertions(+), 31 deletions(-) create mode 100644 src/filter/facebl0r/facebl0r.cpp diff --git a/configure.ac b/configure.ac index 5ce4b4c..0b114c7 100644 --- a/configure.ac +++ b/configure.ac @@ -91,6 +91,7 @@ AM_CONDITIONAL([HAVE_OPENCV], [test x$HAVE_OPENCV = xtrue]) if test x$HAVE_OPENCV = xtrue; then OPENCV_CFLAGS="$OPENCV_CFLAGS -DOPENCV_PREFIX=`pkg-config opencv --variable=prefix`" fi +AC_SUBST(HAVE_OPENCV) HAVE_GAVL=false PKG_CHECK_MODULES(GAVL, gavl >= 0.2.3, [HAVE_GAVL=true], [true]) diff --git a/doc/html/Makefile.am b/doc/html/Makefile.am index adbcca4..075254d 100644 --- a/doc/html/Makefile.am +++ b/doc/html/Makefile.am @@ -1,35 +1,5 @@ htmldocs_DATA = \ - annotated.html \ - doxygen.png \ - functions.html \ - globals.html \ - group__icons.html \ - hierarchy.html \ - structf0r__param__color.html \ - tab_b.gif \ - dir_c6a51e201754b7c7dc5a21651891d7e2.html \ - files.html \ - functions_vars.html \ - globals_type.html \ - group__PARAM__TYPE.html \ - index.html \ - structf0r__param__info.html \ - tab_l.gif \ - dirs.html \ - frei0r_8h.html \ - globals_defs.html \ - group__COLOR__MODEL.html \ - group__PLUGIN__TYPE.html \ - structf0r__param__position.html \ - tab_r.gif \ - doxygen.css \ - frei0r_8h-source.html \ - globals_func.html \ - group__concurrency.html \ - group__pluglocations.html \ - modules.html \ - structf0r__plugin__info.html \ - tabs.css + $(shell ls * | grep -v Makefile) htmldocsdir=${prefix}/share/doc/${PACKAGE}-1.1/html diff --git a/src/Makefile.am b/src/Makefile.am index f35cd7f..4b34d84 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,11 @@ plugin_LTLIBRARIES += facedetect.la facedetect_la_SOURCES = filter/facedetect/facedetect.c facedetect_la_CFLAGS = @OPENCV_CFLAGS@ @CFLAGS@ facedetect_la_LIBADD = @OPENCV_LIBS@ + +plugin_LTLIBRARIES += facebl0r.la +facebl0r_la_SOURCES = filter/facebl0r/facebl0r.cpp +facebl0r_la_CFLAGS = @OPENCV_CFLAGS@ @CFLAGS@ +facebl0r_la_LIBADD = @OPENCV_LIBS@ endif cluster_la_SOURCES = filter/cluster/cluster.c diff --git a/src/filter/facebl0r/facebl0r.cpp b/src/filter/facebl0r/facebl0r.cpp new file mode 100644 index 0000000..1f40a01 --- /dev/null +++ b/src/filter/facebl0r/facebl0r.cpp @@ -0,0 +1,251 @@ +/* + * This source code is free software; you can redistribute it and/or + * modify it under the terms of the GNU Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer + * to the GNU Public License for more details. + * + * You should have received a copy of the GNU Public License along + * with this source code; if not, write to: Free Software Foundation, + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#include +#include +#include +#include + +#include + + +typedef struct { + IplImage* hsv; //input image converted to HSV + IplImage* hue; //hue channel of HSV image + IplImage* mask; //image for masking pixels + IplImage* prob; //face probability estimates for each pixel + + CvHistogram* hist; //histogram of hue in original face image + + CvRect prev_rect; //location of face in previous frame + CvBox2D curr_box; //current face location estimate +} TrackedObj; + +// camshift +TrackedObj* create_tracked_object (IplImage* image, CvRect* face_rect); +void destroy_tracked_object (TrackedObj* tracked_obj); +CvBox2D camshift_track_face (IplImage* image, TrackedObj* imgs); +void update_hue_image (const IplImage* image, TrackedObj* imgs); + +//trackface +IplImage* capture_video_frame (CvCapture*); +CvRect* detect_face (IplImage*, CvHaarClassifierCascade*, CvMemStorage*); +void cleanup (char*, CvHaarClassifierCascade*, CvMemStorage*); +void print_help (char*); + + + +class FaceBl0r: public frei0r::filter { + +public: + FaceBl0r(int wdt, int hgt); + ~FaceBl0r(); + + virtual void update(); + +private: + + void _init(int wdt, int hgt); + + TrackedObj* tracked_obj; + CvBox2D face_box; //area to draw + CvRect* face_rect; + +//used by capture_video_frame, so we don't have to keep creating. + IplImage* image; + + CvHaarClassifierCascade* cascade; + CvMemStorage* storage; + + char *classifier; + + int bytesize; +}; + + +frei0r::construct plugin("FaceBl0r", + "automatic face blur ", + "ZioKernel, Biilly, Jilt, Jaromil", + 1,0); + +FaceBl0r::FaceBl0r(int wdt, int hgt) { + CvHaarClassifierCascade* cascade = 0; + CvMemStorage* storage = 0; + + width = wdt; + height = hgt; + bytesize = width*height*4; + //initialize + classifier = (const char*)"/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"; + cascade = (CvHaarClassifierCascade*) cvLoad(classifier, 0, 0, 0 ); + storage = cvCreateMemStorage(0); + //validate + //assert(cascade && storage); + + face_rect = 0; + image = 0; + tracked_obj = 0; + +} + +FaceBl0r::~FaceBl0r() { + if(tracked_obj) + destroy_tracked_object(tracked_obj); +// cleanup(cascade); +// cleanup(storage); +} + +void FaceBl0r::update() { + unsigned char *src = (unsigned char *)in; + unsigned char *dst = (unsigned char *)out; + + if( !image ) + image = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 4 ); + unsigned char* ipli = (unsigned char*)image->imageData; + int step = image->widthStep; + unsigned i, j; + for (i = 0; (i < height); i++) { + for (j = 0; (j < width); j++) { + ipli[i*step+j*4+2] = src[2]; + ipli[i*step+j*4+1] = src[1]; + ipli[i*step+j*4+0] = src[0]; + //ipli += 4; + src += 4; + } + } + + face_rect = detect_face(image, cascade, storage); + // if face detected + if (!face_rect) { + memcpy(out,in,bytesize); + return; + } + + //track detected face with camshift + tracked_obj = create_tracked_object(image, face_rect); + + + //track the face in the new frame + face_box = camshift_track_face(image, tracked_obj); + +//////////////////////////////////////////////////////////////////////// + cvSetImageROI (image, tracked_obj->prev_rect); + cvSmooth (image, image, CV_BLUR, 22, 22, 0, 0); +// cvSmooth (image, image, CV_BLUR, 11, 11, 0, 0); +// cvSmooth (image, image, CV_GAUSSIAN, 11, 11, 0, 0); + cvResetImageROI (image); +//////////////////////////////////////////////////////////////////////// + + //outline face ellipse + cvEllipseBox(image, face_box, CV_RGB(255,0,0), 3, CV_AA, 0); + memcpy(out,image->imageData,bytesize); + +} + +/* Create a camshift tracked object from a region in image. */ +TrackedObj* create_tracked_object (IplImage* image, CvRect* region) { + TrackedObj* obj; + + //allocate memory for tracked object struct + if((obj = (TrackedObj *) malloc(sizeof *obj)) != NULL) { + //create-image: size(w,h), bit depth, channels + obj->hsv = cvCreateImage(cvGetSize(image), 8, 3); + obj->mask = cvCreateImage(cvGetSize(image), 8, 1); + obj->hue = cvCreateImage(cvGetSize(image), 8, 1); + obj->prob = cvCreateImage(cvGetSize(image), 8, 1); + + int hist_bins = 30; //number of histogram bins + float hist_range[] = {0,180}; //histogram range + float* range = hist_range; + obj->hist = cvCreateHist(1, //number of hist dimensions + &hist_bins, //array of dimension sizes + CV_HIST_ARRAY, //representation format + &range, //array of ranges for bins + 1); //uniformity flag + } + + //create a new hue image + update_hue_image(image, obj); + + float max_val = 0.f; + + //create a histogram representation for the face + cvSetImageROI(obj->hue, *region); + cvSetImageROI(obj->mask, *region); + cvCalcHist(&obj->hue, obj->hist, 0, obj->mask); + cvGetMinMaxHistValue(obj->hist, 0, &max_val, 0, 0 ); + cvConvertScale(obj->hist->bins, obj->hist->bins, + max_val ? 255.0/max_val : 0, 0); + cvResetImageROI(obj->hue); + cvResetImageROI(obj->mask); + + //store the previous face location + obj->prev_rect = *region; + + return obj; +} + +/* Release resources from tracked object. */ +void destroy_tracked_object (TrackedObj* obj) { + cvReleaseImage(&obj->hsv); + cvReleaseImage(&obj->hue); + cvReleaseImage(&obj->mask); + cvReleaseImage(&obj->prob); + cvReleaseHist(&obj->hist); + + free(obj); +} + +/* Given an image and tracked object, return box position. */ +CvBox2D camshift_track_face (IplImage* image, TrackedObj* obj) { + CvConnectedComp components; + + //create a new hue image + update_hue_image(image, obj); + + //create a probability image based on the face histogram + cvCalcBackProject(&obj->hue, obj->prob, obj->hist); + cvAnd(obj->prob, obj->mask, obj->prob, 0); + + //use CamShift to find the center of the new face probability + cvCamShift(obj->prob, obj->prev_rect, + cvTermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1), + &components, &obj->curr_box); + + //update face location and angle + obj->prev_rect = components.rect; + obj->curr_box.angle = -obj->curr_box.angle; + + return obj->curr_box; +} + +void update_hue_image (const IplImage* image, TrackedObj* obj) { + //limits for calculating hue + int vmin = 65, vmax = 256, smin = 55; + + //convert to HSV color model + cvCvtColor(image, obj->hsv, CV_BGR2HSV); + + //mask out-of-range values + cvInRangeS(obj->hsv, //source + cvScalar(0, smin, MIN(vmin, vmax), 0), //lower bound + cvScalar(180, 256, MAX(vmin, vmax) ,0), //upper bound + obj->mask); //destination + + //extract the hue channel, split: src, dest channels + cvSplit(obj->hsv, obj->hue, 0, 0, 0 ); +} From 1cfb3077fe265e0152aa76db6c4e272eaf7754e8 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 4 Jul 2010 17:25:58 +0200 Subject: [PATCH 2/5] fixed in post-hackmeeting with anarchia --- src/filter/facebl0r/facebl0r.cpp | 138 ++++++++++++++++++++++--------- 1 file changed, 98 insertions(+), 40 deletions(-) diff --git a/src/filter/facebl0r/facebl0r.cpp b/src/filter/facebl0r/facebl0r.cpp index 1f40a01..05fffa2 100644 --- a/src/filter/facebl0r/facebl0r.cpp +++ b/src/filter/facebl0r/facebl0r.cpp @@ -35,18 +35,6 @@ typedef struct { CvBox2D curr_box; //current face location estimate } TrackedObj; -// camshift -TrackedObj* create_tracked_object (IplImage* image, CvRect* face_rect); -void destroy_tracked_object (TrackedObj* tracked_obj); -CvBox2D camshift_track_face (IplImage* image, TrackedObj* imgs); -void update_hue_image (const IplImage* image, TrackedObj* imgs); - -//trackface -IplImage* capture_video_frame (CvCapture*); -CvRect* detect_face (IplImage*, CvHaarClassifierCascade*, CvMemStorage*); -void cleanup (char*, CvHaarClassifierCascade*, CvMemStorage*); -void print_help (char*); - class FaceBl0r: public frei0r::filter { @@ -59,7 +47,15 @@ public: private: - void _init(int wdt, int hgt); +// camshift + TrackedObj* create_tracked_object (IplImage* image, CvRect* face_rect); + void destroy_tracked_object (TrackedObj* tracked_obj); + CvBox2D camshift_track_face (IplImage* image, TrackedObj* imgs); + void update_hue_image (const IplImage* image, TrackedObj* imgs); + +//trackface + CvRect* detect_face (IplImage*, CvHaarClassifierCascade*, CvMemStorage*); + TrackedObj* tracked_obj; CvBox2D face_box; //area to draw @@ -73,7 +69,7 @@ private: char *classifier; - int bytesize; + bool face_found; }; @@ -83,30 +79,31 @@ frei0r::construct plugin("FaceBl0r", 1,0); FaceBl0r::FaceBl0r(int wdt, int hgt) { - CvHaarClassifierCascade* cascade = 0; - CvMemStorage* storage = 0; width = wdt; height = hgt; - bytesize = width*height*4; + size = width*height*4; //initialize classifier = (const char*)"/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"; cascade = (CvHaarClassifierCascade*) cvLoad(classifier, 0, 0, 0 ); storage = cvCreateMemStorage(0); //validate - //assert(cascade && storage); + assert(cascade && storage); face_rect = 0; image = 0; tracked_obj = 0; + face_found = false; } FaceBl0r::~FaceBl0r() { if(tracked_obj) destroy_tracked_object(tracked_obj); -// cleanup(cascade); -// cleanup(storage); + +// if(cascade) cvReleaseHaarClassifierCascade(&cascade); +// if(storage) cvReleaseMemStorage(&storage); + } void FaceBl0r::update() { @@ -115,49 +112,110 @@ void FaceBl0r::update() { if( !image ) image = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 4 ); + unsigned char* ipli = (unsigned char*)image->imageData; int step = image->widthStep; unsigned i, j; for (i = 0; (i < height); i++) { for (j = 0; (j < width); j++) { - ipli[i*step+j*4+2] = src[2]; - ipli[i*step+j*4+1] = src[1]; - ipli[i*step+j*4+0] = src[0]; + +// ipli[(i*step)+j*4+0] = src[0]; + ipli[(i*step)+j*4+2] = src[2]; + ipli[(i*step)+j*4+1] = src[1]; + ipli[(i*step)+j*4+0] = src[0]; //ipli += 4; src += 4; } } - face_rect = detect_face(image, cascade, storage); - // if face detected - if (!face_rect) { - memcpy(out,in,bytesize); - return; + + /* + no face* + - look for (detect_face) + yes face + - track face + - no more face + no face* + */ + + if(!face_found) { + face_rect = detect_face(image, cascade, storage); + // if face detected + if (!face_rect) { + memcpy(out,in,size); + return; + } + //track detected face with camshift + tracked_obj = create_tracked_object(image, face_rect); + face_found = true; } - //track detected face with camshift - tracked_obj = create_tracked_object(image, face_rect); - - //track the face in the new frame face_box = camshift_track_face(image, tracked_obj); - + + if( ( face_box.size.width < 10 ) + || (face_box.size.height <10 ) + || (face_box.size.width > 500 ) + || (face_box.size.height > 500 ) + ) { + + face_found = false; + return; + } + //////////////////////////////////////////////////////////////////////// cvSetImageROI (image, tracked_obj->prev_rect); - cvSmooth (image, image, CV_BLUR, 22, 22, 0, 0); -// cvSmooth (image, image, CV_BLUR, 11, 11, 0, 0); +// cvSmooth (image, image, CV_BLUR, 22, 22, 0, 0); + cvSmooth (image, image, CV_BLUR, 11, 11, 0, 0); // cvSmooth (image, image, CV_GAUSSIAN, 11, 11, 0, 0); cvResetImageROI (image); //////////////////////////////////////////////////////////////////////// //outline face ellipse cvEllipseBox(image, face_box, CV_RGB(255,0,0), 3, CV_AA, 0); - memcpy(out,image->imageData,bytesize); + +// memcpy(out,image->imageData,size); + src = (unsigned char *)in; + + for (i = 0; (i < height); i++) { + for (j = 0; (j < width); j++) { + +// ipli[(i*step)+j*4+0] = src[0]; + dst[3] = src[3]; + dst[2] = ipli[(i*step)+j*4+2]; + dst[1] = ipli[(i*step)+j*4+1]; + dst[0] = ipli[(i*step)+j*4+0]; + //ipli += 4; + dst += 4; + src += 4; + } + } } +/* Given an image and a classider, detect and return region. */ +CvRect* FaceBl0r::detect_face (IplImage* image, + CvHaarClassifierCascade* cascade, + CvMemStorage* storage) { + + CvRect* rect = 0; + + //get a sequence of faces in image + CvSeq *faces = cvHaarDetectObjects(image, cascade, storage, + 1.1, //increase search scale by 10% each pass + 6, //require 6 neighbors + CV_HAAR_DO_CANNY_PRUNING, //skip regions unlikely to contain a face + cvSize(0, 0)); //use default face size from xml + + //if one or more faces are detected, return the first one + if(faces && faces->total) + rect = (CvRect*) cvGetSeqElem(faces, 0); + + return rect; +} + /* Create a camshift tracked object from a region in image. */ -TrackedObj* create_tracked_object (IplImage* image, CvRect* region) { +TrackedObj* FaceBl0r::create_tracked_object (IplImage* image, CvRect* region) { TrackedObj* obj; //allocate memory for tracked object struct @@ -200,7 +258,7 @@ TrackedObj* create_tracked_object (IplImage* image, CvRect* region) { } /* Release resources from tracked object. */ -void destroy_tracked_object (TrackedObj* obj) { +void FaceBl0r::destroy_tracked_object (TrackedObj* obj) { cvReleaseImage(&obj->hsv); cvReleaseImage(&obj->hue); cvReleaseImage(&obj->mask); @@ -211,7 +269,7 @@ void destroy_tracked_object (TrackedObj* obj) { } /* Given an image and tracked object, return box position. */ -CvBox2D camshift_track_face (IplImage* image, TrackedObj* obj) { +CvBox2D FaceBl0r::camshift_track_face (IplImage* image, TrackedObj* obj) { CvConnectedComp components; //create a new hue image @@ -233,7 +291,7 @@ CvBox2D camshift_track_face (IplImage* image, TrackedObj* obj) { return obj->curr_box; } -void update_hue_image (const IplImage* image, TrackedObj* obj) { +void FaceBl0r::update_hue_image (const IplImage* image, TrackedObj* obj) { //limits for calculating hue int vmin = 65, vmax = 256, smin = 55; From f89778e6371d663c44e5ef290bc467b727438ba8 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Fri, 16 Jul 2010 12:49:49 +0100 Subject: [PATCH 3/5] fixed link to git snapshot --- web/index.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/index.org b/web/index.org index 81a7c5a..b73cc00 100644 --- a/web/index.org +++ b/web/index.org @@ -94,7 +94,7 @@ revisioning system *GIT* : git clone git://code.dyne.org/frei0r.git Daily snapshots are also packed ready to "./configure; make" on -[[http://ftp.dyne.org/frei0r/][FTP.dyne.org]] +[[http://www.piksel.no/frei0r/snapshot/][www.piksel.no/frei0r/snapshot]] ** Debian / Ubuntu From a29ddf2042214b3e5c1f1ccb7a4438a83c4f9549 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Fri, 16 Jul 2010 12:54:40 +0100 Subject: [PATCH 4/5] some more variables and adjustements haarcascade path is hardcoded for now ?string parameters in frei0r aren't working from cpp? --- src/filter/facebl0r/facebl0r.cpp | 134 ++++++++++++++++--------------- 1 file changed, 71 insertions(+), 63 deletions(-) diff --git a/src/filter/facebl0r/facebl0r.cpp b/src/filter/facebl0r/facebl0r.cpp index 05fffa2..3aae93f 100644 --- a/src/filter/facebl0r/facebl0r.cpp +++ b/src/filter/facebl0r/facebl0r.cpp @@ -15,6 +15,8 @@ */ +#include + #include #include #include @@ -67,9 +69,16 @@ private: CvHaarClassifierCascade* cascade; CvMemStorage* storage; - char *classifier; - bool face_found; + int face_found; + int face_notfound; + unsigned int width; + unsigned int height; + unsigned int size; // = width * height + + f0r_param_string haarcascade[256]; + char classifier[512]; + }; @@ -83,8 +92,12 @@ FaceBl0r::FaceBl0r(int wdt, int hgt) { width = wdt; height = hgt; size = width*height*4; + + sprintf(haarcascade,"frontalface_default"); //initialize - classifier = (const char*)"/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml"; + snprintf(classifier,511,"/usr/share/opencv/haarcascades/haarcascade_%s.xml", haarcascade); + fprintf(stderr,"%s\n",classifier); + // para cascade = (CvHaarClassifierCascade*) cvLoad(classifier, 0, 0, 0 ); storage = cvCreateMemStorage(0); //validate @@ -93,7 +106,11 @@ FaceBl0r::FaceBl0r(int wdt, int hgt) { face_rect = 0; image = 0; tracked_obj = 0; - face_found = false; + face_found = 0; + face_notfound = 1; + +// register_param(haarcascade, "pattern model for recognition", +// "frontalface_alt2, frontalface_alt_tree, frontalface_alt, frontalface_default, fullbody, lowerbody, profileface, upperbody (see in share/opencv/haarcascades)"); } @@ -101,8 +118,8 @@ FaceBl0r::~FaceBl0r() { if(tracked_obj) destroy_tracked_object(tracked_obj); -// if(cascade) cvReleaseHaarClassifierCascade(&cascade); -// if(storage) cvReleaseMemStorage(&storage); + if(cascade) cvReleaseHaarClassifierCascade(&cascade); + if(storage) cvReleaseMemStorage(&storage); } @@ -114,20 +131,7 @@ void FaceBl0r::update() { image = cvCreateImage( cvSize(width,height), IPL_DEPTH_8U, 4 ); unsigned char* ipli = (unsigned char*)image->imageData; - int step = image->widthStep; - unsigned i, j; - for (i = 0; (i < height); i++) { - for (j = 0; (j < width); j++) { - -// ipli[(i*step)+j*4+0] = src[0]; - ipli[(i*step)+j*4+2] = src[2]; - ipli[(i*step)+j*4+1] = src[1]; - ipli[(i*step)+j*4+0] = src[0]; - //ipli += 4; - src += 4; - } - } - + memcpy(image->imageData, in, size); /* no face* @@ -137,60 +141,63 @@ void FaceBl0r::update() { - no more face no face* */ +#define CHECK 25 +#define RECHECK 25 + if(face_notfound>0) { - if(!face_found) { - face_rect = detect_face(image, cascade, storage); - // if face detected + if(face_notfound % CHECK == 0) + face_rect = detect_face(image, cascade, storage); + + // if no face detected if (!face_rect) { - memcpy(out,in,size); + face_notfound++; + memcpy(out, image->imageData, size); + return; + } else { + //track detected face with camshift + if(tracked_obj) + destroy_tracked_object(tracked_obj); + tracked_obj = create_tracked_object(image, face_rect); + face_notfound = 0; + face_found++; + } + + } + + if(face_found>0) { + //track the face in the new frame + face_box = camshift_track_face(image, tracked_obj); + + if( ( face_box.size.width < 10 ) // para + || (face_box.size.height < 10 ) + || (face_box.size.width > 500 ) + || (face_box.size.height > 500 ) + ) { + + face_found = 0; + face_notfound++; return; } - //track detected face with camshift - tracked_obj = create_tracked_object(image, face_rect); - face_found = true; - } - - //track the face in the new frame - face_box = camshift_track_face(image, tracked_obj); - - if( ( face_box.size.width < 10 ) - || (face_box.size.height <10 ) - || (face_box.size.width > 500 ) - || (face_box.size.height > 500 ) - ) { - - face_found = false; - return; - } //////////////////////////////////////////////////////////////////////// - cvSetImageROI (image, tracked_obj->prev_rect); + cvSetImageROI (image, tracked_obj->prev_rect); // cvSmooth (image, image, CV_BLUR, 22, 22, 0, 0); - cvSmooth (image, image, CV_BLUR, 11, 11, 0, 0); + cvSmooth (image, image, CV_BLUR, 23, 23, 0, 0); // cvSmooth (image, image, CV_GAUSSIAN, 11, 11, 0, 0); - cvResetImageROI (image); + cvResetImageROI (image); //////////////////////////////////////////////////////////////////////// - //outline face ellipse - cvEllipseBox(image, face_box, CV_RGB(255,0,0), 3, CV_AA, 0); + //outline face ellipse + cvEllipseBox(image, face_box, CV_RGB(255,0,0), 2, CV_AA, 0); -// memcpy(out,image->imageData,size); - src = (unsigned char *)in; - - for (i = 0; (i < height); i++) { - for (j = 0; (j < width); j++) { - -// ipli[(i*step)+j*4+0] = src[0]; - dst[3] = src[3]; - dst[2] = ipli[(i*step)+j*4+2]; - dst[1] = ipli[(i*step)+j*4+1]; - dst[0] = ipli[(i*step)+j*4+0]; - //ipli += 4; - dst += 4; - src += 4; - } + face_found++; + if(face_found % RECHECK == 0) + face_notfound = 1; // try recheck + } + memcpy(out, image->imageData, size); + cvReleaseImage(&image); } /* Given an image and a classider, detect and return region. */ @@ -202,8 +209,8 @@ CvRect* FaceBl0r::detect_face (IplImage* image, //get a sequence of faces in image CvSeq *faces = cvHaarDetectObjects(image, cascade, storage, - 1.1, //increase search scale by 10% each pass - 6, //require 6 neighbors + 1.2, //increase search scale by 50% each pass + 2, //require 2 neighbors CV_HAAR_DO_CANNY_PRUNING, //skip regions unlikely to contain a face cvSize(0, 0)); //use default face size from xml @@ -211,6 +218,7 @@ CvRect* FaceBl0r::detect_face (IplImage* image, if(faces && faces->total) rect = (CvRect*) cvGetSeqElem(faces, 0); + return rect; } From a1d7bb9edeb4f7261bdcd212a8ce244076a28fd5 Mon Sep 17 00:00:00 2001 From: Jaromil Date: Fri, 16 Jul 2010 12:56:40 +0100 Subject: [PATCH 5/5] opencv detection at configure definition of package_dir at configure --- configure.ac | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 0b114c7..b04c9ad 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,14 @@ LT_INIT([disable-static]) AC_CONFIG_HEADERS([include/config.h]) +if test "x${prefix}" = "xNONE"; then + prefix=${ac_default_prefix} +fi +PACKAGE_LIB_DIR="${prefix}/lib/frei0r-1" +AC_SUBST(PACKAGE_LIB_DIR) +PACKAGE_DATA_DIR="${prefix}/share/frei0r-1" +AC_SUBST(PACKAGE_DATA_DIR) + AC_MSG_CHECKING([host platform]) case $host_os in *linux*) @@ -89,7 +97,9 @@ HAVE_OPENCV=false PKG_CHECK_MODULES(OPENCV, opencv >= 1.0.0, [HAVE_OPENCV=true], [true]) AM_CONDITIONAL([HAVE_OPENCV], [test x$HAVE_OPENCV = xtrue]) if test x$HAVE_OPENCV = xtrue; then - OPENCV_CFLAGS="$OPENCV_CFLAGS -DOPENCV_PREFIX=`pkg-config opencv --variable=prefix`" +# OPENCV_CFLAGS="$OPENCV_CFLAGS -DOPENCV_PREFIX=`pkg-config opencv --variable=prefix`" + AC_DEFINE(HAVE_OPENCV,1,[compiled including opencv]) + AC_DEFINE(OPENCV_DATA_DIR,[${prefix}/share/opencv],opencv data prefix) fi AC_SUBST(HAVE_OPENCV) @@ -97,6 +107,7 @@ HAVE_GAVL=false PKG_CHECK_MODULES(GAVL, gavl >= 0.2.3, [HAVE_GAVL=true], [true]) AM_CONDITIONAL([HAVE_GAVL], [test x$HAVE_GAVL = xtrue]) + AC_CONFIG_FILES([ frei0r.pc Makefile @@ -122,6 +133,7 @@ fi if test x$HAVE_OPENCV = xtrue; then echo " - opencv: YES" +echo " data dir: $OPENCV_DATA_DIR" else echo " - opencv: NO" echo " opencv >= 1.0.0 not found - this program enables optional"