ubuntu 18.04 configuration opencv3.4.5+contrib+cuda10.0

Keywords: OpenCV sudo cmake Linux

1: Preparations

First, configure opencv3.4.5+contrib, so you only need to continue to configure cuda on this basis. For how to configure opencv-3.4.5 + opencv-3.4.5, see this blog: opencv-3.4.5+contrib
Then download cuda 10.0 at: CUDA 10.0 download

II. CUDA installation

install

Open the terminal at the location where you download cuda and enter:

sudo sh cuda_10.0.130_410.48_linux.run

Then go back crazy until it reaches 100%. Next, you will make a choice, as follows

Do you accept the previously read EULA?
accept
Install NVIDIA Accelerated Graphics Driver for linux-x86_64 410.48?
n
Install the CUDA 10.0 Toolkit?
y
Enter Toolkit Location?
[default is /usr/local/cuda-10.0]: 
Do you want to install a symbolic link at /usr/local/cuda?
y
Install the CUDA 10.0 Samples?
y
Enter CUDA Samples Location
[ default is /home/txz ]:

The following prompt:
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 10.0 functionality to work

Configure environment variables

In the home directory, press ctrl+h, find the. bashrc file and open it. Add the following contents to it:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.0/lib64
export PATH=$PATH:/usr/local/cuda-10.0/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.0

Switch to root with su, and then run

source ~/.bashrc

Check whether the installation is successful

Testing with program in cuda

cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make 
./deviceQuery

pass indicates that the installation was successful.

Three configuration CUDA version opencv

First, enter the folder where opencv is installed, then create a new folder, build CUDA, and then enter the folder.

cd opencv-3.4.5
mkdir build_cuda
cd build_cuda

Then cmake is performed. The cmake parameters are as follows:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-3.4.5/modules/ -D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so -D CUDA_ARCH_BIN=7.5 -D CUDA_ARCH_PTX=""   -D WITH_CUDA=ON -D WITH_TBB=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_NVCUVID=1 -D BUILD_opencv_cudacodec=OFF ..

The only thing to note is CUDA ﹣ arch ﹣ bin. This parameter can be input NVIDIA SMI through the terminal to get the video card information, and then Baidu can get the computing power. Or go NVIDIA official website Query the corresponding capabilities of your graphics card.
Then?

sudo make -j8
sudo make install

Configure environment variables

That is, configure the. bashrc file

    echo '/usr/local/lib' | sudo tee -a /etc/ld.so.conf.d/opencv.conf    
    sudo ldconfig    
    printf '# OpenCV\nPKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig\nexport PKG_CONFIG_PATH\n' >> ~/.bashrc    
    source ~/.bashrc    

ok, at this stage, we can basically declare the end, and finally test another wave.

test

General CMakeList.txt

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(test)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV 3.3.0 REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(opencv_example main.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})


Test code

using namespace std;
#include "opencv2/opencv.hpp"
#include "opencv2/core/cuda.hpp"
using namespace cv;
using namespace cv::cuda;
int main()
{
    int num_devices = cv::cuda::getCudaEnabledDeviceCount();

    cout<<num_devices<<endl;
}

The result is one.

Published 3 original articles, won praise 1, visited 62
Private letter follow

Posted by mwichmann4 on Wed, 15 Jan 2020 01:02:34 -0800