No BSD License  

Highlights from
Open CV Viola-Jones Face Detection in Matlab

4.25

4.2 | 27 ratings Rate this file 171 Downloads (last 30 days) File Size: 1.24 MB File ID: #19912

Open CV Viola-Jones Face Detection in Matlab

by

 

13 May 2008 (Updated )

Viola-Jones Fast Face Detection Mex Implementation

| Watch this File

File Information
Description

This zip file contains source code and windows executables for carrying out face detection on a gray scale image. The code implements Viola-Jones adaboosted algorithm for face detection by providing a mex implementation of OpenCV's face detector. Instructions for use and for compiling can be found in the Readme file.

Usage:

FaceDetect (<Haar Cascase XML file>, <Gray scale Image>)

The function returns Nx4 matrix. In case no faces were detected, N=1 and all four entries are -1. Otherwise, N=number of faces in the image and the vector contains the x, y, width and height information of the face.

Example,
A = imread ('lena.jpg', 'JPG');
Img = double (rgb2gray(A));
Face = FaceDetect('haarcascade_frontalface_alt2.xml',Img);

Acknowledgements

This file inspired Fast Eyetracking and Face Detection & Recognition System.

MATLAB release MATLAB 7.5 (R2007b)
Other requirements For compiling Mex Matlab 7.0.0 R14 or Matlab 7.5.0 R2007b Microsoft visual studio 2003 or 2005
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (87)
02 Jul 2014 SUMEET

Hey guys...the code is not running possibly because it contains openCV1.0 files. If anybody is using the same version of openCV then i hope the code will run. If anybody is using new version of openCV then try to find the equivalent files contained in the codes include,bin and lib folder.

Best of Luck

19 Jan 2014 saravanan.R

hi can some1 help me one the compiling,
i cant get it right
well according to the readme.txt included
i will need to select other compiler cos the native matlab compiler is not usable
but then after selecting i still get this message

Error using mex (line 206)
Unable to complete successfully.

please email me at saravanan.10393@gmail.com
thanks for the help

28 Oct 2013 hidangmayum saxena

tell me how to implement this code step by step

29 Jul 2013 qingyang zheng

thanks very good

22 Jul 2013 abukaf

when i am using with different images.........i hav found these errors............

Attempted to access Face(2); index out of bounds because numel(Face)=1.

Error in TestFaceDetection (line 9)
Rectangle = [Face(1) Face(2); Face(1)+Face(3) Face(2); Face(1)+Face(3) Face(2)+Face(4); Face(1) Face(2)+Face(4); Face(1) Face(2)];

13 Jun 2013 Meng onn choy

hi can some1 help me one the compiling,
i cant get it right
well according to the readme.txt included
i will need to select other compiler cos the native matlab compiler is not usable
but then after selecting i still get this message

Error using mex (line 206)
Unable to complete successfully.

please email me at mengonn87@yahoo.com
thanks for the help

06 Jun 2013 Revathi

I need viola jones method for feature detection in my project.plz anyone mail me. ks.revs@gmail.com

12 Dec 2012 Fa Fa

Hi,has somebody Trainingimages and Testimages for face detetection 24x24 Pixel?please send me
fadol@hotmail.de

18 Nov 2012 vns_dah_keke

Someone plz reupload this source code, it's deleted ???

14 Nov 2012 Bindu

FaceDetect.cpp(95) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
LINK : fatal error LNK1561: entry point must be defined
Sir, I am working on face reconstruction for which i needed this code for face detection. I used the code and i am getting the following error can anyone please help me find out the solution ?

C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'FaceDetect.cpp' failed.

Error using mex (line 206)
Unable to complete successfully.
Bindu

27 Jun 2012 Muhammad

In windows 7 I was trying to run getFeatures.m from File through FaceDetect.mexw32
I got the following error.
??? Invalid MEX-file 'c:\release\FaceDetect.mexw32': The
specified module could not be found.

This is how I solved the problem. When I had unzipped FaceDetect.zip, I had found
four folders (besides other files), which were bin, Include, lib and src.
www.mathworks.com/matlabcentral/fileexchange/19912
I decided to disregard these folders and instead decided to use similar folders from openCV2.1.

1: I downloaded openCV2.1 and installed it on
C drive. It created a folder opencv2.1
http://pt.sourceforge.jp/projects/sfnet_opencvlibrary/downloads/opencv-win/2.1/OpenCV-2.1.0-win.zip/
2: I ran Matlab as an administrator.
3. In Matalb, on the command line, I gave the command
mex -setup
It asked me, whether to search compilers, I said, yes.
It gave me two compilers (Visual Studio 2008) and Matlab.
I had on my computer, already installed Visual Studio 2008.
So, I chose this.

4. Then I copied the file FaceDetect.cpp to the folder opencv2.1
5. Then, within Matlab, I changed directory to opencv2.1
cd c:/opencv2.1
6. In this folder, on Matlab commandline I gave the following command.
mex FaceDetect.cpp -IInclude/opencv lib/*.lib -outdir bin/
7. It creates faeDetect.mexw32 in the bin directory.
8. Put this the path of c:/opencv2.1/bin in Matlab. I removed release/bin from
the pathlist of Matlab.
9. Now you can run this command, getFeatures.

05 Jun 2012 Stefan Grandl

Sorry, it's been a while since I've been using the code. So I cannot help you with more details, but the readme file and the other comments here should help you.

05 Jun 2012 Stefan Grandl

Sorry, it's been a while since I've been using the code. So I cannot help you with more details, but the readme file and the other comments here should help you.

01 May 2012 Awais

@Justlike2 i have placed my files on the bon folder but still i am getting the same error................

can you please briefly describe me the exact process.................because i am unable to understand the all process described in text file

thanks!

01 May 2012 Stefan Grandl

@Awais: concerning your first problem: I guess you have to place yourself in the directory where FaceDetect.cpp lies when running the code. Then he should find the file.

01 May 2012 Awais

I have done the Step one
but dont know where i have to change the path as mentioned below .............

2. Change path to the /src/ directory and issue the command
mex FaceDetect.cpp -I../Include/ ../lib/*.
lib -outdir ../bin/

Please Answer
Thanks

01 May 2012 Awais

Getting the error
dont know how to solve
can any body please help me

C:\PROGRA~2\MATLAB\R2009B\BIN\MEX.PL: Error: 'FaceDetect.cpp' not found.

??? Error using ==> mex at 221
Unable to complete successfully.

04 Apr 2012 Pavel M.

Hi,
thank you for the code. It is quite precise.
Can you answer the question:
When I compile the FaceDetect.cpp using mex in matlab I get:

mex FaceDetect.cpp -I../Include/ ../lib/*.lib -outdir ../bin/
Creating library C:\Users\Paul01\AppData\Local\Temp\mex_3vMOt7\templib.x and object C:\Users\Paul01\AppData\Local\Temp\mex_3vMOt7\templib.exp
FaceDetect.obj : error LNK2019: unresolved external symbol cvGetSeqElem referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvHaarDetectObjects referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvClearMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvEqualizeHist referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvReleaseImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvErode referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateStructuringElementEx referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvLoad referenced in function mexFunction
../bin/\FaceDetect.mexw64 : fatal error LNK1120: 10 unresolved externals

E:\MATLAB\BIN\MEX.PL: Error: Link of '..\bin\FaceDetect.mexw64' failed.

??? Error using ==> mex at 208
Unable to complete successfully.

Why such ?
I called mex -setup before and the compiler was setted up correctly.

Thank you.

17 Mar 2012 Chen Mr

Can someone tell me how to run this matlab code. In fact,After I looked ReadMe.txt still confused. So I hope anyone can help me step by step. If so,
that is very great!

I using Matlab 2011b and Microsoft Visual Studio 2010 Express.

15 Mar 2012 amerscs  
28 Jan 2012 Geethapriya

Hi,
I am using Windows 7, 64bit. I tried to run this code. I am getting errors because mex 32 is incompatible with my configuration. Anybody help me to finish the code successfully.

21 Jan 2012 Daksha

I am getting this error: 'Attempted to access Face(2); index out of bounds because numel(Face)=1.'
How to fix it ?

26 Nov 2011 Majid Hafeez

Creating library C:\USERS\MAJIDHZ\APPDATA\LOCAL\TEMP\MEX_LV~1\templib.x and object C:\USERS\MAJIDHZ\APPDATA\LOCAL\TEMP\MEX_LV~1\templib.exp
FaceDetect.obj : error LNK2019: unresolved external symbol _cvGetSeqElem referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvHaarDetectObjects referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvClearMemStorage referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvCreateMemStorage referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvEqualizeHist referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvReleaseImage referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvErode referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvCreateStructuringElementEx referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvCreateImage referenced in function _mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol _cvLoad referenced in function _mexFunction
../BIN/\FaceDetect.mexw32 : fatal error LNK1120: 10 unresolved externals

C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of '..\BIN\FaceDetect.mexw32' failed.

??? Error using ==> mex at 222
Unable to complete successfully.

According to "Readme.text", i can't understand with 2nd step of 'Instructions for compiling'.
any one can explain these lines'The compiled files are stored in the bin directory. Place these output files along with "cv100.dll" and "cxcore.dll"
in desired directory and set path appropriately in matlab.', while i done already set the path for facedetection project.
Any one can help me.............

21 Nov 2011 chaabani hazar

hi,i have installed the matlab R2009b with c++ 2008 to run the detector but tring that, a list of errors was appeared such
FaceDetect.cpp(165) : error C2059: erreur de syntaxeÿ: 'return'
FaceDetect.cpp(166) : error C2059: erreur de syntaxeÿ: '}'
FaceDetect.cpp(166) : error C2143: erreur de syntaxeÿ: absence de ';' avant '}'
FaceDetect.cpp(166) : error C2059: erreur de syntaxeÿ: '}'

C:\PROGRA~1\MATLAB\R2009B\BIN\MEX.PL: Error: Compile of 'FaceDetect.cpp' failed.

??? Error using ==> mex at 221
Unable to complete successfully.

can anyone help me?

24 May 2011 Tim Alyoshin  
20 May 2011 Matthew Shreve

Also, you may need to put a .dll in the directory you a running it from (you can download it from opencv source or just do a google search):

libguide40.dll

19 May 2011 Matthew Shreve

If you get the module error, do this and it will go away (it is different app, but same cause):

http://kb2.adobe.com/cps/403/kb403633.html

03 May 2011 Darli Myint Aung

pls, help me.I want to use face detection code. i read readme.txt. But,how can i use. I have many problems. I have Microsoft Visual version 2005 and Matlab version 7.0.0.4. pls, send me how to install with step by step explanation. pls, send me by email quickly. This code is very important for me.

29 Apr 2011 Randi Cabezas

For those trying to get this to work under x64. I took the trouble of downloading OpenCV 1.0, making the necessary changes and building the x64 libraries. I place them here : https://rapidshare.com/files/459764220/OpenCV_x64_libs.zip

I also included my own .mexw64 (Caution, this was build using Visual Studio, which means you need their runtime libraries)

09 Apr 2011 umesh vasnik

i have followed all the instructions in the readme file but still facing this error.using VS 2005 version 8,matlab 7.10.0 R2010a 64bit

mex FaceDetect.cpp -I../Include/ ../lib/*.lib -outdir ../bin/
Creating library C:\USERS\PC\APPDATA\LOCAL\TEMP\MEX_7P~1\templib.x and object C:\USERS\PC\APPDATA\LOCAL\TEMP\MEX_7P~1\templib.exp
FaceDetect.obj : error LNK2019: unresolved external symbol cvGetSeqElem referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvHaarDetectObjects referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvClearMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvEqualizeHist referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvReleaseImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvErode referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateStructuringElementEx referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvLoad referenced in function mexFunction
../BIN/\FaceDetect.mexw64 : fatal error LNK1120: 10 unresolved externals

C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of '..\BIN\FaceDetect.mexw64' failed.

??? Error using ==> mex at 222
Unable to complete successfully.

23 Mar 2011 Adrian

Dude: this is AWESOME!!!
By the way, kudos to Chris Garson for his step-by-step instructions on how to get this working with OpenCV1.0

27 Feb 2011 Dheerendra Tiwari

Thank you Sir!

16 Feb 2011 Stefan Grandl

Thanks for sharing. But I didn't get it working on Linux (Ubuntu 10.04) with the libraries from OpenCV 2.1. Maybe I have to look for some more solutions...

But a nice and fast way to detect faces on windows anyway!

18 Jan 2011 Albin

I followed the steps from Chris with the addition of the instructions for the compiler http://www.mathworks.com/support/solutions/en/data/1-6IJJ3L/?solution=1-6IJJ3L

The code is however not working properly.

The face is not even found correctly in the Lena image. I was hoping for a correct implementation to try my own built cascades in Matlab. Perhaps there is a quick fix to this problem. I guess the face detector is supposed to work if the MEX function is implemented correctly. There is nothing wrong with the cascade itself.

I will look into this. If someone finds a fix, please let me know.

30 Nov 2010 Idil Selin

Hi, I do need to use a face detector. I do have Microsoft Visaul C++ 2008 SP1 with OpenCV2 library. How can I compile the mex file? This is whay I do and what I get:
______________________________

mex FaceDetect.cpp -I../Include/ ../lib/*.lib -outdir ../bin/
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

C:\DOCUME~1\ELENA\LOCALS~1\TEMP\2\MEX_NN~1\FaceDetect.obj ..\LIB\cv.lib ..\LIB\cvhaartraining.lib ..\LIB\cxcore.lib
Creating library C:\DOCUME~1\ELENA\LOCALS~1\TEMP\2\MEX_NN~1\templib.x and object C:\DOCUME~1\ELENA\LOCALS~1\TEMP\2\MEX_NN~1\templib.exp
FaceDetect.obj : error LNK2019: unresolved external symbol cvGetSeqElem referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvHaarDetectObjects referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvClearMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvEqualizeHist referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvReleaseImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvErode referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateStructuringElementEx referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvLoad referenced in function mexFunction
../BIN/\FaceDetect.mexw64 : fatal error LNK1120: 10 unresolved externals

C:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Link of '..\BIN\FaceDetect.mexw64' failed.

??? Error using ==> mex at 218
Unable to complete successfully.
_____________________________
It looks to me obvious that I must include also the OPENCV library. But I am not confident with the syntax. The library is in
F:\Prog_Libraries\OpenCV2.0
What can I do?
Thank you! Idil

22 Nov 2010 Koos Spee

As I am getting some wrong detections, I was wondering how I can update the training stage. Can anybody point me in the right direction?

08 Oct 2010 Gada Farhan

Frank, I am interested in mex64 version. Could you please send the exectable file "FaceDetect.mex64" as soon as possible because
I need it urgently.

21 Sep 2010 TeckWee Chua

I believe the OpenCV is not installed correctly. Please refer to http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2008 for installation steps. Also, maybe you would like to recompile the mex file in Matlab again.

21 Sep 2010 Uma Parthavi Moravapalli

Can anyone help with the following errors i get wen i try to compile the code?
mex FaceDetect.cpp -I'C:\Program Files (x86)\OpenCV\otherlibs\highgui' -I'C:\Program Files (x86)\OpenCV\cxcore\include' -I'C:\Program Files (x86)\OpenCV\cv\include' -L'C:\Program Files (x86)\OpenCV\lib' -lcv -lcxcore -lhighgui -outdir C:\drivers\
Creating library C:\USERS\PARTHAVI\APPDATA\LOCAL\TEMP\MEX_C4~1\templib.x and object C:\USERS\PARTHAVI\APPDATA\LOCAL\TEMP\MEX_C4~1\templib.exp
FaceDetect.obj : error LNK2019: unresolved external symbol cvGetSeqElem referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvHaarDetectObjects referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvClearMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvEqualizeHist referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvReleaseImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvErode referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateStructuringElementEx referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvLoad referenced in function mexFunction
C:\DRIVERS\\FaceDetect.mexw64 : fatal error LNK1120: 10 unresolved externals

C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of 'C:\DRIVERS\FaceDetect.mexw64' failed.

??? Error using ==> mex at 222
Unable to complete successfully.

07 Sep 2010 Qiu dw

Thanks for sharing your code.

20 Aug 2010 budi anduk

I wanted a lot of face detection. Can you help my problem?

04 Aug 2010 TeckWee Chua

I have solved the performance difference between Matlab and OpenCV sample. It is due to improper data conversion from Matlab to Iplimage. The original "lena.jpg: works is beacause the image dimension is same for width and height. If you try to load other image with width != height then the image is not properly converted. You can detect this by adding cvShowImage("IncorrectIamge", gray); in the FaceDetect.cpp. When executed, the image appear to be slanted.

Now here is the solution:
Replace this line:

gray->imageData[j*NoOfCols+i] = value;

with this:

((uchar*)(gray->imageData+ gray->widthStep*j))[i] = value;

Hope this works for you, Cheers!

04 Aug 2010 TeckWee Chua

This Matlab version always fail except detecting the default "lena.jpg". However, the sample program in OpenCV always able to detect faces. Anyone can figure out what's wrong with the implementation?

22 Jul 2010 Huda Al-Ghaib

Hello..Can I get help?
After I compiled the code with visual Studio I tried to open the FaceDetect.mexw32 in the bin folder but it gave me the following error
Erro usng ==> open at 158
Can't edit the MEX-file 'C:\Documents and Settings....E\Viola code\bin\FaceDetect.mexw32'
I don't know what is the problem???

21 Jul 2010 YIQUN

Simple usage and it works. Good work!

09 Jul 2010 fabien milachon

I recompile my openCV 2.0 in 64 bit, redo the mex compilation, and now i have :
>> FaceDetect('haarcascade_frontalface_alt2.xml',I1)
??? Invalid MEX-file 'C:\Users\MilacH\Downloads\FaceDetect\bin\FaceDetect.mexw64':
C:\Users\MilacH\Downloads\FaceDetect\bin\FaceDetect.mexw64 n’est pas une application Win32 valide.

.
(In english: this is not a valide Win32 application).

Sure it s a 64 bit application !

Please, someone could help ? Thank you.

09 Jul 2010 BENHAMZA

Hi,
i have this message when compiling
>> mex FaceDetect.cpp -I../Include/ ../lib/*.lib -outdir ../bin/
LINK : fatal error LNK1181: cannot open input file 'user32.lib'

?????
Can somebody give us solution please
i installed Visual C++ 2005 express ans the MSDN
Matlab R2009a 7.8
Thnks
..............

Ok i yhink that i found the solution in this link:
http://www.mathworks.com/support/solutions/en/data/1-304969/index.html?product=ML&solution=1-304969

1)you have to download and install the SDK.
2)Add MSSdk like a variable environnement with value of:
"Path of your SDK lib"
My case it was this value: C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib

3) if after you have the same problem like "ddt99999 Tong " above, its not matter, just run the Algorithm with Matlab with the run Button (the green Play button)

When

08 Jul 2010 BENHAMZA

Hi,
i have this message when compiling
>> mex FaceDetect.cpp -I../Include/ ../lib/*.lib -outdir ../bin/
LINK : fatal error LNK1181: cannot open input file 'user32.lib'

?????
Can somebody give us solution please
i installed Visual C++ 2005 express ans the MSDN
Matlab R2009a 7.8
Thnks

08 Jul 2010 fabien milachon

i precise: it s 64 bit windows system

07 Jul 2010 fabien milachon

I follow all instructions but cannot compile it ...
On linux no problem, but on windows 7, matlab 2010a and VS 2008, i got linkage error LNK2019.

I'm lost, some of you have others solutions ?

thank you

15 Jun 2010 Adrien Brilhault

Hi, thanks for your code!
I've made it run using Matlab7.9, VSStudio2008,a and OpenCV 1.0 recompilng the FaceDetect.mexw32 file and it works but not in every situations. There are a lot of images with frontal faces that aren't recognized by the algorithm although they're big enought a quite easy to detect.

So I had a look at OpenCV 1.0 FaceDetect sample program, and it worked for those image where the matlab script couldn't find a face.

After looking at both c/cpp code (facedetect.c in the OpenCV/samples/c directory, and your facedetect.cpp) I couldn't find any difference in the processing method, except the 1.3 scalling in the OpenCV version (but even with this this change the matlab version didn't do better). Does anyone have the same problem? for instance if I run your program this image with this image the face is found : http://bit.ly/9WWYfD, but on this one : http://bit.ly/aNDlTt the matlab script can't detect a face, whereas OpenCV sample program does.

31 May 2010 Wilco Moerman

addendum: I found out when cleaning up that I missed some libraries. I was removing the macports version of opencv 2.0 which I had installed, but could not get to work with MATLAB mex files.

Apparently the software that I missed was installed when I tried the Macports-opencv 2.0 and the 64 bits version of opencv 2.1 used them as well.

So if you don't want to hunt down all the libraries and packages that opencv depends on, just install opencv from macports and the dependencies will come with it. Then just ignore the macports-opencv-2.0 (I guess you could even remove it, as long as the software it was dependent on, remains) and go for installing and compiling opencv 2.1 by yourself as explained in my previous post.

31 May 2010 Wilco Moerman

Hi, I have also tried to get this code working on a Mac with Snow Leopard (10.6) with no success, literally for days.

At first I tried the opencv binaries that are floating around the net, but to no avail. Installing opencv with macports also didn't work. (I could install the binaries and the macports version, but I could not get a mex file to compile using these opencv versions).

Finally I discovered that all these opencv versions are 32 bit, and I am using Snow Leopard (mac os 10.6) 64 bits version. I then downloaded opencv 2.1 from http://opencv.willowgarage.com/wiki/InstallGuide (get latest stable version for linux, has better 64 bit support) and did the install according to the readme file (same link). In step 4 I added -arch x86_64 to the cmake flags.

After installing opencv this way, I could compile the FaceDetect code using: mex FaceDetect.cpp -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lcvaux -lhighgui -lml -outdir ../bin/

thought this might be helpful for other mac users.

11 May 2010 mario

Hi I Have been trying to compile this file, and first I ran into chris garson and others' problem, and when i tried his solution that seems to work for other people, i get the following error

fatal error C1083: Cannot open include file: 'cv.h': No such file or
directory

I think this is a Visual C++ 2008 problem, the thing is that I already have the OpenCV up and running, including the OpenCV version of the Viola&jones...

Any clues?? thanks for the help

23 Apr 2010 Frank

I've sucessfuly built a mex64 version if anyone is interested.
I did notice after I used Visual Studio 2005 it compiled with no errors with the supplied command.

OpenCV 1.0 recompiled to 64bit
Visual Studio 2005

Cheers,

F

06 Apr 2010 Faten

why all these instructions ?
I want simple way to use this function to an image, not to Invade the world

24 Mar 2010 li zhang

Thanks very much, the solution is perfect. I finally can run the Mex file after spending a whole morning on searching webs. Just a reminder for others that in the step 4), It's "-IC:" Not "-I C", there is no space between I and C.

25 Feb 2010 Chris Garson

Weird, I just posted another message which appears to have been deleted. Anyway, I've modified the original code to load the image uint8, rather than double, since this added a bit of overhead. The resulting code exhibits execution times which are faster and more consistent than the original. I've posted the updated code along with a plot comparing the two versions here:
http://drop.io/xam7doz

25 Feb 2010 Chris Garson

Oh, and to those of you who were running into my problem with the missing dll's, you probably want to try recompiling from the source.
1) Download OpenCV 1.0 (NOT the latest 2.0 version)
2) Get Visual C++ 2008 if you don't have it
3) Run mex -setup, choose VC++2008 as the compiler
4) Compile with the following statement:
mex ./src/FaceDetect.cpp -IC:\OpenCV\otherlibs\highgui -IC:\OpenCV\cxcore\include -IC:\OpenCV\cv\include -LC:\OpenCV\lib -lcv -lcxcore -lhighgui
(changing the directories to point to wherever you have OpenCV Installed)
5) Copy cv100.dll, cxcore.dll, and libguide40.dll from your OpenVC\bin directory as well as haarcascade_frontalface_alt2.xml from OpenVC\data\haarcascades to wherever you want to run the mex file
6) Try running the mex
7) If MATLAB crashes, reload it, input the command:
setenv('KMP_DUPLICATE_LIB_OK','TRUE')
and try running the mex again

Hope this helps!

~Chris

13 Feb 2010 Joshua

Hi. I have the same problem as Ralu and Chris. I am also compiling using Microsoft Visual C++ 2008 Express, and following the instructions in Readme.txt.
My error:

Error in ==> TestFaceDetection at 8
Face = FaceDetect('haarcascade_frontalface_alt2.xml',Img);

??? Invalid MEX-file 'C:\Documents and Settings\Josh\My Documents\MATLAB\FaceDetectVnJ\bin\FaceDetect.mexw32': The specified module
could not be found.

Any advice from others who have solved this problem for themselves would be much appreciated!!

13 Jan 2010 Ralu

>Dear all,
>This looks like it could be very useful, but I am unable to get the >code to run. I've compiled using Visual C++ 2008 in MATLAB >r2009B and moved the .mexw32 file and both included .dlls to a >directory on my path. When I try to call the mex file, I get a >message saying "the specified module could not be found".

>I noticed that there's a note in the readme stating something >about "compiler-specific dll's", but this is unclear. Could this be >the source of my problem? If so, where can I find the necessary >dll's? Thank you for your time.

>~Chris

Hi!
I have the same problem as Chris, did you post somewhere any answer for this?

Thank you!

12 Jan 2010 Ferran Poveda

I've tested your code on Mac Os X, it works fine :)

1. Compile and install OpenCV (http://bit.ly/1j2pjL)

2. Config your mex compiler if you haven't done it already (mex -config)

3. Compile Sreekar's code with Matlab as easily as:
mex FaceDetect.cpp -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lcvaux -lhighgui -lml

Hope it helps to the Mac beginners ;)

And, thanks Sreekar for your code!!!

09 Jan 2010 Ashar Waseem

I tested this code and it runs fine. but one problem that I have faced while using it is that when I try to localize multiple faces in an image, it does not do it. However, it works great when an image has only one face. Any method to correct it??

14 Dec 2009 Marcin Eichner

easy to plug-in, it's working straight out of the box.
(checked with opencv 2.0)

08 Nov 2009 Raymond Cheng

Thanks for your sharing.

17 Sep 2009 Chris Garson

Dear all,
This looks like it could be very useful, but I am unable to get the code to run. I've compiled using Visual C++ 2008 in MATLAB r2009B and moved the .mexw32 file and both included .dlls to a directory on my path. When I try to call the mex file, I get a message saying "the specified module could not be found".

I noticed that there's a note in the readme stating something about "compiler-specific dll's", but this is unclear. Could this be the source of my problem? If so, where can I find the necessary dll's? Thank you for your time.

~Chris

14 Aug 2009 Thomas

Dear all,

This library is only provides binary libraries for Windows. For any other architecture you will certainly need your own libraries.

On linux, I can compile with
(in directory src)

mex FaceDetect.cpp -I../Include/ -LPATHTOOPENCVINSTALLATION/lib/ -lcvaux -lcv -lcxcore -lcvhaartraining -lhighgui -outdir ../bin/

then, I need to start matlab with LD_LIBRARY_PATH set:

export LD_LIBRARY_PATH=PATHTOOPENCVINSTALLATION/lib
matlab

and then it works just fine.

The same should work on mac, and probably there is a similar construct for 64bit windows.

cheers,
thomas

13 Aug 2009 Peter Aldrian  
21 Mar 2009 sowjanya sripada

hi,we r pursuing a project on face detection using this code.bt we r unable to understand the xml file.pls help us out

05 Mar 2009 Hanaa

Hi all!

I'm doing my final year project on 'Image Processing Methods for facial recognition using Matlab'. I've got Visual Studio 2005 background but never used MatLab before. I've just started on with research, video tutorials and reading.

Can anyone please help me with a guide, where can I start this from? Does this face detection code helps?

Your help would be very much appreciated! :))

07 Jan 2009 Ravi Varma

Hi All,
I need a help,regarding haartraining xml file
how to understand the xml file?.

31 Dec 2008 ddt99999 Tong

Hi all,

I try to setup the matlab file, the following errors come out:

mex FaceDetect.cpp -I../Include/ ../lib/*.lib -outdir ../bin/
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\ADMINI~1\AppData\Local\Temp\mex_xCuIeX\FaceDetect.obj ../lib/cv.lib ../lib/cvhaartraining.lib ../lib/cxcore.lib
Creating library C:\Users\ADMINI~1\AppData\Local\Temp\mex_xCuIeX\templib.x and object C:\Users\ADMINI~1\AppData\Local\Temp\mex_xCuIeX\templib.exp
FaceDetect.obj : error LNK2019: unresolved external symbol cvGetSeqElem referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvHaarDetectObjects referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvClearMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateMemStorage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvEqualizeHist referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvReleaseImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvErode referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateStructuringElementEx referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvCreateImage referenced in function mexFunction
FaceDetect.obj : error LNK2019: unresolved external symbol cvLoad referenced in function mexFunction
..\bin\FaceDetect.mexw64 : fatal error LNK1120: 10 unresolved externals

E:\MATLAB\R2008A\BIN\MEX.PL: Error: Link of '..\bin\FaceDetect.mexw64' failed.

??? Error using ==> mex at 207
Unable to complete successfully.

I have no clue about what's going on. Do I miss some files? It seems unlikely.

Thanks

18 Dec 2008 Alexander Huth

Hi all - I got this to compile on linux using the following command:

mex FaceDetect.cpp -I../Include -L <path to opencv libraries>/lib*so* -outdir ../bin

11 Dec 2008 sara

Hi Sreekar
can you explain implementation steps. I have not been able to the run this program I would be very gratefully if you could help me.
thank you

10 Nov 2008 Sreekar Krishna

Thanks everyone for the inputs about releasing memory. I am not using this program currently, but would be glad to incorporate these changes and post it back if I can get confirmation that certain fix is working.

30 Oct 2008 Der Baertige

Hi! We built a active face tracker in Simulink using this code. We changed the last lines of the cpp-Part to:

cvReleaseImage( &gray );
cvReleaseMemStorage(&storage);
cvReleaseHaarClassifierCascade(&cascade);

It runs on 6.2 fps with 288x384 Pixel Videoresolution. We tested it for over 20 minutes without crashing.

07 Oct 2008 Mohammad Ali Aktaa

Thanks,
I'll try it.

03 Oct 2008 Petter Strandmark

I have been able to fix (or at least reduce very significantly) the memory leak). I added the following lines at the end:

cvReleaseMemStorage(&storage);
cvRelease(reinterpret_cast<void**>(&cascade));
mxFree(input_buf);

And another line to remove the structuring element:

cvReleaseStructuringElement(&se);

It seems to work now. I might write my own library with these fixes and a possibility to cache the XML data.

03 Oct 2008 Petter Strandmark

There is a memory leak. This code leaks memory:

I = double(rgb2gray(imread('peppers.png')));
for i = 1:1000
FaceDetect('haarcascade_frontalface_alt2.xml',I);
end

I can see multiple objects in the .cpp file that don't seem to be release. But I haven't worked with OpenDV that much. For example, "cascade" and "storage" seem like pointers left on their own.

15 Sep 2008 Petter Strandmark

Thanks!

18 Jul 2008 berry giatra

hi ,my name is berry..do you help my?
i not understand source code face detection with source matlab 7..please send my e-mail..
thanks a lot of

12 Jun 2008 Thomas Mensink

Hi!
Do you have also a version for a Mac?
That should be great!

09 Jun 2008 fady michel

to Mohammad Ali Aktaa
the reason of getting the "out of memory" message is that the video object in expanding in the memory with each aquired frame so one solution to your problem is to clear the object every once and a while (NOT DELET IT) i suggest using the "Clear" command

clear vid

06 Jun 2008 Mohammad Ali Aktaa

Could you please tell me how to make it track the face.
I tried to make it track the face, but after about two minutes it stoped and show me a message (Insufficient memory(out of memory))
I could nit solve it.

% TRACKING

close all;
clear;
clc;

clear all;
imaqreset;
vid = videoinput('winvideo',1,'RGB24_320x240');

w=1;
while (w==1)
preview(vid);
frame = getsnapshot(vid);
image(frame)
i = frame;

Img = double (rgb2gray(i));
Face = FaceDetect('haarcascade_frontalface_alt2.xml',Img);
if(Face~=-1)
Rectangle = [Face(1) Face(2); Face(1)+Face(3) Face(2); Face(1)+Face(3) Face(2)+Face(4); Face(1) Face(2)+Face(4); Face(1) Face(2)];
truesize;
hold on;
plot (Rectangle(:,1), Rectangle(:,2), 'g');
hold off;
end

end

04 Jun 2008 Mohammad Ali Aktaa  
26 May 2008 john poler  
15 May 2008 Sreekar Krishna

Please note that the last but one line of the .cpp file in the 'src' directory - "delete (cascade)" is causing segmentation fault at runtime in the Matlab environment. Please comment or remove this line and recompile as per the "readme.txt" file instructions for a stable program. I will fix this and upload a new version as soon as I figure out how to modify the submission through the administrator.

Contact us