Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Monica Houston
Published © GPL3+

Face Recognition Using Mathworks on Raspberry Pi

Connect your Raspberry Pi and the Pi Camera to MATLAB to run facial recognition.

BeginnerFull instructions provided2 hours7,598

Things used in this project

Story

Read more

Code

facedetection.m

MATLAB
%% set up your raspberry pi hardware peripherals access
mypi = raspi();
myCam = cameraboard(mypi)

%% Image acquisiton & plotting

mySnap = snapshot(myCam)
imshow(mySnap)
hold on

%% Detect face and insert a rectangle around the face

fD = vision.CascadeObjectDetector(); %% from computer vision toolbox
bbox = step(fD, mySnap);
imageOut = insertObjectAnnotation(mySnap, 'rectangle', bbox, 'Face');
imshow(imageOut);

%% Repeat in a loop to make it look like face detection in video
flag = 1;

while flag
clearvars -except mypi myCam flag
mySnap = snapshot(myCam);
imshow(mySnap);
hold on
fD = vision.CascadeObjectDetector();
bbox = step(fD, mySnap);
imageOut = insertObjectAnnotation(mySnap, 'rectangle', bbox, 'Face');
imshow(imageOut);
title('Detected Face');
drawnow %% refreshes the image window after every loop
end
No preview (download only).

Credits

Monica Houston

Monica Houston

77 projects • 453 followers
I don't live on a boat anymore.

Comments