Compiling OpenCV with CUDA support for working with onboard camera on Jetson TX1 – Technoinc India
Compiling OpenCV with CUDA support for working with onboard camera on jetson tx1
Though OpenCV that comes with Jetpack can work with new OpenCV installation, it is a good idea to remove old installation first and then start a new one. This will avoid unnecessary confusion. To accomplish that, the following steps have to be performed.
- Run the following command from the Terminal:
$ sudo apt-get purge libopencv*
- Make sure that all the packages installed are in their latest versions. If that is not the case then you can update it by running following two commands:
$ sudo apt-get update
$ sudo apt-get dist-upgrade
- The latest versions of cmake and gcc compiler are needed to compile OpenCV from the source so it can be installed by running following two commands:
$ sudo apt-get install –only-upgrade gcc-5 cpp-5 g++-5
$ sudo apt-get install build-essential make cmake cmake-curses-gui libglew-dev libgtk2.0-dev
- There are some dependencies that need to be installed to compile OpenCV with GStreamer support. This can be done by the following command:
$ sudo apt-get install libdc1394-22-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
- Download the source for the latest version of OpenCV and extract it in a folder by executing the following commands.
wget https://github.com/opencv/opencv/archive/3.4.0.zip -O opencv.zip
$ unzip opencv.zip
- Now go inside opencv folder and create the build directory. Then go inside this newly created build directory. These can be done by executing the following commands from the command prompt.
$ mkdir build
$ cd build
- The cmake command is used to compile opencv with CUDA support. Make sure WITH_CUDA flag is set to ON in this command. The CUDA_ARCH_BIN should be set to 5.3 for Jetson TX1 development board and 6.2 for Jetson TX2. The examples are not built to save time and space. The entire cmake command is as follows:
-D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=ON -D CUDA_ARCH_BIN=”5.3″ -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 ..
- It will start the configuration and creation of makefile. The cmake will create a makefile in the build directory after successful configuration.
- To compile OpenCV using this makefile execute the command make -j4 from the command window.
- After successful compilation, to install OpenCV you have to execute the command sudo make install from the command line.
If these steps are executed successfully then OpenCV 3.4.0 will be installed with CUDA and GStreamer support on Jetson TX1 and any computer vision application made using OpenCV can be deployed on it.