OpenCV Functions

question about using other feature of opencv. What is the best way to build upon the opencv addon?

I want to incorporate features like cvHaarDetectObjects to find faces and or other objects.

Thanks guys!

hi vanderlin :wink:

here u have the info to build the OpenCV addon.

http://openframeworks.cc/addons/opencv

if u want to incorporate other functionalities present in OpenCV but not in the Openframeworks addon you should try looking at the code of the current OF_opencvAddon and see how you can extend that classes…

for implementing cvHaarDetectObject … that is a function present in cvaux.dll as it’s an experimental functionality. You need to include and link against cvAux (.dll / .lib) in order to use these functions.

here you’ll find more information and a small example on how to use haar classifiers inside opencv :

http://www710.univ-lyon1.fr/~bouakaz/Op-…-ectObjects

hope it helps a bit …

e*

also, jqln here in ny has written the code for detecting faces and eyes, and I will ask her if she can clean it up. It’s our hope to be able to put this in the addon soon.

another point of note is that as we update the addon (see stefanix post on this)
for 0.05 it will be using opencv 1.0.

I’d use the ofCvContourFinder as a guide, for how a face detector could work - you pass in a grayscale image and the detector stores in an array the location of the faces it’s found. then similar to the contour finder, you can query for nFaces and get the locations of each face, etc.

I hope that’s helpful, I’ll see about getting a rough face detection sketch up to build off of. (we’ve done it before - see diego’s post in the examples section)…

take care!
zach

Awesome!
I have been working with the opencv addon for a bit but what to learn how to extend it to build in more features. This is a good start would love to see that example when possible.

Thanks again all!
-T

Hi all,

I’ve used stefanix example to track face with cvHaarDetectObjects. Is a Test example but if someone wants to test it…I’ve used comments of Zach to modify stefanix blobTrack example, but I’m not used sort pointers before add blobs in Blob’s vector.

Why ofCvContourFinder::findContours sort the pointers based on size ?
Code:

  
  
   // sort the pointers based on size  
   if( nCvSeqsFound > 0 ) {  
      qsort( cvSeqBlobs, nCvSeqsFound, sizeof(CvSeq*), qsort_carea_compare);  
   }  
  

source code: http://personales.ya.com/charli-e/src-Blob-face-traking.rar

computer vision libs (only added ofCvFaceFinder.cpp&h and #include “ofCvFaceFinder.h” in OF_CV_MAIN):
http://personales.ya.com/charli-e/computerVision.rar

Remember
add XML face, inside bin folder http://personales.ya.com/charli-e/haarcascade-frontalface-alt.xml
add in ofConstants.h for now … ofPoint and ofRectangle like stefanix post of blobTraking Test.

I hope this is helpful for someone.

c*

haha charlie –

awesome - can’t wait to try it !!

about your question, I asked for that question in a seperate thread, not tacked into another thread … :slight_smile:

http://forum.openframeworks.cc/t/experimental-ofopencv/393/31

we’d like to try to keep threads smaller and more focused.

at any rate, an answer:

_
we sort by size because you may request a certain number of blobs but in some cases opencv finds many more. we needed some criteria for choosing which blobs to pass back. size seems like a pretty good criteria, because often you care about bigger blobs as opposed to smaller ones. it also made sense to order the blobs biggest to smallest when we returned them, instead of returning them in the order that opencv found them. it’s pretty trivial to change the sort routine to sort b L to R, or by some other criteria, and if you want I can post code for that. _

if you have alternative suggestions for sorting, or would like to disable sorting, we’re happy to hear it.

take care,
zach

hope that helps!

this is awesome can’t wait to build

Hi ,
I understand the idea about not extend far… anyway, about findcountour size order…just one fast response. I didn’t know of several findcontour response. Order by size seems pretty method to take care about bigger blobs than smaller. I am more relaxed because in the case of the detection of faces isn’t necessary.

Thnks

c*

Love the face tracking works unreal. I started to play with more of the examples of HaarDetectObjects. There are a couple example in the opencv/data.

I’m not really understanding how it works very wild xml files. Have been reading this
http://www710.univ-lyon1.fr/~bouakaz/Op-…-mental.htm

I want to be able to make my own object detections. Anyone know anything about the
cascade files in HaarDetectObjects and a starting point for those.

I also cleaned up the example of facetracking. Removed the info about contours no need for face tracking. Charlie I like the use of the the blob tracker make since I kept that in there instead of make a new type for just faces.

http://www.toddvanderlin.com/OF/FaceTracker.zip

links that could be useful.
(own object classifiers - tutorial)
http://note.sonots.com/SciSoftware/haartraining.html

(images and xml for HaarTraining)
http://www.alereimondo.com.ar/OpenCV/34

by ^^
c*

[quote author=“vanderlin”]Love the face tracking works unreal. I started to play with more of the examples of HaarDetectObjects. There are a couple example in the opencv/data.

I’m not really understanding how it works very wild xml files. Have been reading this
http://www710.univ-lyon1.fr/~bouakaz/Op-…-mental.htm

I want to be able to make my own object detections. Anyone know anything about the
cascade files in HaarDetectObjects and a starting point for those.

I also cleaned up the example of facetracking. Removed the info about contours no need for face tracking. Charlie I like the use of the the blob tracker make since I kept that in there instead of make a new type for just faces.

http://www.toddvanderlin.com/OF/FaceTracker.zip[/quote]

Cool - I just got it running - it worked a treat!
A couple of things that might make the class a bit more useful:

Move all the stuff you are doing in the constructor to a setup function and let people pass in the xml haar face file.

something like this:

  
  
ofCvFaceFinder::setup(string haarFile) {  
	myMoments		= (CvMoments*)malloc( sizeof(CvMoments) );  
	cascade_name	=  ofToDataPath(haarFile);  // no need for ../../../ now :)  
        cascade		= (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );  
      
    if(!cascade) printf("ERROR: Could not load classifier cascade\n" );  
	reset();  
}  

Also - one thing that might be nice for people to specify is the scale factor (which you have hardcoded to 1.1) - this make a big difference for the size of the faces detected.

You can see the difference playing with the scale factor has with these two images:
http://fffff.at/fuckflickr/data/FFFFFAT-…-erdsAt.jpg
http://fffff.at/fuckflickr/data/FFFFFAT-…-erdsAt.jpg

Anyway it would be great to have this intergrated with stefan’s new ofOpenCV code.

– Stefan nice job on the code btw.
I totally freaked out for a sec - “where is setFromColorImage ???”
then I saw the overloaded operators which are dope!

Theo

Hi Theo , thanks for your comments.
Just I’ve update this new functions: setScaleHaar(float) , and setup (string) in FaceFinder.

source code:
http://personales.ya.com/charli-e/src-Blob-face-traking.rar

computer vision libs (only added ofCvFaceFinder.cpp&h and #include “ofCvFaceFinder.h” in OF_CV_MAIN):
http://personales.ya.com/charli-e/computerVision.rar
Remember: data/xml/haarcascade_frontalface_alt.xml

If you want to integrated, we can rename FaceFinder to HaarFinder or something similar to refer better that it’s possible to use any Haar xml object , if this is good configured.

About FindFaces, in haarExample of OpenCv says:
For a faster operation on real video images the settings are: scale_factor=1.2, min_neighbors=2, flags=CV_HAAR_DO_CANNY_PRUNING, min_size= (for example, ~1/4 to 1/16 of the image area in case of video conferencing)

By ^^
c*

I have also been working on a face and eye detector class

http://dev.chrisoshea.org/faces/play.ph-…-=320&h=240

I’m working on various things that I’ll show at the workshop in London

Great! Chrisoshea,

Impressive! Cool left and right eye detector! About eyes…I’m testing some of xml allocated in http://www.alereimondo.com.ar/OpenCV/34, but in left or right eyes detector doesn’t go fine. Have you any idea to improve this haardetect test?

Best Regards

Thanks

charlie I like the idea of changing the facetracking to haarTracking. Anyone working on that.

I think haarDetector makes more sense than faceDetector although face detector sounds cooler :smiley:

I have a couple of changes to make to charlie_e’s updated code (remove contours, datapath relative etc).

will post soon for you to check out.

theo

charli_e I am using the right eye and left eye haar files, rather than using the haar for both eyes together.

One thing I have in my class as well is set region of interest, as you only want to look for eyes within the upper half of the face & not the whole image, cutting down on the processing time.

I run both left and right eye haar on the face area, but then store them in one big list, any points on the left of the face = left eye. Then you need to filter to find the best eye, or like in Golans case fit an elipse to find the eye centre.

  
  
// set region of interest  
cvSetImageROI(mom.getCvImage(), cvRect(left, top, right, middleY) );  
  
.. find eyes  
  
// reset region of interest  
cvResetImageROI(mom.getCvImage());  
  

Bear in mind when you set the ROI, that a head of position x 250 might have an eye at 260, but because you have ROI it would be x position 10. So you need to add the head x position back on top of the eye x position to get it back to where it should be.

Thanks chrisoshea, that’s good point to extend features in HaarDetect Objects, are you using it in FudicialDetect object?

Anyway, about BlobTraking test from Stefanix. I’ve problems to controle blobs. Are any function to control undesired blobs? in FaceDetect, many times, haarObjects detects spontaneous ghost faces, and I would like to ignore them…

In my faceDetect test, I’m using external array of images , to draw one image over each face . To do it , i’m using Blob ON,OFF,MOVED only order var to control which Images are active and where draw them. Am I doing well?

Best Regards
charlie

while stefan can talk about the blob tracker, I’m not sure it’s such a good idea for face detection, because faces come more sporadically then tracked blobs.

the things you will need from it are different then what people need from it that are tracking blobs found by the contour finder.

when I helped with the project from diego (see examples) we used a different style of tracking for this reason. I don’t know if the source code for that project is still up, but I’ll ask him – I strongly believe you need to employ a different model then the blob tracker, since that tracker is looking from frame to frame and face detection can have many ghost frames, etc.

the model we used was instead of trying to link currently found faces to faces before, we created “ghosts” that hung around over multiple frames and tried to sync themselves with the current faces. the more they matched up, the stronger they got, the less they matched, the weaker they got (until fading out). When a new face came along that didn’t match a ghost, it made a new ghost. Thus faces from 5 frames ago could be matched again. with the blob tracker, that wouldn’t happen.

(it occurs to me that I use ghost here twice : (a) ghost frames to talk about faces that appear once in a while and (b) ghost trackers that hang out and leech energy off of current faces – will try to come up with better terminology… anyone?)

hope that helps –

take care!
zach

Ghosts are a really big issue with faces and zachs method sounds good.

diego code is here, but it doesn’t including ghosts:
http://forum.openframeworks.cc/t/face-tracking/167/0

I’ve cleaned up the haar detector a bit to remove all the blob and contour info; ofCvHaarFinder, and will put together a ofCvFaceFinder class. maybe we should have ofCvFaceTracker class as part of that, to deal with ghosts.