Installing OpenCV 3.4.0 on the Nvidia Jetson Tx2
When using the Jetson Tx2, I found that building OpenCV from source has been beneficial. This allows for other configurations for OpenCV that the Jetson JetPack does not support. For the most part, I followed the tutorial linked here.
The first step is to remove any instances of OpenCV that may already been previously installed on the Jetson. You can do this by applying this command:
sudo apt-get purge libopencv*
It is recommended that you also purge the pre-downloaded (from JetPack) numpy and re-install it using pip:
sudo apt-get purge python-numpy
sudo apt autoremove
sudo apt-get update
sudo apt-get upgrade
I only installed OpenCV 3.4.0 for Python3. Here are the commands I used below:
sudo apt-get install --only-upgrade g++-5 cpp-5 gcc-5
sudo apt-get install build-essential make cmake cmake-curses-gui \
g++ libavformat-dev libavutil-dev \
libswscale-dev libv4l-dev libeigen3-dev \
sudo apt-get install libdc1394-22-dev libxine2-dev \
sudo apt-get install libjpeg8-dev libjpeg-turbo8-dev libtiff5-dev \
libjasper-dev libpng12-dev libavcodec-dev
sudo apt-get install libxvidcore-dev libx264-dev libgtk-3-dev \
sudo apt-get install libopenblas-dev liblapack-dev liblapacke-dev
sudo apt-get install qt5-default
sudo apt-get install python3-dev python3-pip python3-tk
sudo pip3 install numpy
sudo pip3 install matplotlib
Some of these libraries do not have support for the Jetson Tx2, and I haven’t run into problems in which it stopped my OpenCV from compiling, so I have not taken issue with the commands above. After successfully installing matplotlib, you’ll need to edit the matplotlibrc file and modify the backend to be “backend : TkAgg”. It may not be in the exact same place but I used the following command:
sudo vim /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/matplotlibrc
There seems to be an issue with Jetson where you have to apply a particular patch. It deals with fixing a symbolic link. Now, when I was trying to apply this, it actually would not let me make OpenCV successfully. I would try without fixing it first because I think Nvidia actually resolved this problem (albeit, I am not 100% confident on this). I installed curl so that I could do the following (and get OpenCV).
sudo apt-get install -y curl
curl -L https://github.com/opencv/opencv/archive/3.4.0.zip -o opencv-3.4.0.zip
If this works, make a directory inside of this folder and cd into it.
My cmake is as follows; however, you can make it how you want:
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="6.2" -D CUDA_ARCH_PTX="" -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
After doing this, you can find cv2 (if you are using Python3.6) in /python3.6/site-packages. I found that the blog post had it in dist-packages for Python3.5 and it took me a while to find where it was located on mine. Last two commands:
sudo make install
Hopefully, you install it successfully and you would have installed OpenCV 3.4.0 on your Nvidia Jetson Tx2.