CODING


 LINK :-  https://drive.google.com/file/d/14cno2U3ccGUBAvjnylB_CNbFbvRAa8ze/view?usp=sharing


Explanation :-

 load('Mask.mat');

 %  1. Load labelled data file ,which created through image labelling

FaceMask = selectLabels(gTruth,'Mask');

% 2. Creating Variable FaceGtruth in which will store labels 'Face'

if isfolder(fullfile('TrainingData'))
cd TrainingData
else 
mkdir TrainingData
end
addpath('TrainingData');

% 3. if else condition, if means 'if full name TrainingData exist ,locate that file ' else here if TrainingData Files doesnt exits Make one and 
%        add it to the MATLAB Path

trainingData = objectDetectorTrainingData(Faceamsk,'SamplingFactor',1,'writeLocation','TrainingData');
detector = trainACFObjectDetector(trainingData,'NumStages',20);
save('Detector.mat','detector');

rmpath('TrainingData');

% Make variable trainingData in which will store and passing Parameters like FaceGtruth that is labels , Sampling factor means Examples Face images
% if sampling factor is 2 than 2times negative images taken, Writing location = as TrainingData Folder


load('Detector.mat');

% load Trained Object Detector

vidReader = VideoReader('C:\Users\ANKIT TIWARI\Desktop\Face detection UTUBE\face Rawdata\faceMask.mp4');

% VideoReader is for reading Video

vidPlayer = vision.DeployableVideoPlayer;

% Play Video in MATLAB
i = 1;

results = struct('Boxes',[],'Scores',[]);

% results is variable for storing bounding box i.e rectangle values

while(hasFrame(vidReader))
% While loop  
I = readFrame(vidReader);
[bboxes, scores] = detect(detector,I,'Threshold',1);
[~,idx] = max(scores);
results(i).Boxes = bboxes;
results(i).Scores = scores;
annotation = sprintf('Mask' ,detector.ModelName,scores(idx));
I = insertObjectAnnotation(I,'rectangle',bboxes(idx,:),annotation);
step(vidPlayer,I);
i =i+1;
end
results = struct2table(results);

Comments

Popular Posts