Installing OpenCV4 on Xavier (Solved)

OpenCV4 comes out in October, but you can compile and install the prerelease now. OpenCV4 will have further optimizations, C+11 support, and improvements to the DNN module. In order to compile and install you will need around 14GB of free space. Therefore having a NVMe M.2 SSD installed is imperative. Yesterday I purchased a Samsung 970 EVO 250GB for $87.99

  1. I highly recommend using python virtual environments. Then you don’t have to worry about messing up your local python install and dependencies. I like virtualenv. Create one based on the latest Python3.

  2. Install OpenCV4 dependencies:
    sudo apt-get install build-essential cmake unzip pkg-config
    sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
    sudo apt-get install libxvidcore-dev libx264-dev
    sudo apt-get install libgtk-3-dev
    sudo apt-get install libatlas-base-dev gfortran
    sudo apt-get install python3-dev

  3. Download the OpenCV4 repositories from GitHub
    git clone
    git clone

  4. Configure your python virtual environment and make it active. I am using Python v3.6.5.

  5. Install numpy
    pip install numpy

  6. Within the opencv folder create a build folder. Work out of that folder when issuing the cmake command

  7. Issue the cmake command.
    -D CMAKE_INSTALL_PREFIX=/usr/local
    -D OPENCV_EXTRA_MODULES_PATH= ‘path to your opencv_contrib/modules folder’
    -D PYTHON_EXECUTABLE=~/.virtualenvs/xxxx/bin/python \ xxxx = virtual environment folder name

  8. You should see "Build files have been written to: ‘location of your build folder’

  9. The important thing to verify:
    Python 3 Interpreter: points to you virtual environment python instal
    Example: /home/nvidia/.virtualenvs/xxxx/bin/python3 (ver 3.6.5)
    Python 3 numpy: points to your virtual environment numpy install
    Example: /home/nvidia/.virtualenvs/xxxx/lib/python3.6/site-packages/numpy/core/include (ver 1.14.5)
    xxxx = name of your virtual environment

  10. Compile OpenCV4
    make -j4
    (4) is the number of CPU cores you want to devote to this task. I suppose you could use 8, but then maybe your Jetson will
    The compile will take awhile (1 to 2 hours). Walk away from your Jetson and hope.

  11. Hopefully you come back and see:
    [100%] Built target opencv_python3

  12. From the same Build directory issue the follow two commands
    sudo make install
    sudo ldconfig

  13. Create a symbolic link from the OpenCV install directory to your virtual environment
    cd ~/.virtualenvs/xxxx/lib/python3.6/site-packages/ xxxx = virtual environment folder name
    ln -s /usr/local/lib/python3.6/site-packages/

  14. Validating install
    import cv2
    Your output should be: ‘4.0.0-pre’

  15. Congratulations, all is well in your Jetson world.

1 Like


About installing the Samsung 970 EVO, could you share some instructions, do we need to disassemble the unit, and I am new to linux, we need to setup to mount the new drive.

I’ve attached an image of what the SSD looks like installed. You can remove the 4 screws from the two standoffs to gain access. Be very careful when pulling apart the Jetson from the carrier board. There is a fan cable connecting the two. With a little effort they do pull apart.

For mounting the drive I followed these instructions by JetsonHacks. This was done on a different type of SSD but the mounting procedure is still applicable.

Same drive as i have used on my TX2, backed up all my work files to it and crossing fingers that it will just “pop” up on the Xavier ;)

I ordered the drive

Dear All,

Thank you for the step by step guide to install OpenCV4 on the xavier. It worked like a charm.

I have a quick question on the flags used here during the cmake command.
I have seen on the jetsonhacks github repository ( that they explicitly call certain flags for OpenCV 3.4. (see script on the github)

I am particularly intrigued by the: -D WITH_CUDA=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON

Are they ON by default when we run the cmake command in the first post?
Or is there a way to check it?

Thanks a lot for your help.

Hi @JoesMaker,

You can check OpenCV build options with cmake command.

wget --no-check-certificate
mkdir -p opencv-3.4.1/build
cd opencv-3.4.1/build
cmake ..
cmake -LA | awk '{if(f)print} /-- Cache values/{f=1}'

Have anyone succeeded using opencv-java?

@naisy thanks a lot for your help. Useful command