How can I deploy a face tracking algorithm to Raspberry Pi 4?

3 views (last 30 days)
Pietro Ventrella
Pietro Ventrella on 19 Oct 2021
Commented: Pietro Ventrella on 11 Nov 2021
I've created an algorithm to perform face tracking and recognition using a deep neural network. I've adapted the code in order to perform the code generation and it works if i run it from matlab. If i try to deploy it on the raspberry pi i always get some compilers error (see the question https://it.mathworks.com/matlabcentral/answers/887539-can-t-deploy-the-executable-on-raspberry-pi-and-matlab-coder-doesn-t-generate-the-elf-file) . I tried to split the code in different sections and to deploy them singularly: the section on the use of the deep neural network had no issues, but the section about the face detection and tracking gave me a lot of problems.
I've also tried this example https://it.mathworks.com/help/vision/ug/track-face-raspberry-pi2.html but i always had some problems related to the compilation.
Searching on the MATLAB forum i found that the Cascade Object Detector can only be used in simulations and cannot be used for code generation and deploy. How can i work around this problem?

Answers (2)

David Fink
David Fink on 19 Oct 2021
The Cascade Object Detector supports code generation, with some limitations:
In particular, for deployment, see the information on using OpenCV libraries.
Regarding the face tracking example, please reach out to MathWorks Technical Support, who can assist with setup and configuration issues.
  4 Comments
Pietro Ventrella
Pietro Ventrella on 26 Oct 2021
I've linked another question i've made some time ago and there are described all steps that brought me to those errors.
In the comments there is also the error stack.

Sign in to comment.


Rilwan Shekoni
Rilwan Shekoni on 11 Nov 2021
Hello @Pietro Ventrella, I am having a similar issue. Have you found a resolve?
Code.............
function rpiFace %#codegen
%Create raspi & webcam obj
raspiObj = raspi();
cam = webcam(raspiObj,2);
%Initialize DNN and the input size
net = coder.loadDeepLearningNetwork('FaceNet.mat');
inputSize = [227, 227, 1]; %net.Layers(1).InputSize(1:2);
%faceDetector = vision.CascadeObjectDetector;
%faceDetector.MergeThreshold = 8;
bboxes = [0,0,100,100];
text = 'No face detected';
start = tic;
fprintf('Initialing....\n');
while true
%Capture image from webcam
img = snapshot(cam);
imgSet = rgb2gray(img);
elapsedTime = toc(start);
%Process frames at 1 per second
if elapsedTime > 1
%Resize the image
imgSize = imresize(imgSet,inputSize(1:2));
%Classify the input image
[label,score] = classify(net,imgSize);
maxScore = max(score);
strlabel = cellstr(label);
text = sprintf('%s %f',strlabel{:},maxScore);
%bboxes = faceDetector(img);
start = tic;
end
%Display the predicted label
img = insertObjectAnnotation(img,'rectangle',bboxes,text,'TextBoxOpacity',0.9,'FontSize',8);
%img = insertShape(img,'rectangle',(bboxes));
%img = insertText(img,[0,0],text);
displayImage(raspiObj,img);
end
end
Error........
Error executing command "touch -c /home/pi/MATLAB_ws/R2020b/C/Users/RilSh/Documents/MATLAB/DL_Rpi/codegen/exe/piTestB/*.*;make -f piTestB_rtw.mk all MATLAB_WORKSPACE="/home/pi/MATLAB_ws/R2020b" -C /home/pi/MATLAB_ws/R2020b/C/Users/RilSh/Documents/MATLAB/DL_Rpi/codegen/exe/piTestB". Details:
........
??? Build error: C++ compiler produced errors. See the Build Log
for further details.
More information
Code generation failed: View Error Report

Community Treasure Hunt

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

Start Hunting!