Rhonda Software

Highest quality full cycle software development.

Expert in areas of Computer Vision, Multimedia, Messaging, Networking and others. Focused on embedded software development. Competent in building cross-platform solutions and distributed SW systems.

Offer standalone custom solutions as well as integration of existing products. Opened for outsourcing services.

Visit us at: http://www.rhondasoftware.com

Gender detection

Posted on : 22-07-2009 | By : Aleksey Kodubets | In : Demo, Demo video, Demo videos, YouTube

34

Description

In this post we present a video demo of the gender classifier. This classifier is adapted for frontal- and near to frontal-oriented faces. It is capable to provide the real-time gender recognition with the invariance to complicated lighting conditions. The foundation of the implemented method is an AdaBoost powered extraction of the gender-descriptive features along with the further separation of male / female subsets for learning of the decision-making routine.
The classifier works in the conjunction with face-detector and tries to classify all found faces on the each frame. The achieved accuracy of correct classification is 90-92%, though on small faces (less then 32×32 pixels) returned by face-detector the accuracy of gender recognition could reduce to 80-88%.

Comments (34)

I’m experimenting with the OpenCV library myself, and am very impressed with the fact that you can do gender detection. It would make my day if it were as easy as changing that haar classification xml file to yours. Is that something that you can share with me, or do I have to do all the hard work?? Hope its possible for you to share! ๐Ÿ˜€

If not just point me to some abstract research paper and i’ll keep trying ๐Ÿ™

Hi Jeremy,

>>it were as easy as changing that haar classification xml file to yours.

No, it is not haar cascade.

>>If not just point me to some abstract research paper and iโ€™ll keep trying

Sorry, we cannot do it. Most of articles are not for practical using. We cannot recommend a great one. The articles which reached best percent on feret database – cannot be applied on practice use case since actually there are a lot of variation of faces (lighting, pose etc). We attempted to use a lot of approaches. In this video we used our original method based on our experience && research in this field.

>>Is that something that you can share with me, or do I have to do all the hard work?? Hope its possible for you to share!

Our management doesn’t allow to share our code. We can answer on particular question… but cannot share our code (see ‘about’ page for details and contacts, you can discuss with them).

Thanks,
Aleksey

Thanks for responding so quickly! I’ll be looking into HaarTraining and reading over your blog a bit more. I’m definitely getting back to you with some questions. Thanks again for the help ๐Ÿ˜€

Hi,

Its a great work!! Congratulation ๐Ÿ™‚
Can you give me some hint on how you extracted the gender-descriptive features?
Also can you give some hint on which classification tool or some other thing you used for “learning of the decision-making routine” ?

Thanks,
Madhu

Thank you Aleksey.
Can you please tel me what features you extract? Is it eigenfaces?
also is it possible to direct me to some good paper for feature selection using adaboost? are there any kinds of adaboost softwares?

Thanks,
Madhu

Hi Madhu,

>>Can you please tel me what features you extract?

We cannot share this (see โ€˜aboutโ€™ page for details and contacts, you can discuss with our marketing/management).

>>Is it eigenfaces?

No, it is not. I guess with eigenfaces approach it is difficult to receive good quality of classification.

>>also is it possible to direct me to some good paper for feature selection using adaboost? are there any kinds of adaboost softwares?

Please re-read my reply above to Jeremy’s question. We cannot recommend the best article one since there is no such.

Aleksey

Thanks Aleksey ๐Ÿ™‚
I got some of my doubts cleared and also got some good inputs to work on. thank you.
Is it possible to share which face database you used? Or you created your own face data set?
Is there any database you can suggest to me?
Congratulations once again ๐Ÿ™‚

Thanks,
Madhu

Madhu,

We use specially prepared image database which is a combination of few databases (both payware && freeware) and also it contains own uniques images captured manually.

Good luck ๐Ÿ™‚

Aleksey

Thank you Aleksey

Hi,

I tried to use haartraining to train a gender classifier with female as positive and male as negative(about 500:400), but the quality is not so good. The positive image and negative image are very similar, and therefore isn’t a typical object detector. Will it really work?

What’s the number of the samples you would suggest, and is it necessary to use a mask to eliminate the background?

Thanks!

Hi Jacky,

>>Will it really work?

No, it will not. See Vasiliy’s comment: http://www.computer-vision-software.com/blog/2009/06/opencv-haartraining-detect-objects-using-haar-like-features/comment-page-1/#comment-184

>>Whatโ€™s the number of the samples you would suggest, and is it necessary to use a mask to eliminate the background?

[Aleksey] With our approach the background doesn’t impact result of classification seriously.

Aleksey

HI
I tried to use haartrainning por gender detection.
this is possible? or loosing my time?

send me hint!!

Hi Jedota,

Please look at: http://www.computer-vision-software.com/blog/2009/06/opencv-haartraining-detect-objects-using-haar-like-features/comment-page-1/#comment-184

Based on our experience, HaarTraining for gender classification is rather lost time.

another questions

how know, when my tranning is wrong?
is normal, it stay 24 hours in stage 6?

I need change opencv code for this?

thank

Hi Jedota,

Yes, it is normal. The haar training could take 6 days.

You don’t need to change this OpenCV code.

See the best posts on this subject:

http://www.computer-vision-software.com/blog/2009/06/parallel-world-of-opencv/

http://www.computer-vision-software.com/blog/2009/06/opencv-haartraining-detect-objects-using-haar-like-features/

thanks,
another questions

haartraining take the neg pictures and split it in 24×24 …..?

how to do for modificate this!
i need no split the imagens and take the entire picture

regards

Hello, there are some ways:

1) when prepare negative content, you can resize all neg images to 24×24
2) you can change source code icvGetHaarTrainingDataFromBG, not to crop 24×24 images from negative image, but use whole negative image

I need your help, I dont see any crop or resize in negative picture in this function!!

int icvGetHaarTrainingDataFromBG( CvHaarTrainingData* data, int first, int count,
CvIntHaarClassifier* cascade, double* acceptance_ratio, const char * filename = NULL )
{
CV_FUNCNAME( “icvGetHaarTrainingDataFromBG” );

__BEGIN__;

if (filename)
{
CvVecFile file;
short tmp = 0;

file.input = NULL;
if( filename ) file.input = fopen( filename, “rb” );

if( file.input != NULL )
{
fread( &file.count, sizeof( file.count ), 1, file.input );
fread( &file.vecsize, sizeof( file.vecsize ), 1, file.input );
fread( &tmp, sizeof( tmp ), 1, file.input );
fread( &tmp, sizeof( tmp ), 1, file.input );
if( !feof( file.input ) )
{
if( file.vecsize != data->winsize.width * data->winsize.height )
{
fclose( file.input );
CV_ERROR( CV_StsError, “Vec file sample size mismatch” );
}

file.last = 0;
file.vector = (short*) cvAlloc( sizeof( *file.vector ) * file.vecsize );
icvGetHaarTrainingData( data, first, count, cascade,
icvGetHaarTraininDataFromVecCallback, &file, NULL, acceptance_ratio);
cvFree( &file.vector );
}
fclose( file.input );
}
}
else
{
icvGetHaarTrainingData( data, first, count, cascade,
icvGetHaarTrainingDataFromBGCallback, NULL, NULL, acceptance_ratio);
}

__END__;

return count;

Hi

I need configure opencv_traincascade in opencv 2.0, but when choose LBP…the program Break!!

any hint!!

Hi jedota, without debug info, I could not help you.

when use this parameter with LBP the system crash and open visualstudio

C:\temp2>opencv_traincascade.exe -data data/cascade -vec data/vector.vec -bg neg
ative/infofile.txt -numPos 11 -numNeg 20 -numStages 5 -precalcValBufSize 700 -pr
ecalcIdxBufSize 700 -stageTypes BOOST -featureType LBP -w 24 -h 24 -bt GAB

but when select HAAR the system is ok!! I would like uses LBP system

C:\temp2>opencv_traincascade.exe -data data/cascade -vec data/vector.vec -bg neg
ative/infofile.txt -numPos 11 -numNeg 20 -numStages 5 -precalcValBufSize 700 -pr
ecalcIdxBufSize 700 -stageTypes BOOST -featureType HAAR -w 24 -h 24 -bt GAB -mode
BASIC

any hints?

Regards

[…] could not do it with OpenCV haartraining. That’s why for such classification, we used our own gender and attention classificators. Of course you can use Adaboost for this task, which is implemented in […]

Hi everyone.

I want to ask about Opencv_traincascade in opencv2.0.

When i trained the cascade ( i used Haar feature) it generate in cascade folder file .xml seperately for each stage. What should i do with them? . I meant that i should join these files together or leave it so. What tool use to join it if any ?

Thank you every one. Waiting for your answer soon.

who can help me ? plz.

Andrey Soldatov said:

Hi, David. Opencv_haartraining and opencv_traincascade during their work create temporary dirs (haartraining) or files (traincascade) for each stage of the cascade, so you can safely interrupt the process on each stage and then relaunch the program from the last complete step. At the end, they will combine all these dirs/files to one xml file. After that, you may delete all intermediate files. Was it helful?

Andrey Soldatov

Thank you for your answering Aleksey.

Could you help me make clear these points ? :

1) As you said, I can interrupt the training process and resume after that. Because It took long time,so i couldn’t wait until the process finish. I only took several cascade (about 6-8).
So, my question is : if I interrupt when process is at about stage of 7 , how can i use the file xml to be generated before? It don’t combine automatically, do it ? ( in this case i mention opencv_traincascade , with opencv_haartraining I know how to do already) .

2) The structure in file xml generated by opencv_traincascade is a little bit weird to me. It differ from the xml was generated by opencv_haartraining. So, Can I use this kind of xml for my old app usings opencv 1.0 ( about compatible ) ?

Thanks in advance. Waiting to hear you soon.

Hi, David,
> It donโ€™t combine automatically, do it.
It actually does it. Just run application with the same parameters and it will read all already built stages. You will see somewhat as “Stage 0 is loaded” if stage 0 results have been saved before. Unfortunately, opencv_traincascade has very bad checks of parameters and error conditions, so if something is wrong with calculations, it may be difficult to understand the reason.

Thanks Andrey.

Maybe i should continue working with haartraining 1.1 because it completely support openMP which is still not supported in opencv_traincascade or opencv_haartraining .

Hi, David, we didnโ€™t use openmp feature in haartraining (as we used slightly modified code with MPI support instead). But as I can see opencv_haartraining (opencv 2.0) has the same support of openmp as haartraining (opencv 1.1).

i want the source code for gender classification of images in open cv…….plz….

hey hi…. i’m trying to classify gender bt its not working properly…mostly it shows the csv’s file last entry as a gender..mostly.
how can i get atleast 70% accuracy. i need help plz.

/* Function For gender classification is given below*/

int gender_rec(int argc, const char *argv[])
{
// Get the path to your CSV.
string fn_csv = string(argv[2]);

// These vectors hold the images and corresponding labels.
vector images;
vector labels;

try {
read_csv(fn_csv, images, labels);
} catch (cv::Exception& e) {
cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;
// nothing more we can do
exit(1);
}

if(images.size() <= 1) {
string error_message = "This demo needs at least 2 images to work. Please add more images to your data set!";
CV_Error(CV_StsError, error_message);
}
// Get the height from the first image. We'll need this later in code to reshape the images to their original size:
int height = images[0].rows;
// The following lines simply get the last images from your dataset and remove it from the vector. This is done,
//so that the training data (which we learn the cv::FaceRecognizer on) and the test data we test the model with, do not overlap.
Mat testSample = images[images.size() – 1];
int testLabel = labels[labels.size() – 1];
images.pop_back();
labels.pop_back();

Ptr model = createEigenFaceRecognizer();
model->train(images, labels);
const string str=”gender.xml”;
model->save(str);
//model->load(str);
int predictedLabel = model->predict(testSample);

string result_message = format(“\n\nPredicted GENDER class = %d”, predictedLabel);
cout << result_message << endl;
cout<<"Predicted Gender is ";
if(predictedLabel==0)
{
cout<<"Female"<<endl;
}
else
{
cout<<"Male"<<endl;
}

return predictedLabel;
}

In csv file i have dedicate 0 for female and 1 for male.
my image database size is 92*112 in pgm format.
please help me to increase accuracy.

HELLO..
what is this error?
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in reshape, file /home/chaithra/OpenCV/opencv-2.4.9/modules/core/src/matrix.cpp, line 802
terminate called after throwing an instance of ‘cv::Exception’
what(): /home/chaithra/OpenCV/opencv-2.4.9/modules/core/src/matrix.cpp:802: error: (-13) The matrix is not continuous, thus its number of rows can not be changed in function reshape

Aborted (core dumped)

Hi jedota,
inside icvGetHaarTrainingDataFromBG, icvGetBackgroundImage is called, in it, 24×24 is cropped from whole negative image.

Write a comment