Reputation: 11925
I installed the OpenCV 2.4.8 Java API to play with the face detection example that is given in the tutorial.
In the example, lbpcascade_frontalface.xml
-which is a CascadeClassifier
- works OK in detecting the female face image (lena.png
) that they provide. However, when I tried it on this random image from the web, the classifier produced the following image, missing 4 obvious(!) faces:
I am quite disappointed because I expected this (with the clear contrasts) to be a very easy image for detecting faces.
1) Coding in Java, is it possible to improve this classifier to detect all faces in this picture? Or do I need C++ for this?
2) I looked at OpenCV's CascadeClassification
web page and saw taht it is possible to train your own classifier. But the instructions are in C++. Has anyone done this using Java or is it only doable in C++?
Upvotes: 2
Views: 2215
Reputation: 2148
It is because the faceDetector the tutorial chose to use is lbpcascade_frontalface.xml which is not good enough, at least couldn't detect all the faces in the picture you used.
You may change to use haarcascade_frontalface_alt.xml under opencv-2.4.8\sources\data\haarcascades folder. Then all faces would be detected.
Here following is the result:, more details please refer to:http://www.pkuaas.org/?uid-1140-action-viewspace-itemid-3224
Upvotes: 1
Reputation: 1094
I have saved your image and this c++ code finds the missing 4 faces as well as all the others (note the different Haar cascade and the minimum size):
Mat im1 = imread("JuVIA.png", CV_LOAD_IMAGE_COLOR);
vector<Rect> faces;
CascadeClassifier cascade( "C:/local/opencv249/sources/data/haarcascades/haarcascade_frontalface_alt2.xml" );
cascade.detectMultiScale( im1, faces, 1.1, 2, 0| CV_HAAR_SCALE_IMAGE, Size(30, 30) );
for( vector<Rect>::const_iterator r = faces.begin(); r != faces.end(); r++ )
cv::rectangle( im1, *r, CV_RGB(255,0,0) );
imshow("in", im1);
imwrite( "miss4.png", im1);
waitKey();
Upvotes: 2
Reputation: 668
The training is not related to any programming language.
http://docs.opencv.org/doc/user_guide/ug_traincascade.html
You need only to use two already written programs included in the opencv library: createsamples and traincascade. You can use Haar and LBP features too, but the Haar features are slightly better for face detection. (And by the way: don't use haartraining).
Upvotes: 3