Home / How To / MATLAB Easy Face Detection: 4 steps

MATLAB Easy Face Detection: 4 steps



MATLAB SCRIPT: clear all % clear all objects
clc% clear screen
FDetect = vision.CascadeObjectDetector; % Discover objects using the Viola-Jones algorithm

% Read the input image

image = imread (c: t % load the image using imread (file location name.jpg & # 39;)

BB = step (FDetect, image); % Returns Bounding Box values ​​based on number of objects [figure] figure,
imshow (I);

holds

for i = 1: size (BB, 1)

rectangle (& # 39; Position & # 39 ;, BB (i, :), & # 39; LineWidth & # 39 ;, 5, & # 39; Linestyle & # 39 ;, & # 39; ̵

1; & # 39 ;, & # 39; EdgeColor & # 39 ;, & # 39; r; & # 39;;; % r-red, g-green, b-blue

end

title ("Face Detection");

The result is as the image attached in this step itself

To count the number of faces detected:

] clear all % clear all objects
clc % clear screen

FDetect = vision.CascadeObjectDetector; % Detect objects using the Viola-Jones algorithm% Read the input image

image = imread (c: c: DeskPotter.jpg & # 39;); % load the image using imread (file location name.jpg & # 39;)

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

imshow (I);

holds

for i = 1: size (BB, 1)

rectangle (& # 39; Position & # 39 ;, BB (i, :), & # 39; LineWidth & # 39 ;, 5, & # 39; LineStyle & # 39 ;, & # 39; – & # 39 ;, & # 39; EdgeColor & # 39 ;, & # 39; r; #;; % r-red, g-green, b-blue

end

text 10,10, strcat (color {red} Number of faces = & # 39 ;, num2str (length (BB)))); This line gives you the counter

title (& # 39; Face Detection & # 39;); % title of the figure

holds off;


Source link