GPU Coder Error with OpenCV

3 views (last 30 days)
I'm trying to use the example "Semantic Segmentation on NVIDIA DRIVE" just modifying it to be executing on a Jetson Nano board. I train my own network, then Ijust load my network instead of the one defined on the example, nevertheless when I try to deploy it to the Nano I have the following error:
/main.cu:10:10: fatal error: opencv2/opencv.hpp: No such file or directory
#include "opencv2/opencv.hpp"
I check on the nano to see if the installation of OpenCV is correct:
alvaro@alvaro-nano:~$ pkg-config --modversion opencv
2.4.9
The installation is correct, also when I call the code generation I pass the path as an -I command:
codegen -config cfg autoSemanticSegmentation -args {img} -I /usr/include/opencv4 -report -v
And I saw that this is inluded on the generated make file.
How can I fix this issue to be able to compile and execute the example on the Nano?
  4 Comments
Walter Roberson
Walter Roberson on 11 Mar 2020
alvaro@alvaro-nano:~$ pkg-config --modversion opencv
opencv pkg is not the same as openvc2 pkg. opencv still exists as a package
Alvaro Izaguirre Serrano
Alvaro Izaguirre Serrano on 11 Mar 2020
yes, actually I work with opencv4 and now I'm able to compile

Sign in to comment.

Accepted Answer

Hariprasad Ravishankar
Hariprasad Ravishankar on 9 Mar 2020
Hi Alvaro,
I believe the issue is due to the line below,
cfg.CustomInclude = fullfile('/usr/include/opencv4');
For hardware deployment workflow, cfg.CustomInclude prepends the host working directory structure to create the following structure
-I/home/alvaro/remoteBuildDir/MATLAB_ws/R2019b/usr/include/opencv4
-I/home/alvaro/remoteBuildDir/MATLAB_ws/R2019b/usr/include/opencv4/opencv2
Rather than,
-I/usr/include/opencv4
-I/usr/include/opencv4/opencv2
To resolve the issue you can try one of the two approaches
1) Rename /usr/include/opencv4/opencv2 to /usr/include/opencv2
mv /usr/include/opencv4/opencv2 /usr/include/opencv2
This should ensure that the compiler is able to find opencv2/opencv.hpp under /usr/include/
2) Use coder.updateBuildInfo('addIncludePaths', '/usr/include/opencv4/');
function out = segnet_predict(in)
%#codegen
% A persistent object mynet is used to load the DAG network object.
% At the first call to this function, the persistent object is constructed and
% setup. When the function is called subsequent times, the same object is reused
% to call predict on inputs, thus avoiding reconstructing and reloading the
% network object.
% Update buildinfo with the OpenCV library flags.
opencv_link_flags = '`pkg-config --cflags --libs opencv`';
coder.updateBuildInfo('addLinkFlags',opencv_link_flags);
coder.updateBuildInfo('addIncludePaths', '/usr/include/opencv4/');
persistent mynet;
if isempty(mynet)
mynet = coder.loadDeepLearningNetwork('SegNet.mat');
end
% pass in input
out = predict(mynet,in);
Hari
  13 Comments
Hariprasad Ravishankar
Hariprasad Ravishankar on 16 Mar 2020
Hi David,
Thats good to know. We will look into updating the example to work with opencv4 in a future release.
Hari
Rodrigo Botelho
Rodrigo Botelho on 31 Jul 2022
Edited: Rodrigo Botelho on 8 Jul 2024
Hi, Hariprasad,
I'm trying the Segnet demo from the Support Package, but I'm running into the same problem with opencv4.
I've tried the suggestion no.2, but I'm getting the same error.
Any udpates on how to use this demo with Opencv4?
rcbb

Sign in to comment.

More Answers (2)

Liwei
Liwei on 8 Jul 2024
I am using the Matlab 2023b, I have no issue to compile the InceptionV3 classification to the Nvidia Jetson orin 32 GB. Now I got NVIDIA JETSON ORIN 64 BIT, I compiled the executable using GPU coder. I got issue. I upgraded matlab to 2024b, I have the same issue.
i am using the following codes
opencv_linkflags = '`pkg-config --cflags --libs opencv4`';
coder.updateBuildInfo('addLinkFlags',opencv_linkflags);
coder.updateBuildInfo('addIncludePaths', '/usr/include/opencv4/'); %both remove or add this line, the GPU coder compilation process does not work.
fatal error: opencv2/imgproc/imgproc.hpp: No such file or directory
57 | #include <opencv2/imgproc/imgproc.hpp>
Any idea to help solve the issue?

Ramakrishna Mandalapu
Ramakrishna Mandalapu on 12 Sep 2024
Hi Lewei,
Can you check if you have OpenCV installed?
please run the below command on the terminal of the NVIDIA DRIVE hardware
pkg-config --cflags --libs opencv4
If not installed then please install.
Thanks

Categories

Find more on Deployment in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!