Follow by Email

Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Recent Posts

FACE DETECTION - MATLAB CODE

                                  Lets see how to detect face, nose, mouth and eyes using the MATLAB built-in class and function. Based on Viola-Jones face detection algorithm, the computer vision system toolbox contains vision.CascadeObjectDetector System object which detects objects based on above mentioned algorithm.
  
Prerequisite: Computer vision system toolbox

FACE DETECTION:

clear all
clc
%Detect objects using Viola-Jones Algorithm

%To detect Face
FDetect = vision.CascadeObjectDetector;

%Read the input image
I = imread('HarryPotter.jpg');

%Returns Bounding Box values based on number of objects
BB = step(FDetect,I);

figure,
imshow(I); hold on
for i = 1:size(BB,1)
    rectangle('Position',BB(i,:),'LineWidth',5,'LineStyle','-','EdgeColor','r');
end
title('Face Detection');
hold off;



The step(Detector,I) returns Bounding Box value that contains [x,y,Height,Width] of the objects of interest.


BB =

    52    38    73    73
   379    84    71    71
   198    57    72    72

NOSE DETECTION:


%To detect Nose
NoseDetect = vision.CascadeObjectDetector('Nose','MergeThreshold',16);



BB=step(NoseDetect,I);


figure,
imshow(I); hold on
for i = 1:size(BB,1)
    rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','b');
end
title('Nose Detection');
hold off;





EXPLANATION:


To denote the object of interest as 'nose', the argument  'Nose' is passed.

vision.CascadeObjectDetector('Nose','MergeThreshold',16);

The default syntax for Nose detection :
vision.CascadeObjectDetector('Nose');

Based on the input image, we can modify the default values of the parameters passed to vision.CascaseObjectDetector. Here the default value for 'MergeThreshold' is 4.

When default value for 'MergeThreshold' is used, the result is not correct.
Here there are more than one detection on Hermione.




To avoid multiple detection around an object, the 'MergeThreshold' value can be overridden. 


MOUTH DETECTION:



%To detect Mouth
MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',16);

BB=step(MouthDetect,I);


figure,
imshow(I); hold on
for i = 1:size(BB,1)
 rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','r');
end
title('Mouth Detection');
hold off;



EYE DETECTION:


%To detect Eyes
EyeDetect = vision.CascadeObjectDetector('EyePairBig');

%Read the input Image
I = imread('harry_potter.jpg');

BB=step(EyeDetect,I);



figure,imshow(I);
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b');
title('Eyes Detection');
Eyes=imcrop(I,BB);
figure,imshow(Eyes);







Cropped Image


I will discuss more about object detection and how to train detectors to identify object of our interest in my upcoming posts. Keep reading for updates.

like button Like "IMAGE PROCESSING" page

38 comments:

Rohini Bhargava said... Reply to comment

I have MATLAB of version R2010a which does not have the Computer vision system toolbox.How to detect eyes,mouth,nose in that case?

Aaron Angel said... Reply to comment

@Rohini Bhargava

You need to install 'Computer vision system toolbox' . For more information, visit http://www.mathworks.in/products/computer-vision/ .

Praga Deesan said... Reply to comment

@AaronAngel_ hi ...i am doing a mini project on matlab....pls help me... i need to capture image ,recognize the customer ,display his names.

Mitesh Ochaney said... Reply to comment

i hav matlab version 7. how do i perform face recognition on that.. please help..

Gul Sayyar Ali said... Reply to comment

can some0ne tell me how to install computer vivsion toolbox

nishant agrawal said... Reply to comment

i m doing a major projct on matlab... plz tell me how to campare or recognize captured image with the image stored in database and will display the name

nishant agrawal said... Reply to comment

i m doing my major project on matlab..plz tell me how to campare or recognize captured image with the image stored in database and will be display the name after successful matching...

Saxena Hidangmayum said... Reply to comment

thnk u very much....i was wondering how to detect the facial features.....it is interesting.

pallavi sharma said... Reply to comment

@nishant agrawalhaan yr ye he humein samajh nhe aa rhe tujhe pta chale to reply zarur karna yaad se bhoolna mat.....

銘仁^^ said... Reply to comment

Dear friend
what your Principle on ur mouth and eyes detection?

銘仁^^ said... Reply to comment

Dear friend
What Theory or Principle on your mouth and eyes ?
I want to do research in this area thanks more^^

mae nak said... Reply to comment

how to separate left eye and right eye?

ram said... Reply to comment

hey !!! can you help me in Iris localaization
?

Divya jax said... Reply to comment

Dear Friend. How to identify a face in snap?? Please response me

Divya jax said... Reply to comment

How to identify a face in snap???

Abhishek Gourav said... Reply to comment

how can i find the centre of the squares that detects eyes or nythiing???

ankita taparia said... Reply to comment

Hello!!!
I am an assistant professor in an engg college and need an account on MATLAB. Please tell me the procedure

Gaurav Lonkar said... Reply to comment

Can you give me the m file?

Nive Nivetha said... Reply to comment

but i dnt hv control vision toolbox,witout that vision cascade object detector method is not possible?wat can i do?

Bindu Pedapalli said... Reply to comment

computer vision system tool box in matlab which verision

KT said... Reply to comment

There's something wrong with mouth detection. It detects everything like eyes and nose. On the other great tutorial thanks!

Hana Anber said... Reply to comment

Could you please tell me are you using Viola and jones algorithm only or you used Adaboost beside ?

nevraa said... Reply to comment

It's very useful, thank you!

Siddhant Sharma said... Reply to comment

i have requested for the toolbox but how to install it.???

Malek said... Reply to comment

thank u

K@NN@N said... Reply to comment

Hi i m so interested in face reconition. Pls can you tell me how to capture the watch on the wrist of a person and to display the current time on that watch

K@NN@N said... Reply to comment

Hi i m interested in face and object recogonition. Pls can you tellme how to capture the image of the watch in the wrist of a person and to display the current time on the watch. Pls rply me its very urgent for the part of my project in matlab

K@NN@N said... Reply to comment

Hi i m so interested in face reconition. Pls can you tell me how to capture the watch on the wrist of a person and to display the current time on that watch

Azadeh T said... Reply to comment

thanks. I need to detect eyes, mouth and nose in different images simultaneousely. how can I set Mergethreshold value?

Azadeh T said... Reply to comment

I need to detect eyes, mouth and nose in many different images. but Mergethreshold value must be different in different images. what can J do?

Vivekanand Goud said... Reply to comment

hey this is awesome thanks for sharing this
can you help me out to detect the ears from the image using any matlab algorithm

thank you ..

Arslan mohal said... Reply to comment

How it can be trained by our own images????

Arslan mohal said... Reply to comment

How can We train it by our own images??
plx Reply

Aaron Angel said... Reply to comment

@Arslan mohalUse 'trainCascadeObjectDetector'

Vijay Bharath said... Reply to comment

I am wondering whether the same can be applied for the detection of say, number plates?

rosh said... Reply to comment

hai..I would like to know whether we can detect the eyes and nose in same window?? for that what we have to do for multiple detection in single image

Lich Le said... Reply to comment

hello!
I'm learning about identifying and catching face,. Can you help me?

Ganesh Babu said... Reply to comment

how can i create a code for facial expression

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com