在系统设置-软件和更新下ubuntu软件中勾选源代码,并且更换镜像(华为云,阿里云,中科大,清华皆可)注意:镜像选择之后最后不要再更换了
其他软件中勾选Canonical合作伙伴和Canonical合作伙伴(源代码)
在系统设置-详细信息中安装更新
在系统设置-软件和更新-附加驱动中选择专有驱动
# 验证驱动是否安装成功
nvidia-smi
cuda官方下载
按Ctrl+alt+F1进入字符界面进行安装
可能需要的库
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install git cmake build-essential
# 如果文件没有可执行权限则添加
chmod a+x cuda_9.0.176_384.81_linux.run
sudo sh cuda_9.0.176_384.81_linux.run
# 有提示是否安装驱动,如果已经安装,则不再安装
# 打补丁
sudo sh cuda_9.0.176.1_linux.run
sudo sh cuda_9.0.176.2_linux.run
sudo sh cuda_9.0.176.3_linux.run
sudo sh cuda_9.0.176.4_linux.run
# 配置环境变量
sudo gedit /etc/profile
# 添加如下路径
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
# 保存退出,重启
sudo reboot
# 测试CUDA的例子
cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
# 若输出pass则成功
# 声明环境变量
sudo gedit ~/.bashrc
# 在文本窗口最后输入
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
# 保存退出
source ~/.bashrc
# 设置环境变量
sudo gedit /etc/profile
# 在末尾添加
export PATH=/usr/local/cuda/bin:$PATH
# 保存退出
# 创建链接文件
sudo gedit /etc/ld.so.conf.d/cuda.conf
# 在打开文件添加如下路径
/usr/local/cuda/lib64
# 使链接生效
sudo ldconfig
# 验证显卡驱动
cat /proc/driver/nvidia/version
# 验证CUDA版本
nvcc -V
cudnn官方下载
tar -zxvf cudnn-9.0-linux-x64-v7.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
# 到本地cuda路径,创建软连接
cd /usr/local/cuda/lib64
# 增加读取权限
sudo ln -sf libcudnn.so.7.0.5 libcudnn.so.7
sudo ln -sf libcudnn.so.7 libcudnn.so
sudo ldconfig
# 在本地cuda路径检测一下
ll
安装教程
先更新下pip
sudo apt update
# for Python 3.n
sudo apt install -y python3-dev python3-pip
# 升级pip3
sudo -H pip3 install --upgrade pip
# for Python 2.7
sudo apt install -y python-pip python-dev
# 升级pip
sudo -H pip install --upgrade pip
安装科学套件
sudo apt-get install -y build-essential cmake git unzip pkg-config libopenblas-dev liblapack-dev
sudo apt-get install -y python-numpy python-scipy python-matplotlib python-yaml
sudo apt-get install -y libhdf5-serial-dev python-h5py
sudo apt-get install -y graphviz
sudo -H pip3 install pydot-ng
可能的依赖:大多不知道有什么用
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libopencv-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev doxygen
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev libblas-dev
sudo apt-get install -y libatlas-base-dev libopenblas-dev libgphoto2-dev libeigen3-dev libhdf5-dev
sudo apt-get install -y python-dev python-pip python-nose python-numpy python-scipy python-wheel python-six
sudo apt-get install -y python3-dev python3-pip python3-nose python3-numpy python3-scipy python3-wheel python3-six
# 使用pip,先对pip进行更新
sudo -H pip3 install numpy matplotlib ipython protobuf jupyter mock
sudo -H pip3 install scipy scikit-image scikit-learn
# 下面有关keras不知是否需要
sudo -H pip3 install keras_applications==1.0.6 --no-deps
sudo -H pip3 install keras_preprocessing==1.0.5 --no-deps
sudo -H pip3 install --upgrade numpy
官方教程
安装Virtualenv
sudo pip3 install -U virtualenv
创建虚拟环境(推荐)
# 继承系统目录下多有的包,并使用python3
virtualenv --system-site-packages -p python3 ./venv
# 激活该虚拟环境
source ./venv/bin/activate
# 当 virtualenv 处于有效状态时,bash 提示符带有 (venv) 前缀。
# 在不影响主机系统设置的情况下,在虚拟环境中安装软件包。首先升级 pip:
pip install --upgrade pip
# 在虚拟环境内安装一些库
pip install wheel numpy scipy matplotlib scikit-image scikit-learn ipython dlib
# 显示在该虚拟环境下的包
pip list
# 在虚拟环境中安装tensorflow和keras
pip install tensorflow-gpu==1.8.0
pip install keras
# 验证安装效果
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
# 退出激活环境
deactivate # don't exit until you're done using TensorFlow
系统安装制定版本的tensorflow
pip3 install --user tensorflow-gpu==1.8.0
# 验证安装效果
python3 -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
结合每个库的说明来用
sudo apt-get install libeigen3-dev
git clone http://github.com/strasdat/Sophus.git
git checkout a621ff
mkdir build
cd build
cmake ..
make
sudo apt install -y cmake
sudo apt install -y libeigen3-dev
sudo apt install -y libsuitesparse-dev
sudo apt install -y qtdeclarative5-dev
sudo apt install -y qt5-qmake
sudo apt install -y libqglviewer-dev
mkdir build
cd build
cmake ..
make
sudo make install
安装教程
# OpenGL
sudo apt-get install -y build-essential libgl1-mesa-dev libglu1-mesa-dev
sudo apt-get install -y freeglut3-dev
# GLew
sudo apt-get install -y libglew-dev
# CMake
sudo apt-get install -y cmake
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install libpython2.7-dev
sudo apt-get install libpython3-dev
sudo apt-get install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev
sudo apt-get install libdc1394-22-dev libraw1394-dev
sudo apt-get install libjpeg-dev libpng12-dev libtiff5-dev libopenexr-dev
sudo apt-get install -y libopenni-dev
sudo apt-get install -y libopenni2-dev
安装libuvc库
git clone https://github.com/ktossell/libuvc
cd libuvc
mkdir build
cd build
cmake ..
make
sudo make install
编译安装
mkdir build
cd build
cmake -DCPP11_NO_BOOST=1 ..
make -j
依赖
sudo apt-get install cmake doxygen libqt4-dev libqt4-opengl-dev libqglviewer-dev-qt4
依赖项安装
sudo apt-get install -y git build-essential linux-libc-dev
sudo apt-get install -y cmake cmake-gui
sudo apt-get install -y libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install -y libqhull* libgtest-dev
sudo apt-get install -y libgl1-mesa-dev
sudo apt-get install -y libxt-dev
sudo apt-get install -y freeglut3-dev pkg-config
sudo apt-get install -y libxmu-dev libxi-dev
sudo apt-get install -y mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install -y mono-complete
sudo apt-get install -y libopenni-dev
sudo apt-get install -y libopenni2-dev
可以安装完VTK后再安装OpenCV
flann安装
sudo apt-get install -y libflann1.8 libflann-dev
Boost安装
sudo apt-get update
sudo apt-get install -y libboost-all-dev
EIGEN3安装
sudo apt-get update
sudo apt-get install -y libeigen3-dev
QT5.9.2安装
官方网站
# 给运行程序添加可执行权限
chmod +x qt-unified-linux-x64-3.1.0-online.run
直接双击打开该run文件即可安装
安装X11
sudo apt-get install -y libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
安装OpenGL
sudo apt-get install -y build-essential libgl1-mesa-dev libglu1-mesa-dev
sudo apt-get install -y freeglut3-dev
源码编译安装vtk7.1.1
官方网站
# 在vtk目录下
mkdir build
cd build
cmake ..
make -j4
sudo make install
源码编译安装PCL1.8.1(ros自带pcl1.7.0)
官方网站
# 在pcl目录下
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j4
sudo make install
官方安装教程
官方创建工作空间教程
从Gihub上克隆下来的OpenCV会遇到编译不正确的问题
在编译OpenCV时,会遇到有关vtk的错误提示,还有可能遇到找不到cuda库的问题:
cuda问题简要:
samples/gpu/CMakeFiles/example_gpu_driver_api_stereo_multi.dir/build.make:123: recipe for target 'bin/example_gpu_driver_api_stereo_multi' failed
解决方法
OpenCV装在ROS后面,反之,ROS自带的OpenCV设置将会使python3无法使用OpenCV。不过没弄清楚是否应该先装qt还是先装OpenCV,若qt安装在之前,如果编译时OpenCV添加了qt选项,则安装的qt将会被取代
**注意:**不要再装附加qt的OpenCV了,把WITH_QT=ON这一项去掉
带cuda的官方安装教程
不带cuda的官方安装教程
下载OpenCV和OpenCV_contrib
# 下载OpenCV
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 3.4.1
cd ..
# 下载OpenCV-contrib
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 3.4.1
cd ..
依赖项不知道哪些需要哪些不需要就都装了吧,最好把官方的依赖项装了
OpenCV3.4.4依赖项(首选)
sudo apt -y remove x264 libx264-dev
## Install dependencies
sudo apt -y install build-essential checkinstall cmake pkg-config yasm
sudo apt -y install git gfortran
sudo apt -y install libjpeg8-dev libjasper-dev libpng12-dev
sudo apt -y install libtiff5-dev
sudo apt -y install libtiff-dev
sudo apt -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt -y install libxine2-dev libv4l-dev
cd /usr/include/linux
sudo ln -s -f ../libv4l1-videodev.h videodev.h
cd $cwd
sudo apt -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt -y install libgtk2.0-dev libtbb-dev qt5-default
sudo apt -y install libatlas-base-dev
sudo apt -y install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt -y install libvorbis-dev libxvidcore-dev
sudo apt -y install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt -y install libavresample-dev
sudo apt -y install x264 v4l-utils
# Optional dependencies
sudo apt -y install libprotobuf-dev protobuf-compiler
sudo apt -y install libgoogle-glog-dev libgflags-dev
sudo apt -y install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
# 安装python库
sudo apt -y install python3-dev python3-pip python3-venv
sudo -H pip3 install -U pip numpy
sudo apt -y install python3-testresources
sudo -H pip3 install wheel numpy scipy matplotlib scikit-image scikit-learn ipython dlib
如果使用在pip安装时使用sudo,应该加上标志位-H,不知道为什么
OpenCV3.3的依赖项
sudo apt-get install -y build-essential cmake git
sudo apt-get install -y pkg-config unzip ffmpeg qtbase5-dev python-dev python3-dev python-numpy python3-numpy
sudo apt-get install -y libopencv-dev libgtk-3-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install -y libv4l-dev libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
sudo apt-get install -y libvorbis-dev libxvidcore-dev v4l-utils vtk6
sudo apt-get install -y liblapacke-dev libopenblas-dev libgdal-dev checkinstall
OpenCV3.4.x的依赖项
# 必要包
sudo apt-get install -y build-essential
sudo apt-get install -y cmake git g++
# 依赖包
sudo apt-get install -y libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install -y checkinstall yasm libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install -y libopencore-amrnb-dev libopencore-amrwb-dev libavresample-dev x264 v4l-utils
# 处理图像所需的包
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
# 处理视频所需的包
sudo apt-get install -y libxvidcore-dev libx264-dev ffmpeg
# opencv功能优化
sudo apt-get install -y libatlas-base-dev gfortran
# 部分依赖包,里面有qt4的选项,如果想要qt5可不安装
sudo apt-get install -y libopencv-dev libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3.1.4 libcholmod3.0.6
sudo apt-get install -y python-dev python-numpy
# 可选依赖包
sudo apt-get install -y libprotobuf-dev protobuf-compiler
sudo apt-get install -y libgoogle-glog-dev libgflags-dev
sudo apt-get install -y libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
# 谨慎
sudo apt-get install -y python-vtk
CMake用法
mkdir build
cd build
# 官方cmake,可以根据需要功能,选择相应的cmake选项
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_PNG=OFF \
-DBUILD_TIFF=OFF \
-DBUILD_TBB=OFF \
-DBUILD_JPEG=OFF \
-DBUILD_JASPER=OFF \
-DBUILD_ZLIB=OFF \
-DBUILD_EXAMPLES=ON \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_python2=ON \
-DBUILD_opencv_python3=OFF \
-DWITH_OPENCL=OFF \
-DWITH_OPENMP=OFF \
-DWITH_FFMPEG=ON \
-DWITH_GSTREAMER=OFF \
-DWITH_GSTREAMER_0_10=OFF \
-DWITH_CUDA=ON \
-DWITH_GTK=ON \
-DWITH_VTK=OFF \
-DWITH_TBB=ON \
-DWITH_1394=OFF \
-DWITH_OPENEXR=OFF \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0 \
-DCUDA_ARCH_BIN='3.0 3.5 5.0 6.0 6.2' \
-DCUDA_ARCH_PTX="" \
-DINSTALL_C_EXAMPLES=ON \
-DINSTALL_TESTS=OFF \
-DOPENCV_TEST_DATA_PATH=../opencv_extra/testdata \
../opencv
# opencv3.4.1cmake
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 WITH_TBB=ON -D WITH_V4L=ON -D WITH_GTK=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
# cmake1
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3 -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUDA=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
# 推荐cmake
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
编译和安装
make -j8
sudo make install
# 后面路径配置步骤可不需要,输入sudo ldconfig即可
# 或者添加路径
sudo gedit /etc/ld.so.conf.d/opencv.conf
# 再打开文件末尾添加
/usr/local/lib
# 配置路径生效
sudo ldconfig
# 配置bash
sudo gedit /etc/bash.bashrc
# 在打开文件末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
# 使配置生效
source /etc/bash.bashrc
# 更新
sudo updatedb
# 测试
cd opencv-3.4.4/samples/cpp/example_cmake
mkdir build
cd build
cmake ..
make
./opencv_example
带ros插件的qtcreator安装教程
创客智造安装教程
安装依赖包
sudo apt-get install -y phonon-backend-gstreamer phonon4qt5-backend-gstreamer phonon-backend-vlc
安装kdevelop
sudo apt-get install -y kdevelop
安装破解过于复杂,还要安装相关ros插件,放弃了
安装教程
参考链接