赞
踩
opencv: https://opencv.org/releases/
opencv_contrib: https://github.com/opencv/opencv_contrib
注意opencv_contrib和opencv版本要对应
下载后将安装包解压到主目录,重命名为opencv和opencv_contrib
安装g++, cmake, make, wget, unzip
sudo apt install -y g++
sudo apt install -y cmake
sudo apt install -y make
sudo apt install -y wget
sudo apt install -y unzip
安装opencv依赖的基本库
sudo apt-get install build-essential libgtk2.0-dev libgtk-3-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
如果提前安装了anaconda, 建议先把anaconda环境变量注释掉,并把anaconda文件夹移进回收站等装完再移出来(改软连接也行,但上述更无脑些)
主目录下打开终端
cd opencv
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules .. \
-DWITH_CUDA=1 \
-DCUDA_ARCH_BIN=8.6 \
-DENABLE_FAST_MATH=1 \
-DCUDA_FAST_MATH=1 \
-DWITH_CUBLAS=1 \
-DOPENCV_GENERATE_PKGCONFIG=1 \
..
注意:上面的DCUDA_ARCH_BIN指定GPU算力,在NVIDIA官网查询 https://developer.nvidia.com/cuda-gpus#compute,常用的30系显卡是8.6,40系显卡是8.9
nproc
比如输出 16
那么就
make -j16
sudo make install
sudo gedit /etc/profile.d/pkgconfig.sh
可能为空文件,在文件中加入
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
保存并退出,source激活
source /etc/profile
验证是否成功
pkg-config --libs opencv4
输出类似下面这样即为成功
-L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_barcode -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cudabgsegm -lopencv_cudafeatures2d -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_cudacodec -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_cudaoptflow -lopencv_optflow -lopencv_cudalegacy -lopencv_videoio -lopencv_cudawarping -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_imgproc -lopencv_cudaarithm -lopencv_core -lopencv_cudev
sudo gedit /etc/ld.so.conf.d/opencv4.conf
文件末尾加上
/usr/local/lib
使配置生效
sudo ldconfig
打开新终端,进入到example_cmake目录
cd ~/opencv/samples/cpp/example_cmake
cmake .
make
./opencv_example
正常来说,应该有摄像头窗口界面;如果没有摄像头,出现“Hello OpenCV“也测试成功
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。