File Exchange

image thumbnail

Detect and Track Multiple Faces

version 1.1.0.1 (2.9 KB) by Dima Lisin
Detect and track multiple faces from live video.

53 Downloads

Updated 01 Sep 2016

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This is a simple system for detecting and tracking multiple faces from live video. It uses the Computer Vision System Toolbox and the Webcam Support Package. The system detects faces using the Viola-Jones algorithm, detects min-eigen corners within each face's bounding box, and tracks the corners using the Kanade-Lucas-Tomasi (KLT) algorithm. It re-detects the faces every 10 frames in order to correct the tracker and replenish the points.

Comments and Ratings (65)

Dear Dima Lisin
based on which article references that you are used to developed this algorithm?
best regards,

RAJ KUMAR

frans Thabo

wekel sigab

tao huang

That's cool!

Xyful Haqeem

Hi Dima..i had these errors when run the code;

Attempt to reference field of non-structure array.

Error in MultiObjectTracker/addDetections (line 109)
if this.PointTracker.isLocked();

Error in MultiObjectTracker2 (line 29)
tracker.addDetections(frame, bboxes);

How to overcome this errors? I hope you can reply asap, thanks :)

Gmal Ahmed

please, i need to modify pointTracker.m
I have error writing pointTracker.m

Kh. Islam

Charul Singh

Hi, I have tried for multiple people detection in a video but the problem I'm facing while detection is that the bounding box is not making for a specific number of people and also it continues to make bounding box again and again for the same number of people.could you please provide the steps where the loop should stop.

Undefined function 'thingSpeakRead' for input arguments of type
'double'.

Error in main_modv3 (line 16)

md khan

It breaks when there is no face in the frame.

Error using insertObjectAnnotation
Expected LABEL to be nonempty.

Error in detectAndTrackFaces (line 58)
displayFrame = insertObjectAnnotation(framergb, 'rectangle',...

Paul

Paul (view profile)

it is giving an error in the line

tracker = MultiObjectTrackerKLT;

guangming xu

if there is no object,it will break.

ALI JAVED

Chirag Shekar

yuki

yuki (view profile)

Hi,if I want to count how many faces in the video I had detected,what should I do?Could you provide me some good ideas?

Hi Dima, please write the steps to be followed to run this program...

Aj_ti

Aj_ti (view profile)

Hi,
how to make the program play the video before detect the face?
(since this code only display the sequence after detect the face).
Any idea?

How can i estimate the change in position eye by using this code?

Liang Seacom

Aj_ti

Aj_ti (view profile)

How to input images sequence?

Paul

Paul (view profile)

Dear sir,
Can the class file(MultiObjectTrackerKLT) be put in a matlab directory so that the script can be executed without keeping the both in same directory?
Or, is it possible to set the path for the class in the script?
Thanks & regards

Shubhobrata

Wonderful work is done Sir. Thanks a lot.

Dima Lisin

Hi Chaitanya,

You have to install the Webcam Support Package for this to work:
http://www.mathworks.com/help/supportpkg/usbwebcams/ug/installing-the-webcams-support-package.html

Chaitanya P

Undefined function or variable 'webcam'.

Error in detectAndTrackFaces (line 10)
vidObj = webcam;

Can u tell me whats wrong??
I am from computer science background..

mandy

mandy (view profile)

Hello Sir,
Thanks for uploading the codes.
After running the program, I am getting the below error:
Error using matlab.webcam.internal.WebcamController/getCurrentFrame
Time out occured while trying to get a frame from the webcam.

Error in webcam/snapshot (line 227)
[image, timestamp] = obj.CamController.getCurrentFrame();

Error in face_prac (line 16)
frame = snapshot(vidObj);

Can u please help me to debug this.
Thanks in advance.

Dima Lisin

Hi Osumanu,

Of course, there is. You would have to modify the code to crop each bounding box using imcrop(), and save it using imwrite().

Osumanu Ra-is

please is there a way to detect and track the face and save it into a folder for a trainning images

Dima Lisin

Hi Arun,

I am not sure what you mean. What you download is a .zip file. You then have to extract the .m files from it. On Windows, you should be able to do that from the Windows Explorer. On Linux, you can use the unzip command on the command prompt.

Alternatively, you can simply click on the links to the .m files on the right, and save them to your local machine one by one.

Arun Krishna

can somebode please tell me how to get the code from this file ? it seems encrypted

zhu jiagang

Thanks lot. It is very useful.

very usefull work, thank so much...

Hi! Thank you so much for this amazing file. Would there be any additional documentation or code on how to train your algorithm further? That is, would it be possible for us to cross-validate all the frames that are rendered to see how many of them belong to the same face?

yk s

yk s (view profile)

jialin lu

bhaskar appu

Dima Lisin

Hi Ajay,
It sounds like you may be running an older version of MATLAB. This example requires R2014a or later, and it also requires the Computer Vision System Toolbox.

Dima Lisin

Hi Mudassar,
It sounds like the directory containing the files needed for this example is not on your path. The easiest thing is to change your working directory to the one where you have downloaded the files.

Dima Lisin

Hi Mitesh,

To use webcam you have to install the Webcam Support Package, which is a type of plugin. The error message should contain a link, which will take you to the Support Package Installer.

hii this code not running at all in my system showing some line 100 annotation error what should i do

i am running but there is error saying
"Undefined function or variable 'MultiObjectTrackerKLT'."
Please help me

Mitesh

Mitesh (view profile)

i am try to run, but getting some ERROR >

Error using webcam (line 13)
MATLAB Support Package for Webcams has not been installed. Open Support Package Installer to install the Webcam
Support Package.

i am use MATLAB 2014a

Dima Lisin

@Carnie, all you have to do is use vision.VideoFileReader to read the video one frame at a time. The step() method of vision.VideoReader would replace the calls to snapshot().

Carine

Carine (view profile)

Hello, can anyone tell me what modifications should we make to this code to make it work on a video rather than webcam?

zeng changqi

@Dima Lisin,@Ben,
I'm not proficient at the MATLAB, and don't know how to add the code to turned off the camera. Could you help?

Bui

Bui (view profile)

Dima Lisin

@Ben, cool! Thanks for the tip.

Ben

Ben (view profile)

@Dima Lisin,

I found a way to handle this by using the onCleanup function as below:

%% Setup a clean up function to deal with Ctrl-C
fnCleanup = onCleanup(@() cleanup(videoPlayer, vidObj));

And then simply write a function like this:

function cleanup(videoPlayer, vidObj)
%% Clean up
if ~isempty(videoPlayer)
release(videoPlayer);
end;

if ~isempty(vidObj)
clear vidObj;
end

This works fine on my Mac.

Dima Lisin

Hi Ben. Thank you for trying it out! Unfortunately Ctrl-C cannot turn off the camera. To turn it off, you would have to clear vidObj. As of R2014b, you can use the isOpen() method of vision.VideoPlayer to exit gracefully when the player window is closed.

Ben

Ben (view profile)

One minor issue: the camera was not turned off after pressed "Ctrl+C" to exit.

Ben

Ben (view profile)

Thanks a lot for sharing! It ran very well on my first trial.

Dima Lisin

Hi Lee. Unfortunately that will not work. The code uses features from R2014a. The key component here is vision.PointTracker, which was introduced in R2012b. So, with some work, you can probably make it run on R2012b or later.

Lee Dan

How to do this code run on matlab r2007b version ?

Dima Lisin

Unfortunately, this code will not work in 2012a. With some tweaking you can probably make it work in 2012b, which is when vision.PointTracker was added.

Hi, I am kind of started for video analytic. Actually I am unable to run the code. Can i run this code on MATLAB 2012a?

Dima Lisin

@txrxmo, detectAndTrackFaces.m is a script, which you can run from the command prompt. It uses vision.VideoPlayer to display the video.

txrxmo

txrxmo (view profile)

Hi. This system can be used for a matlab GUI editor? Or its for command window?

vinothkumar r

good

Updates

1.1.0.1

Updated license

1.1.0.0

Updated the title.

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

MATLAB Online Live Editor Challenge

View the winning live scripts from faculty and students who participated in the recent challenge.

Learn more

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video