Tuesday, March 5, 2019

[OpenCV] Build OpenCV 3.4.4 on TX2

For the reason that I was curious about the performance of OpenCV on TX2 using GPU, I installed OpenCV 3.4.4 (this version and after will integrate with the inference engine) on my TX2 based on the following links.
https://jkjung-avt.github.io/opencv3-on-tx2/
https://www.learnopencv.com/install-opencv-3-4-4-on-ubuntu-16-04/



Step 1:
$ sudo apt-get dist-upgrade

### Update gcc apt package to the latest version (highly recommended)
$ sudo apt-get install --only-upgrade g++-5 cpp-5 gcc-5

### Install dependencies based on the Jetson Installing OpenCV Guide
$ sudo apt-get install build-essential make cmake cmake-curses-gui \
                       g++ libavformat-dev libavutil-dev \
                       libswscale-dev libv4l-dev libeigen3-dev \
                       libglew-dev libgtk2.0-dev

### Install dependencies for gstreamer stuffs
$ sudo apt-get install libdc1394-22-dev libxine2-dev \
                       libgstreamer1.0-dev \
                       libgstreamer-plugins-base1.0-dev

### Install additional dependencies according to the pyimageresearch article
$ 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 \
                       libatlas-base-dev gfortran
$ sudo apt-get install libopenblas-dev liblapack-dev liblapacke-dev

### Install Qt5 dependencies
$ sudo apt-get install qt5-default
Step 2: ( enable CUDA in cmake configuration )
$ export cvVersion=3.4.4

$ git clone https://github.com/opencv/opencv.git
$ cd opencv
$ git checkout $cvVersion
$ cd ..

$ git clone https://github.com/opencv/opencv_contrib.git
$ cd opencv_contrib
$ git checkout $cvVersion
$ cd ..

$ cd opencv
$ mkdir build
$ cd build

$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D WITH_CUDA=ON \
      -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-9.0 \
      -D CUDA_ARCH_BIN=6.2 \
      -D CUDA_ARCH_PTX="" \
      -D WITH_CUBLAS=ON \
      -D ENABLE_FAST_MATH=ON \
      -D CUDA_FAST_MATH=ON \
      -D ENABLE_NEON=ON \
      -D WITH_LIBV4L=ON \
      -D BUILD_TESTS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D BUILD_EXAMPLES=OFF \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON .. 

$ make -j4
$ sudo make install

I can try OpenCV 3.4.4 on TX2 using the following this post:
https://www.learnopencv.com/deep-learning-based-human-pose-estimation-using-opencv-cpp-python/
https://github.com/spmallick/learnopencv/tree/master/OpenPose

The performance is not good because TX2 takes 6.3 sec for 1 frame...Orz...
It seems that OpenCV 3 doesn't support CUDA too much. And the following link also mentioned " opencv3 package included in JetPack had no CUDA nor gstreamer support."
https://devtalk.nvidia.com/default/topic/1042056/jetson-tx2/jetpack-3-3-opencv-error-no-cuda-support-the-library-is-compiled-without-cuda-support-/post/5285618/#5285618


Here this one is running on my laptop and it takes 4.5 sec for 1 frame.

No comments: