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
[url]https://www.amazon.com/gp/product/B07BN5FJZQ/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1[/url]
-
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.
-
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 -
Download the OpenCV4 repositories from GitHub
git clone GitHub - opencv/opencv: Open Source Computer Vision Library
git clone GitHub - opencv/opencv_contrib: Repository for OpenCV's extra modules -
Configure your python virtual environment and make it active. I am using Python v3.6.5.
-
Install numpy
pip install numpy -
Within the opencv folder create a build folder. Work out of that folder when issuing the cmake command
-
Issue the cmake command.
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D INSTALL_PYTHON_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=OFF
-D OPENCV_EXTRA_MODULES_PATH= āpath to your opencv_contrib/modules folderā
-D PYTHON_EXECUTABLE=~/.virtualenvs/xxxx/bin/python \ xxxx = virtual environment folder name
-D BUILD_EXAMPLES=ON ā¦ -
You should see "Build files have been written to: ālocation of your build folderā
-
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 -
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
freeze.
The compile will take awhile (1 to 2 hours). Walk away from your Jetson and hope. -
Hopefully you come back and see:
[100%] Built target opencv_python3 -
From the same Build directory issue the follow two commands
sudo make install
sudo ldconfig -
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/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so -
Validating install
python
import cv2
cv2.version
Your output should be: ā4.0.0-preā -
Congratulations, all is well in your Jetson world.