top of page

Matlab face detection

  • MrHasif
  • Aug 15, 2017
  • 2 min read

So as the project goes the first thing we need is to detect the face in the video frame given as input,

I didn't found a way to do a live recording and detect face but i found a way to detect a face and by track where ever it moves that is really important .

The matlab code i found is in the link below and it's explanation but i am going to paste the code here

https://in.mathworks.com/help/vision/examples/face-detection-and-tracking-using-camshift.html?requestedDomain=www.mathworks.com

Code

% Create a cascade detector object.

faceDetector = vision.CascadeObjectDetector();

% Read a video frame and run the detector.

videoFileReader = vision.VideoFileReader('visionface.avi');

videoFrame = step(videoFileReader);

bbox = step(faceDetector, videoFrame);

% Draw the returned bounding box around the detected face.

videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');

figure, imshow(videoOut), title('Detected face');

% Get the skin tone information by extracting the Hue from the video frame

% converted to the HSV color space.

[hueChannel,~,~] = rgb2hsv(videoFrame);

% Display the Hue Channel data and draw the bounding box around the face.

figure, imshow(hueChannel), title('Hue channel data'); rectangle('Position',bbox(1,:),'LineWidth',2,'EdgeColor',[1 1 0])

% Detect the nose within the face region. The nose provides a more accurate

% measure of the skin tone because it does not contain any background

% pixels.

noseDetector = vision.CascadeObjectDetector('Nose', 'UseROI', true);

noseBBox = step(noseDetector, videoFrame, bbox(1,:));

% Create a tracker object.

tracker = vision.HistogramBasedTracker;

% Initialize the tracker histogram using the Hue channel pixels from the

% nose.

initializeObject(tracker, hueChannel, noseBBox(1,:));

% Create a video player object for displaying video frames.

videoInfo = info(videoFileReader);

videoPlayer = vision.VideoPlayer('Position',[300 300 videoInfo.VideoSize+30]);

% Track the face over successive video frames until the video is finished.

while ~isDone(videoFileReader)

% Extract the next video frame videoFrame = step(videoFileReader);

% RGB -> HSV [hueChannel,~,~] = rgb2hsv(videoFrame);

% Track using the Hue channel data

bbox = step(tracker, hueChannel);

% Insert a bounding box around the object being tracked

videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');

% Display the annotated video frame using the video player object

step(videoPlayer, videoOut);

end

% Release resources

release(videoFileReader);

release(videoPlayer);


 
 
 

Comments


Featured Posts
Check back soon
Once posts are published, you’ll see them here.
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
  • Facebook Social Icon
  • Twitter Social Icon
  • Google+ Social Icon
  • YouTube Social  Icon
  • Instagram Social Icon
bottom of page