MATLAB Answers

Deep learning on Raspberry Pi Squeezenet example unable to find opencv library

3 views (last 30 days)
Matteo Lenti
Matteo Lenti on 7 Mar 2020
Answered: Matteo Lenti on 11 Mar 2020
I'm trying to execute this example: https://www.mathworks.com/help/coder/ug/code-generation-for-deep-learning-on-raspberry-pi.html and deploy it on a Raspberry Pi 3 Model B on which i have installed the Raspbian image provided by Mathworks. I followed the setup instructions to write the SD card with the Raspbian image. I connected the Raspberry Pi directly to the PC.
I have succesfully installed the ARM COMPUTE Library and correctly set-up the path on the Raspberry. I tried to do the same with opencv library: in this case I installed the library version 4.2.0 since the installation of the previous versions (3.1.0 and 3.2.0) failed. Also in this case I tried to set-up the path as specified here: https://www.mathworks.com/matlabcentral/answers/455591-matlab-coder-how-do-i-setup-the-environment-variables-on-arm-targets-to-point-to-the-arm-compute-li but probably I'm doing something wrong because I'm obtaining this error:
Error executing command "touch -c /home/pi/remoteBuildDir/MATLAB_ws/R2019b/C/Users/matte/Documents/MATLAB/Examples/R2019b/deeplearning_shared/CodeGenerationForDeepLearningOnRaspberryPiExample/codegen/exe/squeezenet_raspi_predict/*.*;make -f squeezenet_raspi_predict_rtw.mk all MATLAB_WORKSPACE="/home/pi/remoteBuildDir/MATLAB_ws/R2019b" -C /home/pi/remoteBuildDir/MATLAB_ws/R2019b/C/Users/matte/Documents/MATLAB/Examples/R2019b/deeplearning_shared/CodeGenerationForDeepLearningOnRaspberryPiExample/codegen/exe/squeezenet_raspi_predict". Details:
STDERR: /home/pi/remoteBuildDir/MATLAB_ws/R2019b/C/Users/matte/Documents/MATLAB/Examples/R2019b/deeplearning_shared/CodeGenerationForDeepLearningOnRaspberryPiExample/main_squeezenet_raspi.cpp:9:31: fatal error: /opencv2/opencv.hpp: No such file or directory
#include "/opencv2/opencv.hpp"
^
compilation terminated.
make: *** [main_squeezenet_raspi.cpp.o] Error 1
Has anyone had this problem? How did you solve?
Thank you.

  0 Comments

Sign in to comment.

Answers (2)

Hariprasad Ravishankar
Hariprasad Ravishankar on 9 Mar 2020
Hi Matteo,
It is likely that the compiler is unable to find the headers for opencv.
You can add the include path to opecv by using coder.updateBuildInfo as follows.
If opencv is installed under ~/opencv3.4 , you may include coder.updateBuildInfo('addIncludePaths', '~/opencv3.4/include')
function out = squeezenet_raspi_predict(in)
%#codegen
% A persistent object mynet is used to load the DAGNetwork object.
% At the first call to this function, the persistent object is constructed and
% set up. When the function is called subsequent times, the same object is reused
% to call predict on inputs, avoiding reconstructing and reloading the
% network object.
persistent net;
opencv_linkflags = '`pkg-config --cflags --libs opencv`';
coder.updateBuildInfo('addLinkFlags',opencv_linkflags);
coder.updateBuildInfo('addIncludePaths', '~/opencv3.4/include');
if isempty(net)
net = coder.loadDeepLearningNetwork('squeezenet', 'squeezenet');
end
out = net.predict(in);
end
Hari

  0 Comments

Sign in to comment.


Matteo Lenti
Matteo Lenti on 11 Mar 2020
Thank you for the reply.
I fixed the problem by formatting the SD card of my Raspberry and installing again the OS and the libraries. Now it works. Probably something went wrong when I installed the libraries the first time.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!