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

3 views (last 30 days)
I'm trying to execute this example: 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: 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 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.

Accepted Answer

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)
% 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('addIncludePaths', '~/opencv3.4/include');
if isempty(net)
net = coder.loadDeepLearningNetwork('squeezenet', 'squeezenet');
out = net.predict(in);

More Answers (1)

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.

Community Treasure Hunt

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

Start Hunting!