opencv sample code compilation on Drive AGX linux directly

I found below write

This write said about method of build OpenCV on host machine for Drive AGX and Drive AGX Linux.
Then I have some question: If I build opencv on Drive AGX Linux, can I compile some opencv sample code (e.g ‘jpg file draw example’ provided by OpenCV official website) on Drive AGX Linux directly?

Hi pjhkb083gak9,
yes, you can compile natively on the Drive AGX Linux, though we encourage cross-compiling/debugging.
note also that profiling is available through Nsight System/Compute remotely only from a host computer.

Hi shayNV,

I have some problem still about directly compile on AGX Drive
after install opencv on AGX Drive follow the script on

I tried to compile opencv example code seen below


#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;
using namespace std;
int main( int argc, char** argv )
String imageName( “cat.jpg” ); // by default
if( argc > 1)
imageName = argv[1];
Mat image;
image = imread( imageName, IMREAD_COLOR ); // Read the file
if( image.empty() ) // Check for invalid input
cout << “Could not open or find the image” << std::endl ;
return -1;
namedWindow( “Display window”, WINDOW_AUTOSIZE ); // Create a window for display.
imshow( “Display window”, image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;

and I use this compile command :
g++ test.cpp -o test ‘pkg-config --libs opencv’

but enter this command, there are no process of compile. I see “>” mark on terminal and there are no more reactions.

Could you let me know the code which used when you try to compile and compile command?

And I have another question:
Can I compile another version of opencv (ex. opencv 3.4) on AGX Drive through changing the scripts? and Could you let me know?

Hi @pjhkb083gak9,
I think you have a problem in the ’ mark on your command.
please try the attached script to compile and let me know if this works. (238 Bytes)

also, you can verify the opencv installation for python if you want as follow:
#python2 -c ‘import cv2; print(“python2, opencv version:”); print(cv2.version)’
#python3 -c ‘import cv2; print(“python2, opencv version:”); print(cv2.version)’

Hi @pjhkb083gak9,
did this solved your problem?
can I close this topic?

HI @shayNV
I can not confirm your solution because another works.
I will reply after testing this method soon.