Face recognition in live video

28 views (last 30 days)
tamim boubou
tamim boubou on 22 Jul 2017
Commented: omar A.alghafoor on 17 Mar 2021
I need to detect and track faces using MatLab ....I'm suing MatLab 2014a,I tried the example on the following page but gave me an error It responds with the following message :
Undefined function 'isOpen' for input arguments of type
Here is the link to the page :
Any ideas ....plz help

Answers (2)

Gareth Thomas
Gareth Thomas on 22 Jul 2017
Does this work for you from the example? (This is the basic starting point of that demo).
%%Play a Video File
% Read video from a file and set up player object.
videoFReader = vision.VideoFileReader('viplanedeparture.mp4');
videoPlayer = vision.VideoPlayer;
Play video. Every call to the step method reads another frame.
while ~isDone(videoFReader)
frame = step(videoFReader);
Close the file reader and video player.
  1 Comment
omar A.alghafoor
omar A.alghafoor on 17 Mar 2021
Hi Mathworks team .
I am having two problems distinguishing faces using (face recognition convolutional neural network)
First: How to detect the intruder.
Second: The facial recognition overlaps between one person and another in the system.
The first test on grayscale images was good recognition, but on realtime of web camera the results are incorrect, knowing that I use a camera that has accuracy: 1024x570
note : all imge are grayscale .
Where is the defect in the code?
this my code for training dataset:
close all
%% variables
trainingNumFiles = 0.8;
faceData = imageDatastore('AutoCapturedFaces','IncludeSubfolders',true,'LabelSource','foldernames');
% Resize the images to the input size of the net
faceData.ReadFcn = @(loc)imresize(imread(loc),[227,227]);
% read one image to get pixel size
img = readimage(faceData,1);
% splitting the testing and training data
[trainFaceData,testFaceData] = splitEachLabel(faceData, ...
%% defining CNN parameters
% defining layers
layers = [imageInputLayer([size(img,1) size(img,2) 1])
%middle layers
convolution2dLayer(5,3,'Padding', 2, 'Stride',3)
%final layers
% options to train the network
options = trainingOptions('sgdm', ...
'MiniBatchSize', 40, ...
'InitialLearnRate', 1e-4, ...
'MaxEpochs', 25, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.875, ...
'LearnRateDropPeriod', 12, ...
'VerboseFrequency', 5);
% training the network
convnet = trainNetwork(trainFaceData,layers,options);
%% classifying
YTest = classify(convnet,testFaceData);
TTest = testFaceData.Labels;
%% Calculate the accuracy.
accuracy = sum(YTest == TTest)/numel(TTest)
save convnet
accuracy =

Sign in to comment.

tamim boubou
tamim boubou on 26 Jul 2017
No, it didn't work
the video file doesn't seem to be existed in my laptop

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!