Question

In: Computer Science

Face detection code in Matlab

Face detection code in Matlab

Solutions

Expert Solution

Face Detection - MATLAB CODE(Image Processing)

  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);


Related Solutions

I am trying to do edge detection using matlab. I have posted code here. It does...
I am trying to do edge detection using matlab. I have posted code here. It does not give any error but it's not running it at all. So please help me to fix it and also exaplin each line of this code pls. Thanks! i = imread('C:\Users\Amanda\Desktop"); I = rgb2gray(1i); BW1 = edge(I,'prewitt'); BW2= edge(I,'sobel'); BW3= edge(I,'roberts'); subplot (2,2,1); imshow(I); title('original'); subplot(2,2,2); imshow(BW1); title('Prewitt'); subplot(2,2,3); imshow(BW2); title('Sobel'); subplot(2,2,4); imshow(BW3); title('Roberts');
Matlab code for Gauss Siedel with solved example in Matlab
Matlab code for Gauss Siedel with solved example in Matlab
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
solve in MATLAB and screenshot code ?′′ −??′ +??= ???(????−?????)
matlab code to graph an ecg
matlab code to graph an ecg
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
Fill in the blanks in the MATLAB code below.
Fill in the blanks in the MATLAB code below. (Do not type unnecessary words or blank spaces in your response. The correct answers are case-sensitive.) % Consider a row vector v. % Complete the lines of code below to find the average and standard deviation of the elements of vector v such that these two values are assigned to variables M and S, respectively. E = G =
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you...
Implement the steffenson method in matlab. The code must be in MATLAB DOnt answer if you cannot give correct MATLAB
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT