0% found this document useful (0 votes)
154 views2 pages

Face, Nose, Mouth, Eye Detection Code

The document demonstrates using MATLAB's vision toolbox to detect faces, noses, mouths, and eyes in an image using Viola-Jones object detection algorithms. It loads an image of Harry Potter, detects faces using the default cascade detector. It then detects noses, modifying the default 'MergeThreshold' parameter value for better detection results. Similarly, it detects mouths and eye pairs, drawing bounding boxes around each detected object on the original images and displaying the results.

Uploaded by

usman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views2 pages

Face, Nose, Mouth, Eye Detection Code

The document demonstrates using MATLAB's vision toolbox to detect faces, noses, mouths, and eyes in an image using Viola-Jones object detection algorithms. It loads an image of Harry Potter, detects faces using the default cascade detector. It then detects noses, modifying the default 'MergeThreshold' parameter value for better detection results. Similarly, it detects mouths and eye pairs, drawing bounding boxes around each detected object on the original images and displaying the results.

Uploaded by

usman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Face Detection Code

clear all
clc
%Detect objects using Viola-Jones Algorithm

%To detect Face


FDetect = [Link];

%Read the input image


I = imread('[Link]');

%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;
Nose detect

%To detect Nose


NoseDetect = [Link]('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;

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

[Link]('Nose','MergeThreshold',16);

The default syntax for Nose detection :

[Link]('Nose');
Based on the input image, we can modify the default values of the parameters passed
to [Link]. 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.

MOUTH DETECTION:

%To detect Mouth


MouthDetect = [Link]('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 = [Link]('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);

You might also like