Madhu here for a holiday special post!


My friends (who ended up being my guinea pigs for this post) bought me a Raspberry Pi B+ and camera board as a gift for Thanksgiving. I thought I would surprise them by monitoring my office door (using their gift) to detect faces and display on my laptop screen. I used the Computer Vision Toolbox and wrote a simple MATLAB script to achieve my goal. 


%% The code that I used to perform Face Detection

% Set up your Raspberry Pi hardware peripherals access

mypi = raspi;

% Set up the Raspi camera board

myCam = cameraboard(mypi,'Resolution','320x240');

% Take a snap shot from the camera board

mySnapshot = snapshot(myCam);

% Plot the snapshot in a new figure window


hold on

% Create a Face detection object from the Computer Vision Toolbox's visio package

faceDetector = vision.CascadeObjectDetector();

% Detect objects using the Viola-Jones algorithm in the toolbox

bbox = step(faceDetector, mySnapshot);

% Insert an annotation to show detected face

imageOut = insertObjectAnnotation(mySnapshot,'rectangle',bbox,'Face');


title('Detected face');


Few minutes of coding was my return gift, which brought this smile on to their faces :-)