手把手带你在Linux上安装带GPU加速的opencv库(C++版本)_opencv linux-CSDN博客
cmake \-D CMAKE_BUILD_TYPE=RELEASE \-D OPENCV_GENERATE_PKGCONFIG=ON \-D CMAKE_INSTALL_PREFIX=/usr/local \-D OPENCV_EXTRA_MODULES_PATH=/home/hwj/opencv/opencv_contrib/modules \-D CUDA_CUDA_LIBRARY=/usr/local/cuda/lib64/stubs/libcuda.so \-D CUDA_ARCH_BIN=8.9 \-D CUDA_ARCH_PTX="" \-D WITH_CUDA=ON \-D WITH_TBB=ON \-D BUILD_NEW_PYTHON_SUPPORT=ON \-D WITH_V4L=ON \-D INSTALL_C_EXAMPLES=ON \-D INSTALL_PYTHON_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=ON \-D BUILD_opencv_cudacodec=OFF \-D WITH_GSTREAMER=ON \-D WITH_GSTREAMER_0_10=OFF \-DBUILD_OPENJPEG:BOOL=ON ..
sudo make -j12
sudo make install
安装完成之后查看版本:
python3 -c "import cv2; print(cv2.__version__)"
pkg-config --modversion opencv4
配置用户环境变量
nano ~/.bashrc
# OpenCV Environment Variables
export OPENCV_INCLUDE_DIR=/usr/local/include/opencv4
export OPENCV_LIB_DIR=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/opencv4
source ~/.bashrc # 或者 source ~/.zshrc
验证
echo $OPENCV_INCLUDE_DIR
echo $OPENCV_LIB_DIR
测试
#include <opencv2/opencv.hpp>
#include <iostream>int main() {std::cout << "OpenCV version: " << CV_VERSION << std::endl;return 0;
}
g++ -o test main.cc $(pkg-config --cflags --libs opencv4)