关于Ubuntu18.04安装后的一系列环境配置过程的总结

2023-05-16

Updating...

目录

1.注意

2.更换国内源

3.设置/home文件夹下为英文

4.禁用Nouveau驱动

5.安装Nvidia驱动(有可能会损坏系统,如果损坏可以重装并看看网上的其他教程,除了这种安装方法还有其他安装方法,自行上网了解)

6.cuda安装:

7.cudnn安装:

8.安装ROS(有些图忘记截了)

9.安装opencv-3.4.16和opencv_contrib-3.4.16

10.安装protobuf2.6.1

11.配置OpenBLAS

12.配置seetaface2工作空间

13.百度智能云手骨骼点检测

14.使在桌面上右键打开终端时进入Desktop目录

15.同步双系统时间

​编辑

16.启动菜单的默认项

17.安装darknet版yolov3及darknet-ros工作空间

18.Azure Kinect SDK-v1.4.0的安装

19.配置科大讯飞

20.配置realsense及realsense工作空间

21.配置Kinova机械臂工作空间

22.配置机器人导航(实体)

23.安装配置caffe

24.安装libfreenect2

P.S:


本文所有用到的文件打包供大家下载(不含代码){Updating}:

链接:

https://pan.baidu.com/s/1PgmWHKl8oyX_cWYx_uZJrg?pwd=zwz4

提取码:

zwz4
--来自百度网盘超级会员v4的分享

1.注意

刚进入系统一段时间,系统会通知更新到新版本系统(Ubuntu20.04),选择否,之后会询问是否更新系统组件(大概400mb),选择是。

阻止软件更新弹窗:

打开终端输入:

sudo chmod a-x /usr/bin/update-notifier

将关机时间从90秒换为5秒:

打开终端输入:

sudo gedit /etc/systemd/system.conf

 将:

#DefaultTimeoutStopSec=90s

改为:

DefaultTimeoutStopSec=5s

 保存退出,打开终端输入:

sudo systemctl daemon-reload

2.更换国内源

sudo gedit /etc/apt/sources.list

 将原本的注释掉,在最下方加入

#  中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
sudo apt-get update

3.设置/home文件夹下为英文

export LANG=en_US
xdg-user-dirs-gtk-update

​编辑选择右边的Update Names

11860bd995624609b10076f25fc108fb.png

 之后执行以下语句:

export LANG=zh_CN
reboot

勾选不要在次询问我,并选择保留旧的名称

560bffa1f8fd4255a9bec1f2be43efcd.png

4.禁用Nouveau驱动

sudo gedit /etc/modprobe.d/blacklist.conf

输入

blacklist nouveau
options nouveau modeset=0

保存后关闭,打开终端,输入:

sudo update-initramfs -u
reboot

5.安装Nvidia驱动(有可能会损坏系统,如果损坏可以重装并看看网上的其他教程,除了这种安装方法还有其他安装方法,自行上网了解)

打开终端,输入:

sudo apt-get install gcc g++ make
sudo ubuntu-drivers devices

15997876f01749bfa95298efd251fcd1.png

 寻找带有recommended的版本,输入

sudo apt-get install nvidia-driver-* nvidia-settings nvidia-prime

(*是你的版本号)

sudo apt-get update
sudo apt-get upgrade
reboot

 验证版本

nvidia-smi

3edc9839576e4b20a1e95a852e80d8e4.png

6.cuda安装:

https://developer.nvidia.com/cuda-toolkit-archivehttps://developer.nvidia.com/cuda-toolkit-archive

选择和上一步nvidia-smi显示的cuda版本对应的进行安装,官方有教程

安装好之后打开终端输入

sudo gedit ~/.bashrc

 在最后输入

#cuda
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda  #cuda的软连接库,可以设置多版本共存指向

保存后关闭,打开终端,输入: 

source ~/.bashrc
sudo gedit /etc/profile

 在最后加入

#cuda
export PATH=/usr/local/cuda/bin:$PATH
export PATH=/usr/local/cuda/bin:$PATH

保存后关闭,打开终端,输入: 

 source /etc/profile

  验证cuda版本

nvcc -V

 91fd7494b10a420ba9cd584fc7abcc8f.png

 安装成功!

7.cudnn安装:

cuDNN Archive | NVIDIA DeveloperExplore and download past releases from cuDNN GPU-accelerated primitive library for deep neural networks.https://developer.nvidia.com/rdp/cudnn-archive

同样需要选择与刚才安装cuda对应的版本下载,下载好后进入文件所在目录打开终端

tar -xvf cudnn-*-linux-x64-*.tgz 

打开终端:

sudo cp -r cuda/include/* /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
sudo ln -sf /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.0.1 /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
sudo ln -sf /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.0.1 /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
sudo ln -sf /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.1 /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
sudo ln -sf /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.0.1 /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
sudo ln -sf /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.0.1 /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
sudo ln -sf /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.0.1 /usr/local/cuda-11.4/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
sudo ln -sf /usr/local/cuda-11.4/lib64/libcudnn.so.8 /usr/local/cuda-11.4/lib64/libcudnn.so.8.2.2

 验证是否安装成功

cat /usr/local/cuda/include/cudnn_version.h

 7b37c756e39f4137941bd046fe2fe661.png

8.安装ROS(有些图忘记截了)

设置中科大源

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

设置公钥

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt-get install python3-pip 

 使用阿里镜像源加速pip下载:

sudo pip3 install rosdepc -i https://mirrors.aliyun.com/pypi/simple/
sudo rosdepc init
rosdepc update
sudo chmod 777 -R ~/.ros/ 
roscore

52b0561164a34d3ea62b74322abe50bc.png

   再新建两个终端,分别输入

rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

 在rosrun turtlesim turtle_teleop_key所在终端点击一下任意位置,然后使用↕↔小键盘控制,看小海龟会不会动,如果会动则安装成功

c40128bd8c5245a48d386c21ba465449.png

9.安装opencv-3.4.16和opencv_contrib-3.4.16

虽然使用cv_bridge时某些shared object有可能和ROS自带的opencv-3.2.0版本冲突,但实测安装3.2.0对cuda的兼容性太差导致无法使用深度相机,所以安装官网最近更新过的OpenCV3.4.16

git clone -b 3.4.16 https://gitee.com/KylenWrt/opencv.git opencv-3.4.16
cd opencv-3.4.16
git clone -b 3.4.16 https://gitee.com/zsy26226/opencv_contrib.git opencv_contrib-3.4.16

  安装所需依赖库,打开终端,输入:

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev liblapacke-dev checkinstall
sudo apt-get install liblapacke-dev checkinstall

进入opencv-3.4.16文件夹,打开终端,输入:

mkdir build
cd build

 接下来编译安装,注意此命令的OPENCV_EXTRA_MODULES_PATH=后边的路径是你电脑下的绝对路径,请自行修改

cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_GTK_2_X=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_EXTRA_MODULES_PATH=/home/m0rtzz/Program_Files/opencv-3.4.16/opencv_contrib-3.4.16/modules -D WITH_CUDA=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D WITH_NVCUVID=ON -D -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_EXE_LINKER_FLAGS=-lcblas -DWITH_LAPACK=OFF -j16 ..

过程中会出现IPPICV: Download: ippicv_2020_lnx_intel64_20191018_general.tgz

 解决方法:

cd ../ && mkdir downloads 
cd downloads && pwd

 复制绝对路径后:

打开这个ippicv.cmake

 把绝对路径复制进去:

 然后把下面网址下载的文件cp进去就行了(或者开头百度云分享链接中自取~)

https://github.com/opencv/opencv_3rdparty/blob/ippicv/master_20191018/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgzhttps://github.com/opencv/opencv_3rdparty/blob/ippicv/master_20191018/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz之后重新打开终端,输入:cmake(别忘了改路径):

cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_GTK_2_X=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_EXTRA_MODULES_PATH=/home/m0rtzz/Program_Files/opencv-3.4.16/opencv_contrib-3.4.16/modules -D WITH_CUDA=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D WITH_NVCUVID=ON -D -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_EXE_LINKER_FLAGS=-lcblas -DWITH_LAPACK=OFF -j16 ..

这些.i文件需要在国外下载,网上说下载好文件直接把他们放进相对应的目录下就行,实测不行(建议科学的上网,想试试网上说法的:

Reference:fatal error: boostdesc_bgm.i: No such file or directory_"atal error: boostdesc_bgm.i: no such file or dire_eziaowonder的博客-CSDN博客OpenCV4 编译 fatal error: boostdesc_bgm.i: No such file or directory环境编译参考错误原因数据参考环境硬件:树莓派 4B 4G系统:RasberryPi OS编译参考Raspberry pi 树莓派安装 OpenCV 4.1.2子豪兄教你在树莓派上安装OpenCV错误编译到 83% 左右的时候出现类似下图的错误(当时没截图,用 #1301 的部分出错报告)[ 80%] Building CXX object modules/xfhttps://blog.csdn.net/curious_undergather/article/details/111639199?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167905082916800184134715%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=167905082916800184134715&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-1-111639199-null-null.blog_rank_default&utm_term=boosetdesc_bgm.i&spm=1018.2226.3001.4450 文件的话,开头百度云分享链接里都有)

cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_GTK_2_X=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_EXTRA_MODULES_PATH=/home/m0rtzz/Program_Files/opencv-3.4.16/opencv_contrib-3.4.16/modules -D WITH_CUDA=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D WITH_NVCUVID=ON -D -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_EXE_LINKER_FLAGS=-lcblas -DWITH_LAPACK=OFF -j16 ..

sudo make -j16

打开那个头文件,把报错所在行改为:

#include "lapacke.h"
sudo make -j16

sudo make install

sudo gedit /etc/ld.so.conf.d/opencv.conf

  加入

/usr/local/lib

保存后关闭,打开终端,输入: 

sudo ldconfig
sudo gedit /etc/bash.bashrc

加入

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

保存后关闭,打开终端,输入: 

source /etc/bash.bashrc

测试

cd ../samples/cpp/example_cmake
cmake -j8 .
sudo make -j8
./opencv_example

1cb714361c874eacb01f3bce3f37e1fb.png

安装成功!

设置cv_bridge的版本:

sudo gedit /opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake
# generated from catkin/cmake/template/pkgConfig.cmake.in

# append elements to a list and remove existing duplicates from the list
# copied from catkin/cmake/list_append_deduplicate.cmake to keep pkgConfig
# self contained
macro(_list_append_deduplicate listname)
  if(NOT "${ARGN}" STREQUAL "")
    if(${listname})
      list(REMOVE_ITEM ${listname} ${ARGN})
    endif()

    list(APPEND ${listname} ${ARGN})
  endif()
endmacro()

# append elements to a list if they are not already in the list
# copied from catkin/cmake/list_append_unique.cmake to keep pkgConfig
# self contained
macro(_list_append_unique listname)
  foreach(_item ${ARGN})
    list(FIND ${listname} ${_item} _index)

    if(_index EQUAL -1)
      list(APPEND ${listname} ${_item})
    endif()
  endforeach()
endmacro()

# pack a list of libraries with optional build configuration keywords
# copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig
# self contained
macro(_pack_libraries_with_build_configuration VAR)
  set(${VAR} "")
  set(_argn ${ARGN})
  list(LENGTH _argn _count)
  set(_index 0)

  while(${_index} LESS ${_count})
    list(GET _argn ${_index} lib)

    if("${lib}" MATCHES "^(debug|optimized|general)$")
      math(EXPR _index "${_index} + 1")

      if(${_index} EQUAL ${_count})
        message(FATAL_ERROR "_pack_libraries_with_build_configuration() the list of libraries '${ARGN}' ends with '${lib}' which is a build configuration keyword and must be followed by a library")
      endif()

      list(GET _argn ${_index} library)
      list(APPEND ${VAR} "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}")
    else()
      list(APPEND ${VAR} "${lib}")
    endif()

    math(EXPR _index "${_index} + 1")
  endwhile()
endmacro()

# unpack a list of libraries with optional build configuration keyword prefixes
# copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig
# self contained
macro(_unpack_libraries_with_build_configuration VAR)
  set(${VAR} "")

  foreach(lib ${ARGN})
    string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}")
    list(APPEND ${VAR} "${lib}")
  endforeach()
endmacro()

if(cv_bridge_CONFIG_INCLUDED)
  return()
endif()

set(cv_bridge_CONFIG_INCLUDED TRUE)

# set variables for source/devel/install prefixes
if("FALSE" STREQUAL "TRUE")
  set(cv_bridge_SOURCE_PREFIX /tmp/binarydeb/ros-melodic-cv-bridge-1.13.1)
  set(cv_bridge_DEVEL_PREFIX /tmp/binarydeb/ros-melodic-cv-bridge-1.13.1/.obj-x86_64-linux-gnu/devel)
  set(cv_bridge_INSTALL_PREFIX "")
  set(cv_bridge_PREFIX ${cv_bridge_DEVEL_PREFIX})
else()
  set(cv_bridge_SOURCE_PREFIX "")
  set(cv_bridge_DEVEL_PREFIX "")
  set(cv_bridge_INSTALL_PREFIX /opt/ros/melodic)
  set(cv_bridge_PREFIX ${cv_bridge_INSTALL_PREFIX})
endif()

# warn when using a deprecated package
if(NOT "" STREQUAL "")
  set(_msg "WARNING: package 'cv_bridge' is deprecated")

  # append custom deprecation text if available
  if(NOT "" STREQUAL "TRUE")
    set(_msg "${_msg} ()")
  endif()

  message("${_msg}")
endif()

# flag project as catkin-based to distinguish if a find_package()-ed project is a catkin project
set(cv_bridge_FOUND_CATKIN_PROJECT TRUE)

# if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
# set(cv_bridge_INCLUDE_DIRS "")
# set(_include_dirs "include;/usr/include;/usr/include/opencv")
if(NOT "include;/usr/local/include/opencv;/usr/local/include/opencv2 " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/local/include/opencv;/usr/local/include/opencv;/usr/local/include/;/usr/include")

  if(NOT "https://github.com/ros-perception/vision_opencv/issues " STREQUAL " ")
    set(_report "Check the issue tracker 'https://github.com/ros-perception/vision_opencv/issues' and consider creating a ticket if the problem has not been reported yet.")
  elseif(NOT "http://www.ros.org/wiki/cv_bridge " STREQUAL " ")
    set(_report "Check the website 'http://www.ros.org/wiki/cv_bridge' for information and consider reporting the problem.")
  else()
    set(_report "Report the problem to the maintainer 'Vincent Rabaud <vincent.rabaud@gmail.com>' and request to fix the problem.")
  endif()

  foreach(idir ${_include_dirs})
    if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir})
      set(include ${idir})
    elseif("${idir} " STREQUAL "include ")
      get_filename_component(include "${cv_bridge_DIR}/../../../include" ABSOLUTE)

      if(NOT IS_DIRECTORY ${include})
        message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found.  It does not exist in '${include}'.  ${_report}")
      endif()
    else()
      message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found.  It does neither exist as an absolute directory nor in '\${prefix}/${idir}'.  ${_report}")
    endif()

    _list_append_unique(cv_bridge_INCLUDE_DIRS ${include})
  endforeach()
endif()

# set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2.0;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0")
set(libraries "cv_bridge;/usr/local/lib/libopencv_core.so.3.4.16;/usr/local/lib/libopencv_imgproc.so.3.4.16;/usr/local/lib/libopencv_imgcodecs.so.3.4.16")

foreach(library ${libraries})
  # keep build configuration keywords, target names and absolute libraries as-is
  if("${library}" MATCHES "^(debug|optimized|general)$")
    list(APPEND cv_bridge_LIBRARIES ${library})
  elseif(${library} MATCHES "^-l")
    list(APPEND cv_bridge_LIBRARIES ${library})
  elseif(${library} MATCHES "^-")
    # This is a linker flag/option (like -pthread)
    # There's no standard variable for these, so create an interface library to hold it
    if(NOT cv_bridge_NUM_DUMMY_TARGETS)
      set(cv_bridge_NUM_DUMMY_TARGETS 0)
    endif()

    # Make sure the target name is unique
    set(interface_target_name "catkin::cv_bridge::wrapped-linker-option${cv_bridge_NUM_DUMMY_TARGETS}")

    while(TARGET "${interface_target_name}")
      math(EXPR cv_bridge_NUM_DUMMY_TARGETS "${cv_bridge_NUM_DUMMY_TARGETS}+1")
      set(interface_target_name "catkin::cv_bridge::wrapped-linker-option${cv_bridge_NUM_DUMMY_TARGETS}")
    endwhile()

    add_library("${interface_target_name}" INTERFACE IMPORTED)

    if("${CMAKE_VERSION}" VERSION_LESS "3.13.0")
      set_property(
        TARGET
        "${interface_target_name}"
        APPEND PROPERTY
        INTERFACE_LINK_LIBRARIES "${library}")
    else()
      target_link_options("${interface_target_name}" INTERFACE "${library}")
    endif()

    list(APPEND cv_bridge_LIBRARIES "${interface_target_name}")
  elseif(TARGET ${library})
    list(APPEND cv_bridge_LIBRARIES ${library})
  elseif(IS_ABSOLUTE ${library})
    list(APPEND cv_bridge_LIBRARIES ${library})
  else()
    set(lib_path "")
    set(lib "${library}-NOTFOUND")

    # since the path where the library is found is returned we have to iterate over the paths manually
    foreach(path /opt/ros/melodic/lib;/opt/ros/melodic/lib)
      find_library(lib ${library}
        PATHS ${path}
        NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)

      if(lib)
        set(lib_path ${path})
        break()
      endif()
    endforeach()

    if(lib)
      _list_append_unique(cv_bridge_LIBRARY_DIRS ${lib_path})
      list(APPEND cv_bridge_LIBRARIES ${lib})
    else()
      # as a fall back for non-catkin libraries try to search globally
      find_library(lib ${library})

      if(NOT lib)
        message(FATAL_ERROR "Project '${PROJECT_NAME}' tried to find library '${library}'.  The library is neither a target nor built/installed properly.  Did you compile project 'cv_bridge'?  Did you find_package() it before the subdirectory containing its code is included?")
      endif()

      list(APPEND cv_bridge_LIBRARIES ${lib})
    endif()
  endif()
endforeach()

set(cv_bridge_EXPORTED_TARGETS "")

# create dummy targets for exported code generation targets to make life of users easier
foreach(t ${cv_bridge_EXPORTED_TARGETS})
  if(NOT TARGET ${t})
    add_custom_target(${t})
  endif()
endforeach()

set(depends "rosconsole;sensor_msgs")

foreach(depend ${depends})
  string(REPLACE " " ";" depend_list ${depend})

  # the package name of the dependency must be kept in a unique variable so that it is not overwritten in recursive calls
  list(GET depend_list 0 cv_bridge_dep)
  list(LENGTH depend_list count)

  if(${count} EQUAL 1)
    # simple dependencies must only be find_package()-ed once
    if(NOT ${cv_bridge_dep}_FOUND)
      find_package(${cv_bridge_dep} REQUIRED NO_MODULE)
    endif()
  else()
    # dependencies with components must be find_package()-ed again
    list(REMOVE_AT depend_list 0)
    find_package(${cv_bridge_dep} REQUIRED NO_MODULE ${depend_list})
  endif()

  _list_append_unique(cv_bridge_INCLUDE_DIRS ${${cv_bridge_dep}_INCLUDE_DIRS})

  # merge build configuration keywords with library names to correctly deduplicate
  _pack_libraries_with_build_configuration(cv_bridge_LIBRARIES ${cv_bridge_LIBRARIES})
  _pack_libraries_with_build_configuration(_libraries ${${cv_bridge_dep}_LIBRARIES})
  _list_append_deduplicate(cv_bridge_LIBRARIES ${_libraries})

  # undo build configuration keyword merging after deduplication
  _unpack_libraries_with_build_configuration(cv_bridge_LIBRARIES ${cv_bridge_LIBRARIES})

  _list_append_unique(cv_bridge_LIBRARY_DIRS ${${cv_bridge_dep}_LIBRARY_DIRS})
  list(APPEND cv_bridge_EXPORTED_TARGETS ${${cv_bridge_dep}_EXPORTED_TARGETS})
endforeach()

set(pkg_cfg_extras "cv_bridge-extras.cmake")

foreach(extra ${pkg_cfg_extras})
  if(NOT IS_ABSOLUTE ${extra})
    set(extra ${cv_bridge_DIR}/${extra})
  endif()

  include(${extra})
endforeach()

10.安装protobuf2.6.1

https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gzhttps://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz解压压缩包后进入文件夹,打开终端,输入:

./autogen.sh

da01acbb001f42cea9ca08ddad814655.png

./configure --prefix=/usr/local/protobuf 

1c6a5408dece4f7aa5fb4e78680eb913.png

sudo make -j16

140562b609004503a731358eea387731.png

 养成make check 的好习惯

sudo make check -j16

f9827d81f7f946d8ba91d26494c7251d.png

 sudo make install

bf530b0ab13e4939bd810d4731e2764d.png

sudo gedit /etc/profile

在最后加入:

#protobuf
export PATH=$PATH:/usr/local/protobuf/bin/
export PKG_CONFIG_PATH=/usr/local/protobuf/lib/pkgconfig/

保存后关闭,打开终端,输入: 

source /etc/profile
sudo gedit /etc/ld.so.conf

在最后一行输入:

/usr/local/protobuf/lib

保存后关闭,打开终端,输入: 

sudo ldconfig

d80cbadb617b4986a99827d13170e9eb.png

最后验证版本:

protoc --version

11.配置OpenBLAS

OpenBLAS文件夹最上方百度网盘里有,或者绕开github用gitee进行克隆:

git clone https://gitee.com/HyperChao/OpenBLAS.git OpenBLAS
cd OpenBLAS
sudo apt-get install gfortran
 sudo make FC=gfortran -j16
 sudo make PREFIX=/usr/local install

af045e49e18643d8a1c0c12deb166d44.png

 查看版本

grep OPENBLAS_VERSION /usr/local/include/openblas_config.h 

e76d37851f2e4d08b08c4ac035423cbc.png

12.配置seetaface2工作空间

sudo gedit ~/.bashrc

 在最后加入

source /home/m0rtzz/Workspaces/catkin_ws/devel/setup.bash

保存后关闭,打开终端,输入:  

source ~/.bashrc

597806c7f0834400b846b99cae4c9d63.png

0bccdd5c978048189fcd47437ad89dfc.png

解决办法:

终端输入: 

sudo gedit ~/.bashrc

加入工作空间下lib文件夹的路径

export LD_LIBRARY_PATH=/home/m0rtzz/Workspaces/catkin_ws/lib:$LD_LIBRARY_PATH

保存后关闭,打开终端,输入:  

source ~/.bashrc

4000fa5374ee48dfbc2fdee5c5ddf2d0.png

 解决!

报错:

Gtk-Message: 15:22:30.610: Failed to load module "canberra-gtk-module"

下方第16小节最后有解决办法~

13.百度智能云手骨骼点检测

sudo apt-get install curl

include jsoncpp库的头文件改为

 #include <jsoncpp/json/json.h>

g++编译

g++ *.cpp -o * -lcurl -ljsoncpp

 运行

./*

14.使在桌面上右键打开终端时进入Desktop目录

Ubuntu – Details of source package gnome-terminal in bionichttps://packages.ubuntu.com/source/bionic/gnome-terminal

下载下图表格中的下边两个文件

ae94b3493cf44d08a7a962e070256653.png

 下载好gnome-terminal_3.28.1.orig.tar.xz文件之后解压出一个文件夹gnome-terminal-3.28.1,将gnome-terminal_3.28.1-1ubuntu1.debian.tar.xz 里面debian目录下的文件解压到之前解压出的gnome-terminal-3.28.1目录下


5097eb7f2b8b474a8411cf11a3694b55.png

在此目录下打开终端

git apply patches/*.patch

安装依赖

sudo apt install  intltool  libvte-2.91-dev gsettings-desktop-schemas-dev uuid-dev libdconf-dev libpcre2-dev libgconf2-dev libxml2-utils  gnome-shell libnautilus-extension-dev itstool  yelp-tools pcre2-utils

 打开src/下的terminal-nautilus.c

找到

static inline gboolean
desktop_opens_home_dir (TerminalNautilus *nautilus)
{
#if 0
  return  _client_get_bool (gconf_client,
                                "/apps/nautilus-open-terminal/desktop_opens_home_dir",
                                NULL);
#endif
  return TRUE;
}

改为

static inline gboolean
desktop_opens_home_dir (TerminalNautilus *nautilus)
{
#if 0
  return  _client_get_bool (gconf_client,
                                "/apps/nautilus-open-terminal/desktop_opens_home_dir",
                                NULL);
#endif
  return FALSE;
}

 src下打开终端

cd ..
autoreconf --install
autoconf
./configure --prefix='/usr'
sudo make -j8
sudo make check -j8
sudo make install

83ef9eec20fe4b5991ce5e0d3107d68d.png

reboot

之后在桌面上打开终端,看看是否生效 ,没生效打开终端

sudo cp /usr/lib/nautilus/extensions-3.0/libterminal-nautilus.so /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/
reboot

问题解决!

15.同步双系统时间

sudo apt-get install ntpdate
sudo ntpdate time.windows.com
timedatectl set-local-rtc 1 --adjust-system-clock

c17b8bd812df4e5f86bfba16f5948a9d.png

16.启动菜单的默认项

sudo gedit /etc/default/grub

 改一下GRUB_DEFAULT=后边的数字,默认是0,windows是第n个就设置为 n-1

2a4260711db540b6af9fd30682dc9257.png

保存后关闭,打开终端,输入:  

sudo update-grub

cb668a5bf2a84177956f1c6417f5310a.png

reboot

 重启后问题解决~

17.安装darknet版yolov3及darknet-ros工作空间

git clone https://gitee.com/q1255569493/darknet.git darknet
cd darknet
sudo gedit Makefile

 修改以下前几行为:

GPU=1
CUDNN=1
CUDNN_HALF=0
OPENCV=1
AVX=0
OPENMP=0
LIBSO=1
ZED_CAMERA=0
ZED_CAMERA_v2_8=0

cc434aa984054be39074c69b5692f455.png

 然后修改NVCC=后边为nvcc路径:

NVCC=/usr/local/cuda-11.4/bin/nvcc

d12dd2a5ce1e4ea7b24103796dc07a00.png

 之后保存退出后,打开终端,输入:

sudo gedit /etc/ld.so.conf.d/cuda.conf

 加入以下内容后保存退出:

/usr/local/cuda/lib64

 打开终端输入:

sudo ldconfig
sudo make -j16
./darknet

输出为:

usage: ./darknet <function>

9e10fa48060244c9972d9db1be8178cb.png

 之后我们下载yolov3权重文件:

mkdir weights && wget https://pjreddie.com/media/files/yolov3.weights 

正常wget太慢,我们使用mwget进行安装:

找一个你想安装mwget的地方打开终端,输入:

sudo apt install build-essential
sudo apt upgrade intltool
sudo apt install  libssl-dev

 之后:

wget http://jaist.dl.sourceforge.net/project/kmphpfm/mwget/0.1/mwget_0.1.0.orig.tar.bz2
tar -xjvf mwget_0.1.0.orig.tar.bz2
cd mwget_0.1.0.orig
./configure
sudo make -j8
sudo make install

 函数报错的话在文件夹中搜索httpplugin.h和ftpplugin.h中加入

#include <string.h>

保存后关闭,打开终端,输入:  

再次安装:

sudo make -j8
sudo make install

 之后mwget就安装成功了

我们用mwget多线程获取权重文件:

cd darknet/ && mkdir weights && cd weights/
mwget https://pjreddie.com/media/files/yolov3.weights -n16

上方命令是16线程获取 ,速度会快很多

05ea3530787d45c1b9672559eb8df952.png

到此为止darknet版yolov3就配置好了

下面我们测试一下:

./darknet detect cfg/yolov3.cfg weights/yolov3.weights data/dog.jpg

 输出以下就证明配置没有问题:

9967309fc02949e98046bf0b4566371b.png

输出的最后一行报错:

Gtk-Message: 15:22:30.610: Failed to load module "canberra-gtk-module"

解决方法:

sudo apt-get install libcanberra-gtk*

 安装之后重新运行就不会报错了。 

配置 darknet-ros工作空间:

mkdir darknet-ros_test_ws && cd darknet-ros_test_ws/ && mkdir src
cd src/ && catkin_init_workspace
cd .. && catkin_make -j16
cd src/
git clone --recursive https://gitee.com/mirrors_leggedrobotics/darknet_ros.git darknet_ros 

 若darknet_ros/darknet文件夹下为空,则:

cd darknet_ros && sudo rm -rf darknet
git clone https://github.com/pjreddie/darknet.git darknet

 catkin_make如果编译不过的话,注意以下命令是只编译darknet-ros一个包,若工作空间下有多个包需要一起编译那么把命令中的darknet-ros删除重新执行即可:

catkin_make -j16 darknet-ros --cmake-args -DCMAKE_CXX_FLAGS=-DCV__ENABLE_C_API_CTORS

 如果报错nvcc fatal : Unsupported gpu architecture 'compute_30'之类的,是因为CUDA11已经不支持compute_30了,我们将darknet_ros/darknet/Makefile和darknet_ros/darknet_ros/CMakeLists.txt中含有 'compute_30'的行进行注释后重新catkin_make:

 

18.Azure Kinect SDK-v1.4.0的安装

Reference: BkbK-的博客https://bokai.blog.csdn.net/article/details/119115883?spm=1001.2014.3001.5502

git clone -b v1.4.0 https://github.com/microsoft/Azure-Kinect-Sensor-SDK.git Azure-Kinect-Sensor-SDK-v1.4.0

 嫌太慢可以使用gitee镜像仓库克隆:

git clone -b v1.4.0 https://gitee.com/javenst/Azure-Kinect-Sensor-SDK.git Azure-Kinect-Sensor-SDK-v1.4.0
sudo dpkg --add-architecture amd64
sudo apt-get update
sudo apt install -y  pkg-config  ninja-build doxygen clang  gcc-multilib  g++-multilib python3 nasm cmake libgl1-mesa-dev libsoundio-dev libvulkan-dev libx11-dev libxcursor-dev libxinerama-dev libxrandr-dev libusb-1.0-0-dev libssl-dev libudev-dev mesa-common-dev uuid-dev

Index of /ubuntu/18.04/prod/pool/main/libk/https://packages.microsoft.com/ubuntu/18.04/prod/pool/main/libk/

从上面的网站下载 libk4a1.2libk4a1.2_1.2.0_amd64.deb文件

f806a0d411ac415497e78b45bf3c20ac.png

 解压 .deb 文件,再解压内部的 data.tar.gzcontrol.tar.gz文件,并进入data文件夹,打开终端输入:

cd usr/lib/x86_64-linux-gnu
sudo cp libdepthengine.so.2.0 /usr/lib/x86_64-linux-gnu

随后进入下载好的 Azure-Kinect-Sensor-SDK-v1.4.0文件夹下打开终端输入

mkdir build && cd build
cmake -j8 .. -GNinja

注意此步过程中extern/libyuv/src克隆较慢原因是使用了google的网站,我们把对应文件的克隆url改为github的就能正常克隆了,在Azure-Kinect-Sensor-SDK-v1.4.0文件夹下键盘Ctrl+H显示隐藏文件,打开.gitmodules文件,修改libyuv的部分为:

[submodule "extern/libyuv/src"]
	path = extern/libyuv/src
	url = https://github.com/lemenkov/libyuv.git

保存后关闭

 之后打开.git文件夹下的config文件,修改libyuv的部分为:

[submodule "extern/libyuv/src"]
	active = true
	url = https://github.com/lemenkov/libyuv.git

接下来就能正常克隆了,但是速度还是很慢,请耐心等待~

保存后关闭,打开终端,输入: 

cmake -j8 .. -GNinja

克隆完成后为如图所示:

b07fac22ae4b45ebb3e5a061739a4d87.png

 之后输入:

sudo ninja -j8

 完成后如下:

c625650ae9744c02aea905984da47566.png

 最后输入:

sudo ninja install

完成后如下:

b71183010a584c469b0a6cbfc72b3e39.png

 之后安装依赖:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo gedit /etc/apt/sources.list

 在最后一行加入:

##gcc-4.9
deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe
##

保存后关闭,打开终端,输入:

sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get upgrade libstdc++6

之后测试一下:

sudo ./bin/k4aviewer

 授予权限:

cd ../ && sudo cp scripts/99-k4a.rules /etc/udev/rules.d/.

19.配置科大讯飞

SDK下载 - 科大讯飞api接口 - 讯飞开放平台科大讯飞api接口,为开发者免费提供:语音识别、语音合成、语音评测、声纹识别、人脸识别等SDK下载服务,一站式人机智能语音交互等解决方案。https://www.xfyun.cn/sdk/dispatcher

sudo apt-get install sox libsox-fmt-all pavucontrol
sudo gedit /usr/include/pcl-1.8/pcl/visualization/cloud_viewer.h

修改一下:

//line 199左右
private:
        /** \brief Private implementation. */
        struct CloudViewer_impl;
        //std::auto_ptr<CloudViewer_impl> impl_;
	    std::shared_ptr<CloudViewer_impl> impl_;
        
        boost::signals2::connection 
        registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)>);

 下载所需SDK,将libs/x64/libmsc.so文件拷贝至/usr/lib/下;修改~/.bashrc;

cmake_minimum_required(VERSION 3.0.2)
project(tts_voice_test)
SET(CMAKE_CXX_FLAGS "-std=c++0x")
find_package(k4a REQUIRED)
find_package(OpenCV REQUIRED)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
cv_bridge
message_generation
)

generate_messages(
  DEPENDENCIES
  std_msgs
)

include_directories(
  ~/Workspaces/tts_test_ws/include
  ${catkin_INCLUDE_DIRS}
)

add_executable(tts_voice_test src/tts_voice_test.cpp)

target_link_libraries(tts_voice_test
  PRIVATE k4a::k4a
  ${OpenCV_LIBRARIES}
  ${PCL_LIBRARIES}
  ${catkin_LIBRARIES}
  ${catkin_LIBRARIES} -lcurl -ljsoncpp -lmsc -lrt -ldl -pthread
  ${catkin_LIBRARIES} /home/m0rtzz/Workspaces/tts_voice_test_ws/libs/x64/libmsc.so -ldl -pthread -lasound

打开终端:

catkin_make

若找不到asoundlib.h文件打开终端输入:

sudo apt-get install libasound2-dev

编译通过~

20.配置realsense及realsense工作空间

sudo apt-get install ros-melodic-realsense2-camera ros-melodic-rgbd-launch

808f1ad01090402eafa94dd83545aed3.png

 安装realsense sdk:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

8fbc31d16a394fdc91f04302aa04b1d4.png

sudo add-apt-repository "deb https://librealsense.intel.com/Debian/apt-repo $(lsb_release -cs) main" -u

344007bb790841da91383d12d7eaa42b.png

sudo apt-get update

 安装realsense lib

sudo apt-get install librealsense2-dkms librealsense2-utils

eaed28f89f1d421ca57b099a6266168a.png

测试:

realsense-viewer

66d6e2234539406982aa1aaad9e82698.png

 下载lib并指定版本为v2.5.0,否则接下来会与realsense-ros版本冲突导致无法打开摄像头:

git clone -b v2.50.0 https://gitee.com/lhospitallky/librealsense.git librealsense-2.5.0

295493ada2824a79bc59561e41fba193.png  安装依赖:

sudo apt-get install libudev-dev pkg-config libgtk-3-dev libusb-1.0-0-dev pkg-config libglfw3-dev

 进入刚才克隆的librealsense文件夹内:

cd librealsense-2.5.0/
./scripts/setup_udev_rules.sh
./scripts/patch-realsense-ubuntu-lts.sh

 注意:上面的命令可能执行过慢,请耐心等待,或者科学的上网~

  完成结果如下:

389a2809970d49d8a24d299ece865576.png

之后输入:

mkdir build && cd build
cmake -j8 ../ -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=true

 以下编译过慢,使用CPU最大线程进行make,速度会快很多:

sudo make -j16
sudo make install

测试:

cd examples/capture
./rs-capture

接下来我们配置realsense工作空间:

创建一个realsense_test_ws文件夹,进入文件夹下,打开终端:

mkdir src && cd src/

 下载功能包:

git clone -b ros1-legacy https://gitee.com/joosoo/realsense-ros.git realsense-ros

2c9b3f3767d845dcb4e2ace8830f6d7b.png

cd ..
catkin_make -j16 -DCATKIN_ENABLE_TESTING=False -DCMAKE_BUILD_TYPE=Release
catkin_make install

d66e547ed18645e380ba7beb0fd3c999.png

测试:

roslaunch realsense2_camera rs_camera.launch

d6c0eef6da874de9aff7596e3cc16a86.png

 还没安摄像头~

21.配置Kinova机械臂工作空间

mkdir -p kinova_test_ws/src
cd kinova_test_ws/src 
catkin_init_workspace

645ec87a65914495adcd474cda614d5f.png

cd ..
catkin_make
echo 'source /home/m0rtzz/Workspaces/kinova_test_ws/devel/setup.bash' >> ~/.bashrc
cd src/
git clone https://gitee.com/dva7777/kinova-ros.git kinova-ros
cd ..

安装缺少的moveit中相应的功能包 :

sudo apt-get install ros-melodic-moveit-visual-tools ros-melodic-moveit-ros-planning-interface
catkin_make -j16

0808ea44aa244c66b30562c0307c9594.png

sudo cp src/kinova-ros/kinova_driver/udev/10-kinova-arm.rules /etc/udev/rules.d/

 安装Moveit和pr2:

sudo apt-get install ros-melodic-moveit ros-melodic-trac-ik ros-melodic-pr2*

4c19506aeb7943caa635bc8a9b92cda9.png 完成~

22.配置机器人导航(实体)

安装 Arduino IDE:

https://www.arduino.cc/en/softwarehttps://www.arduino.cc/en/software

 下载Linux 64bit安装包

tar -xvf arduino-1.8.19-linux64.tar.xz
sudo mv arduino-1.8.19 /opt
cd /opt/arduino-1.8.19
sudo chmod +x install.sh
sudo ./install.sh
sudo apt install ros-melodic-move-base* ros-melodic-turtlebot3-* ros-melodic-dwa-local-planner
sudo apt-get install ros-melodic-joy ros-melodic-teleop-twist-joy ros-melodic-teleop-twist-keyboard ros-melodic-laser-proc ros-melodic-rgbd-launch ros-melodic-depthimage-to-laserscan ros-melodic-rosserial-arduino ros-melodic-rosserial-python ros-melodic-rosserial-server ros-melodic-rosserial-client ros-melodic-rosserial-msgs ros-melodic-amcl ros-melodic-map-server ros-melodic-move-base ros-melodic-urdf ros-melodic-xacro ros-melodic-compressed-image-transport ros-melodic-rqt-image-view ros-melodic-gmapping ros-melodic-navigation ros-melodic-interactive-markers

 安装 gmapping 包(用于构建地图):

sudo apt-get install ros-melodic-gmapping

安装地图服务包(用于保存与读取地图): 

sudo apt-get install ros-melodic-map-server

安装 navigation 包(用于定位以及路径规划): 

sudo apt-get install ros-melodic-navigation

因tf和tf2迁移问题,需将工作空间内的所有global_costmap_params.yaml和local_costmap_params.yaml文件里的头几行去掉“/”,返回工作空间根目录下重新编译。

Reference:

http://wiki.ros.org/tf2/Migrationhttp://wiki.ros.org/tf2/Migration

首先创建实体导航工作空间:

mkdir -p navigation_entity_test_ws/src

e6316e2fe5e941369669b43ab767ea9d.png

cd navigation_entity_test_ws/src
catkin_create_pkg entity_test roscpp rospy std_msgs  gmapping map_server amcl move_base

12f06d657996445fa8d8cac418d21147.png

cd .. && catkin_make

c5a44dee31014fcd9b8f97237e3f58e4.png

 查看一下文件目录,tree命令在下边的PS小节有讲怎么安装

tree .

f5242b23d16a43e88ce2626341f3ed33.png

cd src/ && catkin_create_pkg robot_start_test roscpp rospy std_msgs ros_arduino_python usb_cam rplidar_ros
cd robot_start_test/ && mkdir launch && cd launch && touch start_test.launch
<!--@File Name : start_test.launch 
    @Brief : 机器人启动文件:
        1.启动底盘
        2.启动激光雷达
        3.启动摄像头
 -->
 
<launch>
        <include file="$(find ros_arduino_python)/launch/arduino.launch" />
        <include file="$(find usb_cam)/launch/usb_cam-test.launch" />
        <include file="$(find rplidar_ros)/launch/rplidar.launch" />
</launch>

FIXME:Updating...

接下来创建机器人模型相关的功能包:

cd src/
catkin_create_pkg robot_description_test urdf xacro

0af4f65dceea471f94be94ef66fadbe2.png

 在功能包下新建 urdf 目录,编写具体的 urdf 文件(code命令是VSCode,没安装的小伙伴下边PS小节有下载网址~):

cd robot_description_test/ && mkdir urdf
cd urdf/ && touch {robot.urdf.xacro,robot_base.urdf.xacro,robot_camera.urdf.xacro,robot_laser.urdf.xacro} && code robot.urdf.xacro

将下列代码粘贴进去:

<!-- File Name : robot.urdf.xacro -->

<robot name="robot_test" xmlns:xacro="http://wiki.ros.org/xacro">

    <xacro:include filename="robot_base.urdf.xacro" />
    <xacro:include filename="robot_camera.urdf.xacro" />
    <xacro:include filename="robot_laser.urdf.xacro" />

</robot>

 保存退出,打开终端输入:

code robot_base.urdf.xacro

将下列代码粘贴进去:

<!-- File Name : robot_base.urdf.xacro -->

<robot name="robot_test" xmlns:xacro="http://wiki.ros.org/xacro">

    <xacro:property name="footprint_radius" value="0.001" />
    <link name="base_footprint">
        <visual>
            <geometry>
                <sphere radius="${footprint_radius}" />
            </geometry>
        </visual>
    </link>

    <xacro:property name="base_radius" value="0.1" />
    <xacro:property name="base_length" value="0.08" />
    <xacro:property name="lidi" value="0.015" />
    <xacro:property name="base_joint_z" value="${base_length / 2 + lidi}" />
    <link name="base_link">
        <visual>
            <geometry>
                <cylinder radius="0.1" length="0.08" />
            </geometry>

            <origin xyz="0 0 0" rpy="0 0 0" />

            <material name="baselink_color">
                <color rgba="1.0 0.5 0.2 0.5" />
            </material>
        </visual>

    </link>

    <joint name="link2footprint" type="fixed">
        <parent link="base_footprint"  />
        <child link="base_link" />
        <origin xyz="0 0 0.055" rpy="0 0 0" />
    </joint>

    <xacro:property name="wheel_radius" value="0.0325" />
    <xacro:property name="wheel_length" value="0.015" />
    <xacro:property name="PI" value="3.1415927" />
    <xacro:property name="wheel_joint_z" value="${(base_length / 2 + lidi - wheel_radius) * -1}" />

    <xacro:macro name="wheel_func" params="wheel_name flag">

        <link name="${wheel_name}_wheel">
            <visual>
                <geometry>
                    <cylinder radius="${wheel_radius}" length="${wheel_length}" />
                </geometry>

                <origin xyz="0 0 0" rpy="${PI / 2} 0 0" />

                <material name="wheel_color">
                    <color rgba="0 0 0 0.3" />
                </material>
            </visual>

        </link>

        <joint name="${wheel_name}2link" type="continuous">
            <parent link="base_link"  />
            <child link="${wheel_name}_wheel" />

            <origin xyz="0 ${0.1 * flag} ${wheel_joint_z}" rpy="0 0 0" />
            <axis xyz="0 1 0" />
        </joint>

    </xacro:macro>

    <xacro:wheel_func wheel_name="left" flag="1" />
    <xacro:wheel_func wheel_name="right" flag="-1" />

    <xacro:property name="small_wheel_radius" value="0.0075" />
    <xacro:property name="small_joint_z" value="${(base_length / 2 + lidi - small_wheel_radius) * -1}" />

    <xacro:macro name="small_wheel_func" params="small_wheel_name flag">
        <link name="${small_wheel_name}_wheel">
            <visual>
                <geometry>
                    <sphere radius="${small_wheel_radius}" />
                </geometry>

                <origin xyz="0 0 0" rpy="0 0 0" />

                <material name="wheel_color">
                    <color rgba="0 0 0 0.3" />
                </material>
            </visual>

        </link>

        <joint name="${small_wheel_name}2link" type="continuous">
            <parent link="base_link"  />
            <child link="${small_wheel_name}_wheel" />

            <origin xyz="${0.08 * flag} 0 ${small_joint_z}" rpy="0 0 0" />
            <axis xyz="0 1 0" />
        </joint>

    </xacro:macro >
    <xacro:small_wheel_func small_wheel_name="front" flag="1"/>
    <xacro:small_wheel_func small_wheel_name="back" flag="-1"/>

</robot>

  保存退出,打开终端输入:

code robot_camera.urdf.xacro

 将下列代码粘贴进去:

<!-- File Name : robot_camera.urdf.xacro -->

<robot name="robot_test" xmlns:xacro="http://wiki.ros.org/xacro">

    <xacro:property name="camera_length" value="0.02" /> 
    <xacro:property name="camera_width" value="0.05" /> 
    <xacro:property name="camera_height" value="0.05" /> 
    <xacro:property name="joint_camera_x" value="0.08" />
    <xacro:property name="joint_camera_y" value="0" />
    <xacro:property name="joint_camera_z" value="${base_length / 2 + camera_height / 2}" />

    <link name="camera">
        <visual>
            <geometry>
                <box size="${camera_length} ${camera_width} ${camera_height}" />
            </geometry>
            <origin xyz="0 0 0" rpy="0 0 0" />
            <material name="black">
                <color rgba="0 0 0 0.8" />
            </material>
        </visual>
    </link>

    <joint name="camera2base" type="fixed">
        <parent link="base_link" />
        <child link="camera" />
        <origin xyz="${joint_camera_x} ${joint_camera_y} ${joint_camera_z}" rpy="0 0 0" />
    </joint>

</robot>

   保存退出,打开终端输入:

code robot_laser.urdf.xacro

 将下列代码粘贴进去:

<!-- File Name : robot_laser.urdf.xacro -->

<robot name="robot_test" xmlns:xacro="http://wiki.ros.org/xacro">

    <xacro:property name="support_radius" value="0.01" />
    <xacro:property name="support_length" value="0.15" />

    <xacro:property name="laser_radius" value="0.03" />
    <xacro:property name="laser_length" value="0.05" />

    <xacro:property name="joint_support_x" value="0" />
    <xacro:property name="joint_support_y" value="0" />
    <xacro:property name="joint_support_z" value="${base_length / 2 + support_length / 2}" />

    <xacro:property name="joint_laser_x" value="0" />
    <xacro:property name="joint_laser_y" value="0" />
    <xacro:property name="joint_laser_z" value="${support_length / 2 + laser_length / 2}" />

    <link name="support">
        <visual>
            <geometry>
                <cylinder radius="${support_radius}" length="${support_length}" />
            </geometry>
            <material name="yellow">
                <color rgba="0.8 0.5 0.0 0.5" />
            </material>
        </visual>

    </link>

    <joint name="support2base" type="fixed">
        <parent link="base_link" />
        <child link="support"/>
        <origin xyz="${joint_support_x} ${joint_support_y} ${joint_support_z}" rpy="0 0 0" />
    </joint>
    <link name="laser">
        <visual>
            <geometry>
                <cylinder radius="${laser_radius}" length="${laser_length}" />
            </geometry>
            <material name="black">
                <color rgba="0 0 0 0.5" />
            </material>
        </visual>

    </link>

    <joint name="laser2support" type="fixed">
        <parent link="support" />
        <child link="laser"/>
        <origin xyz="${joint_laser_x} ${joint_laser_y} ${joint_laser_z}" rpy="0 0 0" />
    </joint>
</robot>

保存退出,打开终端:

cd .. && mkdir launch
touch robot_test.launch && code robot_test.launch

将下列代码粘贴进去:

<!-- File Name : robot_test.launch -->

<launch>
    <param name="robot_description" command="$(find xacro)/xacro $(find robot_description_test)/urdf/robot.urdf.xacro" />
    <node pkg="joint_state_publisher" name="joint_state_publisher" type="joint_state_publisher" />
    <node pkg="robot_state_publisher" name="robot_state_publisher" type="robot_state_publisher" />
</launch>

 保存退出,打开终端:

cd ../../../ && echo 'source /home/m0rtzz/Workspaces/navigation_entity_test_ws/devel/setup.bash' >> ~/.bashrc && source ~/.bashrc

 测试一下:

roslaunch robot_description_test robot_test.launch

756d60eb62c14cfe82eafa7e3bdf4862.png

之后Ctrl+Alt+T打开一个新的终端,输入:

rviz

4dc525d781d94b19bfe14f73cd68738f.png

将 Fixed Frame设置为base_footprint:c37069f5d4ba47cf94e637d64a15f416.png

 Add一个RobotModel:4111cf3ff31e4bda9b90de04c5d76e8a.png

 Add一个TF:

9b1fddd56a704702b30240024f4e7b65.png

cd src/entity_test/ && mkdir launch && cd launch/ 
touch gmapping.launch && code gmapping.launch

将下列代码粘贴进去:

<!-- File Name : gmapping.launch -->

<launch>
    <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
      <remap from="scan" to="scan"/>
      <param name="base_frame" value="base_footprint"/><!--底盘坐标系-->
      <param name="odom_frame" value="odom"/> <!--里程计坐标系-->
      <param name="map_update_interval" value="5.0"/>
      <param name="maxUrange" value="16.0"/>
      <param name="sigma" value="0.05"/>
      <param name="kernelSize" value="1"/>
      <param name="lstep" value="0.05"/>
      <param name="astep" value="0.05"/>
      <param name="iterations" value="5"/>
      <param name="lsigma" value="0.075"/>
      <param name="ogain" value="3.0"/>
      <param name="lskip" value="0"/>
      <param name="srr" value="0.1"/>
      <param name="srt" value="0.2"/>
      <param name="str" value="0.1"/>
      <param name="stt" value="0.2"/>
      <param name="linearUpdate" value="1.0"/>
      <param name="angularUpdate" value="0.5"/>
      <param name="temporalUpdate" value="3.0"/>
      <param name="resampleThreshold" value="0.5"/>
      <param name="particles" value="30"/>
      <param name="xmin" value="-50.0"/>
      <param name="ymin" value="-50.0"/>
      <param name="xmax" value="50.0"/>
      <param name="ymax" value="50.0"/>
      <param name="delta" value="0.05"/>
      <param name="llsamplerange" value="0.01"/>
      <param name="llsamplestep" value="0.01"/>
      <param name="lasamplerange" value="0.005"/>
      <param name="lasamplestep" value="0.005"/>
    </node>
</launch>
cd .. && mkdir map
cd launch && touch map_save.launch && code map_save.launch

将下列代码粘贴进去:

<!-- File Name : map_save.launch -->

<launch>
    <arg name="filename" value="$(find entity_test)/map/nav" />
    <node name="map_save" pkg="map_server" type="map_saver" args="-f $(arg filename)" />
</launch>
 touch map_server.launch && code map_server.launch

 将下列代码粘贴进去:

<!-- File Name : map_server.launch -->

<launch>
    <!-- 设置地图的配置文件 -->
    <arg name="map" default="nav.yaml" />
    <!-- 运行地图服务器,并且加载设置的地图-->
    <node name="map_server" pkg="map_server" type="map_server" args="$(find entity_test)/map/$(arg map)"/>
</launch>
touch amcl.launch && code amcl.launch

 将下列代码粘贴进去:

<!-- File Name : amcl.launch -->

<launch>
  <node pkg="amcl" type="amcl" name="amcl" output="screen">
    <!-- Publish scans from best pose at a max of 10 Hz -->
    <param name="odom_model_type" value="diff"/><!-- 里程计模式为差分 -->
    <param name="odom_alpha5" value="0.1"/>
    <param name="transform_tolerance" value="0.2" />
    <param name="gui_publish_rate" value="10.0"/>
    <param name="laser_max_beams" value="30"/>
    <param name="min_particles" value="500"/>
    <param name="max_particles" value="5000"/>
    <param name="kld_err" value="0.05"/>
    <param name="kld_z" value="0.99"/>
    <param name="odom_alpha1" value="0.2"/>
    <param name="odom_alpha2" value="0.2"/>
    <!-- translation std dev, m -->
    <param name="odom_alpha3" value="0.8"/>
    <param name="odom_alpha4" value="0.2"/>
    <param name="laser_z_hit" value="0.5"/>
    <param name="laser_z_short" value="0.05"/>
    <param name="laser_z_max" value="0.05"/>
    <param name="laser_z_rand" value="0.5"/>
    <param name="laser_sigma_hit" value="0.2"/>
    <param name="laser_lambda_short" value="0.1"/>
    <param name="laser_lambda_short" value="0.1"/>
    <param name="laser_model_type" value="likelihood_field"/>
    <!-- <param name="laser_model_type" value="beam"/> -->
    <param name="laser_likelihood_max_dist" value="2.0"/>
    <param name="update_min_d" value="0.2"/>
    <param name="update_min_a" value="0.5"/>

    <param name="odom_frame_id" value="odom"/><!-- 里程计坐标系 -->
    <param name="base_frame_id" value="base_footprint"/><!-- 添加机器人基坐标系 -->
    <param name="global_frame_id" value="map"/><!-- 添加地图坐标系 -->

  </node>
</launch>
cd .. && mkdir param && cd param/ && touch {costmap_common_params.yaml,local_costmap_params.yaml,global_costmap_params.yaml,base_local_planner_params.yaml} && code .

 将下列几个代码分别粘贴进去:

# File Name : base_local_planner_params.yaml

TrajectoryPlannerROS:

# Robot Configuration Parameters
  max_vel_x: 0.5 # X 方向最大速度
  min_vel_x: 0.1 # X 方向最小速速

  max_vel_theta:  1.0 # 
  min_vel_theta: -1.0
  min_in_place_vel_theta: 1.0

  acc_lim_x: 1.0 # X 加速限制
  acc_lim_y: 0.0 # Y 加速限制
  acc_lim_theta: 0.6 # 角速度加速限制

# Goal Tolerance Parameters,目标公差
  xy_goal_tolerance: 0.10
  yaw_goal_tolerance: 0.05

# Differential-drive robot configuration
# 是否是全向移动机器人
  holonomic_robot: false

# Forward Simulation Parameters,前进模拟参数
  sim_time: 0.8
  vx_samples: 18
  vtheta_samples: 20
  sim_granularity: 0.05
# File Name : cost_common_params.yaml

#机器人几何参,如果机器人是圆形,设置 robot_radius,如果是其他形状设置 footprint
robot_radius: 0.12 #圆形
# footprint: [[-0.12, -0.12], [-0.12, 0.12], [0.12, 0.12], [0.12, -0.12]] #其他形状

obstacle_range: 3.0 # 用于障碍物探测,比如: 值为 3.0,意味着检测到距离小于 3 米的障碍物时,就会引入代价地图
raytrace_range: 3.5 # 用于清除障碍物,比如:值为 3.5,意味着清除代价地图中 3.5 米以外的障碍物


#膨胀半径,扩展在碰撞区域以外的代价区域,使得机器人规划路径避开障碍物
inflation_radius: 0.2
#代价比例系数,越大则代价值越小
cost_scaling_factor: 3.0

#地图类型
map_type: costmap
#导航包所需要的传感器
observation_sources: scan
#对传感器的坐标系和数据进行配置。这个也会用于代价地图添加和清除障碍物。例如,你可以用激光雷达传感器用于在代价地图添加障碍物,再添加kinect用于导航和清除障碍物。
scan: {sensor_frame: laser, data_type: LaserScan, topic: scan, marking: true, clearing: true}
# File Name : global_costmap_params.yaml

global_costmap:
  global_frame: map #地图坐标系
  robot_base_frame: base_footprint #机器人坐标系
  # 以此实现坐标变换

  update_frequency: 1.0 #代价地图更新频率
  publish_frequency: 1.0 #代价地图的发布频率
  transform_tolerance: 0.5 #等待坐标变换发布信息的超时时间

  static_map: true # 是否使用一个地图或者地图服务器来初始化全局代价地图,如果不使用静态地图,这个参数为false.
# File Name : local_costmap_params.yaml

local_costmap:
  global_frame: odom #里程计坐标系
  robot_base_frame: base_footprint #机器人坐标系

  update_frequency: 10.0 #代价地图更新频率
  publish_frequency: 10.0 #代价地图的发布频率
  transform_tolerance: 0.5 #等待坐标变换发布信息的超时时间

  static_map: false  #不需要静态地图,可以提升导航效果
  rolling_window: true #是否使用动态窗口,默认为false,在静态的全局地图中,地图不会变化
  width: 3 # 局部地图宽度 单位是 m
  height: 3 # 局部地图高度 单位是 m
  resolution: 0.05 # 局部地图分辨率 单位是 m,一般与静态地图分辨率保持一致
cd ../launch && touch move_base.launch && code move_base.launch

将下列代码粘贴进去: 

<!-- File Name : move_base.launch -->

<launch>

    <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true">
        <rosparam file="$(find nav)/param/costmap_common_params.yaml" command="load" ns="global_costmap" />
        <rosparam file="$(find nav)/param/costmap_common_params.yaml" command="load" ns="local_costmap" />
        <rosparam file="$(find nav)/param/local_costmap_params.yaml" command="load" />
        <rosparam file="$(find nav)/param/global_costmap_params.yaml" command="load" />
        <rosparam file="$(find nav)/param/base_local_planner_params.yaml" command="load" />
    </node>

</launch>
touch auto_slam.launch && code auto_slam.launch

将下列代码粘贴进去:

<!-- File Name : auto_slam.launch -->

<launch>
    <!-- 启动SLAM节点 -->
    <include file="$(find entity_test)/launch/gmapping.launch" />
    <!-- 运行move_base节点 -->
    <include file="$(find entity_test)/launch/move_base.launch" />
</launch>

23.安装配置caffe

Reference:

https://blog.csdn.net/weixin_39161727/article/details/120136500https://blog.csdn.net/weixin_39161727/article/details/120136500首先安装依赖:

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 libatlas-base-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
 git clone https://gitee.com/quietbirds/caffe.git caffe
cd caffe/ && sudo cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#	You should not set this flag if you will be reading LMDBs with any
#	possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH := #-gencode arch=compute_20,code=sm_20 \
		#-gencode arch=compute_20,code=sm_21 \
		#-gencode arch=compute_30,code=sm_30 \
		-gencode arch=compute_35,code=sm_35 \
		-gencode arch=compute_50,code=sm_50 \
		-gencode arch=compute_52,code=sm_52 \
		-gencode arch=compute_60,code=sm_60 \
		-gencode arch=compute_61,code=sm_61 \
		-gencode arch=compute_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
		/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		# $(ANACONDA_HOME)/include/python2.7 \
		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
 PYTHON_LIBRARIES := boost_python3 python3.6m
 PYTHON_INCLUDE := /usr/include/python3.6m \
                 /usr/lib/python3.6/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @
sudo gedit Makefile
PROJECT := caffe

CONFIG_FILE := Makefile.config
# Explicitly check for the config file, otherwise make -k will proceed anyway.
ifeq ($(wildcard $(CONFIG_FILE)),)
$(error $(CONFIG_FILE) not found. See $(CONFIG_FILE).example.)
endif
include $(CONFIG_FILE)

BUILD_DIR_LINK := $(BUILD_DIR)
ifeq ($(RELEASE_BUILD_DIR),)
	RELEASE_BUILD_DIR := .$(BUILD_DIR)_release
endif
ifeq ($(DEBUG_BUILD_DIR),)
	DEBUG_BUILD_DIR := .$(BUILD_DIR)_debug
endif

DEBUG ?= 0
ifeq ($(DEBUG), 1)
	BUILD_DIR := $(DEBUG_BUILD_DIR)
	OTHER_BUILD_DIR := $(RELEASE_BUILD_DIR)
else
	BUILD_DIR := $(RELEASE_BUILD_DIR)
	OTHER_BUILD_DIR := $(DEBUG_BUILD_DIR)
endif

# All of the directories containing code.
SRC_DIRS := $(shell find * -type d -exec bash -c "find {} -maxdepth 1 \
	\( -name '*.cpp' -o -name '*.proto' \) | grep -q ." \; -print)

# The target shared library name
LIBRARY_NAME := $(PROJECT)
LIB_BUILD_DIR := $(BUILD_DIR)/lib
STATIC_NAME := $(LIB_BUILD_DIR)/lib$(LIBRARY_NAME).a
DYNAMIC_VERSION_MAJOR 		:= 1
DYNAMIC_VERSION_MINOR 		:= 0
DYNAMIC_VERSION_REVISION 	:= 0
DYNAMIC_NAME_SHORT := lib$(LIBRARY_NAME).so
#DYNAMIC_SONAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR)
DYNAMIC_VERSIONED_NAME_SHORT := $(DYNAMIC_NAME_SHORT).$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR).$(DYNAMIC_VERSION_REVISION)
DYNAMIC_NAME := $(LIB_BUILD_DIR)/$(DYNAMIC_VERSIONED_NAME_SHORT)
COMMON_FLAGS += -DCAFFE_VERSION=$(DYNAMIC_VERSION_MAJOR).$(DYNAMIC_VERSION_MINOR).$(DYNAMIC_VERSION_REVISION)

##############################
# Get all source files
##############################
# CXX_SRCS are the source files excluding the test ones.
CXX_SRCS := $(shell find src/$(PROJECT) ! -name "test_*.cpp" -name "*.cpp")
# CU_SRCS are the cuda source files
CU_SRCS := $(shell find src/$(PROJECT) ! -name "test_*.cu" -name "*.cu")
# TEST_SRCS are the test source files
TEST_MAIN_SRC := src/$(PROJECT)/test/test_caffe_main.cpp
TEST_SRCS := $(shell find src/$(PROJECT) -name "test_*.cpp")
TEST_SRCS := $(filter-out $(TEST_MAIN_SRC), $(TEST_SRCS))
TEST_CU_SRCS := $(shell find src/$(PROJECT) -name "test_*.cu")
GTEST_SRC := src/gtest/gtest-all.cpp
# TOOL_SRCS are the source files for the tool binaries
TOOL_SRCS := $(shell find tools -name "*.cpp")
# EXAMPLE_SRCS are the source files for the example binaries
EXAMPLE_SRCS := $(shell find examples -name "*.cpp")
# BUILD_INCLUDE_DIR contains any generated header files we want to include.
BUILD_INCLUDE_DIR := $(BUILD_DIR)/src
# PROTO_SRCS are the protocol buffer definitions
PROTO_SRC_DIR := src/$(PROJECT)/proto
PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto)
# PROTO_BUILD_DIR will contain the .cc and obj files generated from
# PROTO_SRCS; PROTO_BUILD_INCLUDE_DIR will contain the .h header files
PROTO_BUILD_DIR := $(BUILD_DIR)/$(PROTO_SRC_DIR)
PROTO_BUILD_INCLUDE_DIR := $(BUILD_INCLUDE_DIR)/$(PROJECT)/proto
# NONGEN_CXX_SRCS includes all source/header files except those generated
# automatically (e.g., by proto).
NONGEN_CXX_SRCS := $(shell find \
	src/$(PROJECT) \
	include/$(PROJECT) \
	python/$(PROJECT) \
	matlab/+$(PROJECT)/private \
	examples \
	tools \
	-name "*.cpp" -or -name "*.hpp" -or -name "*.cu" -or -name "*.cuh")
LINT_SCRIPT := scripts/cpp_lint.py
LINT_OUTPUT_DIR := $(BUILD_DIR)/.lint
LINT_EXT := lint.txt
LINT_OUTPUTS := $(addsuffix .$(LINT_EXT), $(addprefix $(LINT_OUTPUT_DIR)/, $(NONGEN_CXX_SRCS)))
EMPTY_LINT_REPORT := $(BUILD_DIR)/.$(LINT_EXT)
NONEMPTY_LINT_REPORT := $(BUILD_DIR)/$(LINT_EXT)
# PY$(PROJECT)_SRC is the python wrapper for $(PROJECT)
PY$(PROJECT)_SRC := python/$(PROJECT)/_$(PROJECT).cpp
PY$(PROJECT)_SO := python/$(PROJECT)/_$(PROJECT).so
PY$(PROJECT)_HXX := include/$(PROJECT)/layers/python_layer.hpp
# MAT$(PROJECT)_SRC is the mex entrance point of matlab package for $(PROJECT)
MAT$(PROJECT)_SRC := matlab/+$(PROJECT)/private/$(PROJECT)_.cpp
ifneq ($(MATLAB_DIR),)
	MAT_SO_EXT := $(shell $(MATLAB_DIR)/bin/mexext)
endif
MAT$(PROJECT)_SO := matlab/+$(PROJECT)/private/$(PROJECT)_.$(MAT_SO_EXT)

##############################
# Derive generated files
##############################
# The generated files for protocol buffers
PROTO_GEN_HEADER_SRCS := $(addprefix $(PROTO_BUILD_DIR)/, \
		$(notdir ${PROTO_SRCS:.proto=.pb.h}))
PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \
		$(notdir ${PROTO_SRCS:.proto=.pb.h}))
PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc})
PY_PROTO_BUILD_DIR := python/$(PROJECT)/proto
PY_PROTO_INIT := python/$(PROJECT)/proto/__init__.py
PROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py}, \
		$(PY_PROTO_BUILD_DIR)/$(notdir $(file)))
# The objects corresponding to the source files
# These objects will be linked into the final shared library, so we
# exclude the tool, example, and test objects.
CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o})
CU_OBJS := $(addprefix $(BUILD_DIR)/cuda/, ${CU_SRCS:.cu=.o})
PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}
OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
# tool, example, and test objects
TOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o})
TOOL_BUILD_DIR := $(BUILD_DIR)/tools
TEST_CXX_BUILD_DIR := $(BUILD_DIR)/src/$(PROJECT)/test
TEST_CU_BUILD_DIR := $(BUILD_DIR)/cuda/src/$(PROJECT)/test
TEST_CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o})
TEST_CU_OBJS := $(addprefix $(BUILD_DIR)/cuda/, ${TEST_CU_SRCS:.cu=.o})
TEST_OBJS := $(TEST_CXX_OBJS) $(TEST_CU_OBJS)
GTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o})
EXAMPLE_OBJS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o})
# Output files for automatic dependency generation
DEPS := ${CXX_OBJS:.o=.d} ${CU_OBJS:.o=.d} ${TEST_CXX_OBJS:.o=.d} \
	${TEST_CU_OBJS:.o=.d} $(BUILD_DIR)/${MAT$(PROJECT)_SO:.$(MAT_SO_EXT)=.d}
# tool, example, and test bins
TOOL_BINS := ${TOOL_OBJS:.o=.bin}
EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin}
# symlinks to tool bins without the ".bin" extension
TOOL_BIN_LINKS := ${TOOL_BINS:.bin=}
# Put the test binaries in build/test for convenience.
TEST_BIN_DIR := $(BUILD_DIR)/test
TEST_CU_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \
		$(foreach obj,$(TEST_CU_OBJS),$(basename $(notdir $(obj))))))
TEST_CXX_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \
		$(foreach obj,$(TEST_CXX_OBJS),$(basename $(notdir $(obj))))))
TEST_BINS := $(TEST_CXX_BINS) $(TEST_CU_BINS)
# TEST_ALL_BIN is the test binary that links caffe dynamically.
TEST_ALL_BIN := $(TEST_BIN_DIR)/test_all.testbin

##############################
# Derive compiler warning dump locations
##############################
WARNS_EXT := warnings.txt
CXX_WARNS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o.$(WARNS_EXT)})
CU_WARNS := $(addprefix $(BUILD_DIR)/cuda/, ${CU_SRCS:.cu=.o.$(WARNS_EXT)})
TOOL_WARNS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o.$(WARNS_EXT)})
EXAMPLE_WARNS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o.$(WARNS_EXT)})
TEST_WARNS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o.$(WARNS_EXT)})
TEST_CU_WARNS := $(addprefix $(BUILD_DIR)/cuda/, ${TEST_CU_SRCS:.cu=.o.$(WARNS_EXT)})
ALL_CXX_WARNS := $(CXX_WARNS) $(TOOL_WARNS) $(EXAMPLE_WARNS) $(TEST_WARNS)
ALL_CU_WARNS := $(CU_WARNS) $(TEST_CU_WARNS)
ALL_WARNS := $(ALL_CXX_WARNS) $(ALL_CU_WARNS)

EMPTY_WARN_REPORT := $(BUILD_DIR)/.$(WARNS_EXT)
NONEMPTY_WARN_REPORT := $(BUILD_DIR)/$(WARNS_EXT)

##############################
# Derive include and lib directories
##############################
CUDA_INCLUDE_DIR := $(CUDA_DIR)/include

CUDA_LIB_DIR :=
# add <cuda>/lib64 only if it exists
ifneq ("$(wildcard $(CUDA_DIR)/lib64)","")
	CUDA_LIB_DIR += $(CUDA_DIR)/lib64
endif
CUDA_LIB_DIR += $(CUDA_DIR)/lib

INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) ./src ./include
ifneq ($(CPU_ONLY), 1)
	INCLUDE_DIRS += $(CUDA_INCLUDE_DIR)
	LIBRARY_DIRS += $(CUDA_LIB_DIR)
	LIBRARIES := cudart cublas curand
endif

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

# handle IO dependencies
USE_LEVELDB ?= 1
USE_LMDB ?= 1
# This code is taken from https://github.com/sh1r0/caffe-android-lib
USE_HDF5 ?= 1
USE_OPENCV ?= 1

ifeq ($(USE_LEVELDB), 1)
	LIBRARIES += leveldb snappy
endif
ifeq ($(USE_LMDB), 1)
	LIBRARIES += lmdb
endif
# This code is taken from https://github.com/sh1r0/caffe-android-lib
ifeq ($(USE_HDF5), 1)
	LIBRARIES += hdf5_hl hdf5
endif
ifeq ($(USE_OPENCV), 1)
	LIBRARIES += opencv_core opencv_highgui opencv_imgproc

	ifeq ($(OPENCV_VERSION), 3)
		LIBRARIES += opencv_imgcodecs
	endif

endif
PYTHON_LIBRARIES ?= boost_python python2.7
WARNINGS := -Wall -Wno-sign-compare

##############################
# Set build directories
##############################

DISTRIBUTE_DIR ?= distribute
DISTRIBUTE_SUBDIRS := $(DISTRIBUTE_DIR)/bin $(DISTRIBUTE_DIR)/lib
DIST_ALIASES := dist
ifneq ($(strip $(DISTRIBUTE_DIR)),distribute)
		DIST_ALIASES += distribute
endif

ALL_BUILD_DIRS := $(sort $(BUILD_DIR) $(addprefix $(BUILD_DIR)/, $(SRC_DIRS)) \
	$(addprefix $(BUILD_DIR)/cuda/, $(SRC_DIRS)) \
	$(LIB_BUILD_DIR) $(TEST_BIN_DIR) $(PY_PROTO_BUILD_DIR) $(LINT_OUTPUT_DIR) \
	$(DISTRIBUTE_SUBDIRS) $(PROTO_BUILD_INCLUDE_DIR))

##############################
# Set directory for Doxygen-generated documentation
##############################
DOXYGEN_CONFIG_FILE ?= ./.Doxyfile
# should be the same as OUTPUT_DIRECTORY in the .Doxyfile
DOXYGEN_OUTPUT_DIR ?= ./doxygen
DOXYGEN_COMMAND ?= doxygen
# All the files that might have Doxygen documentation.
DOXYGEN_SOURCES := $(shell find \
	src/$(PROJECT) \
	include/$(PROJECT) \
	python/ \
	matlab/ \
	examples \
	tools \
	-name "*.cpp" -or -name "*.hpp" -or -name "*.cu" -or -name "*.cuh" -or \
        -name "*.py" -or -name "*.m")
DOXYGEN_SOURCES += $(DOXYGEN_CONFIG_FILE)


##############################
# Configure build
##############################

# Determine platform
UNAME := $(shell uname -s)
ifeq ($(UNAME), Linux)
	LINUX := 1
else ifeq ($(UNAME), Darwin)
	OSX := 1
	OSX_MAJOR_VERSION := $(shell sw_vers -productVersion | cut -f 1 -d .)
	OSX_MINOR_VERSION := $(shell sw_vers -productVersion | cut -f 2 -d .)
endif

# Linux
ifeq ($(LINUX), 1)
	CXX ?= /usr/bin/g++
	GCCVERSION := $(shell $(CXX) -dumpversion | cut -f1,2 -d.)
	# older versions of gcc are too dumb to build boost with -Wuninitalized
	ifeq ($(shell echo | awk '{exit $(GCCVERSION) < 4.6;}'), 1)
		WARNINGS += -Wno-uninitialized
	endif
	# boost::thread is reasonably called boost_thread (compare OS X)
	# We will also explicitly add stdc++ to the link target.
	LIBRARIES += boost_thread stdc++
	VERSIONFLAGS += -Wl,-soname,$(DYNAMIC_VERSIONED_NAME_SHORT) -Wl,-rpath,$(ORIGIN)/../lib
endif

# OS X:
# clang++ instead of g++
# libstdc++ for NVCC compatibility on OS X >= 10.9 with CUDA < 7.0
ifeq ($(OSX), 1)
	CXX := /usr/bin/clang++
	ifneq ($(CPU_ONLY), 1)
		CUDA_VERSION := $(shell $(CUDA_DIR)/bin/nvcc -V | grep -o 'release [0-9.]*' | tr -d '[a-z ]')
		ifeq ($(shell echo | awk '{exit $(CUDA_VERSION) < 7.0;}'), 1)
			CXXFLAGS += -stdlib=libstdc++
			LINKFLAGS += -stdlib=libstdc++
		endif
		# clang throws this warning for cuda headers
		WARNINGS += -Wno-unneeded-internal-declaration
		# 10.11 strips DYLD_* env vars so link CUDA (rpath is available on 10.5+)
		OSX_10_OR_LATER   := $(shell [ $(OSX_MAJOR_VERSION) -ge 10 ] && echo true)
		OSX_10_5_OR_LATER := $(shell [ $(OSX_MINOR_VERSION) -ge 5 ] && echo true)
		ifeq ($(OSX_10_OR_LATER),true)
			ifeq ($(OSX_10_5_OR_LATER),true)
				LDFLAGS += -Wl,-rpath,$(CUDA_LIB_DIR)
			endif
		endif
	endif
	# gtest needs to use its own tuple to not conflict with clang
	COMMON_FLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
	# boost::thread is called boost_thread-mt to mark multithreading on OS X
	LIBRARIES += boost_thread-mt
	# we need to explicitly ask for the rpath to be obeyed
	ORIGIN := @loader_path
	VERSIONFLAGS += -Wl,-install_name,@rpath/$(DYNAMIC_VERSIONED_NAME_SHORT) -Wl,-rpath,$(ORIGIN)/../../build/lib
else
	ORIGIN := \$$ORIGIN
endif

# Custom compiler
ifdef CUSTOM_CXX
	CXX := $(CUSTOM_CXX)
endif

# Static linking
ifneq (,$(findstring clang++,$(CXX)))
	STATIC_LINK_COMMAND := -Wl,-force_load $(STATIC_NAME)
else ifneq (,$(findstring g++,$(CXX)))
	STATIC_LINK_COMMAND := -Wl,--whole-archive $(STATIC_NAME) -Wl,--no-whole-archive
else
  # The following line must not be indented with a tab, since we are not inside a target
  $(error Cannot static link with the $(CXX) compiler)
endif

# Debugging
ifeq ($(DEBUG), 1)
	COMMON_FLAGS += -DDEBUG -g -O0
	NVCCFLAGS += -G
else
	COMMON_FLAGS += -DNDEBUG -O2
endif

# cuDNN acceleration configuration.
ifeq ($(USE_CUDNN), 1)
	LIBRARIES += cudnn
	COMMON_FLAGS += -DUSE_CUDNN
endif

# NCCL acceleration configuration
ifeq ($(USE_NCCL), 1)
	LIBRARIES += nccl
	COMMON_FLAGS += -DUSE_NCCL
endif

# configure IO libraries
ifeq ($(USE_OPENCV), 1)
	COMMON_FLAGS += -DUSE_OPENCV
endif
ifeq ($(USE_LEVELDB), 1)
	COMMON_FLAGS += -DUSE_LEVELDB
endif
ifeq ($(USE_LMDB), 1)
	COMMON_FLAGS += -DUSE_LMDB
ifeq ($(ALLOW_LMDB_NOLOCK), 1)
	COMMON_FLAGS += -DALLOW_LMDB_NOLOCK
endif
endif
# This code is taken from https://github.com/sh1r0/caffe-android-lib
ifeq ($(USE_HDF5), 1)
	COMMON_FLAGS += -DUSE_HDF5
endif

# CPU-only configuration
ifeq ($(CPU_ONLY), 1)
	OBJS := $(PROTO_OBJS) $(CXX_OBJS)
	TEST_OBJS := $(TEST_CXX_OBJS)
	TEST_BINS := $(TEST_CXX_BINS)
	ALL_WARNS := $(ALL_CXX_WARNS)
	TEST_FILTER := --gtest_filter="-*GPU*"
	COMMON_FLAGS += -DCPU_ONLY
endif

# Python layer support
ifeq ($(WITH_PYTHON_LAYER), 1)
	COMMON_FLAGS += -DWITH_PYTHON_LAYER
	LIBRARIES += $(PYTHON_LIBRARIES)
endif

# BLAS configuration (default = ATLAS)
BLAS ?= atlas
ifeq ($(BLAS), mkl)
	# MKL
	LIBRARIES += mkl_rt
	COMMON_FLAGS += -DUSE_MKL
	MKLROOT ?= /opt/intel/mkl
	BLAS_INCLUDE ?= $(MKLROOT)/include
	BLAS_LIB ?= $(MKLROOT)/lib $(MKLROOT)/lib/intel64
else ifeq ($(BLAS), open)
	# OpenBLAS
	LIBRARIES += openblas
else
	# ATLAS
	ifeq ($(LINUX), 1)
		ifeq ($(BLAS), atlas)
			# Linux simply has cblas and atlas
			LIBRARIES += cblas atlas
		endif
	else ifeq ($(OSX), 1)
		# OS X packages atlas as the vecLib framework
		LIBRARIES += cblas
		# 10.10 has accelerate while 10.9 has veclib
		XCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep 'version' | sed 's/[^0-9]*\([0-9]\).*/\1/')
		XCODE_CLT_GEQ_7 := $(shell [ $(XCODE_CLT_VER) -gt 6 ] && echo 1)
		XCODE_CLT_GEQ_6 := $(shell [ $(XCODE_CLT_VER) -gt 5 ] && echo 1)
		ifeq ($(XCODE_CLT_GEQ_7), 1)
			BLAS_INCLUDE ?= /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/$(shell ls /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ | sort | tail -1)/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/Headers
		else ifeq ($(XCODE_CLT_GEQ_6), 1)
			BLAS_INCLUDE ?= /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/
			LDFLAGS += -framework Accelerate
		else
			BLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
			LDFLAGS += -framework vecLib
		endif
	endif
endif
INCLUDE_DIRS += $(BLAS_INCLUDE)
LIBRARY_DIRS += $(BLAS_LIB)

LIBRARY_DIRS += $(LIB_BUILD_DIR)

# Automatic dependency generation (nvcc is handled separately)
CXXFLAGS += -MMD -MP

# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
# mex may invoke an older gcc that is too liberal with -Wuninitalized
MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)

USE_PKG_CONFIG ?= 0
ifeq ($(USE_PKG_CONFIG), 1)
	PKG_CONFIG := $(shell pkg-config opencv --libs)
else
	PKG_CONFIG :=
endif
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \
		$(foreach library,$(LIBRARIES),-l$(library))
PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))

# 'superclean' target recursively* deletes all files ending with an extension
# in $(SUPERCLEAN_EXTS) below.  This may be useful if you've built older
# versions of Caffe that do not place all generated files in a location known
# to the 'clean' target.
#
# 'supercleanlist' will list the files to be deleted by make superclean.
#
# * Recursive with the exception that symbolic links are never followed, per the
# default behavior of 'find'.
SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo

# Set the sub-targets of the 'everything' target.
EVERYTHING_TARGETS := all py$(PROJECT) test warn lint
# Only build matcaffe as part of "everything" if MATLAB_DIR is specified.
ifneq ($(MATLAB_DIR),)
	EVERYTHING_TARGETS += mat$(PROJECT)
endif

##############################
# Define build targets
##############################
.PHONY: all lib test clean docs linecount lint lintclean tools examples $(DIST_ALIASES) \
	py mat py$(PROJECT) mat$(PROJECT) proto runtest \
	superclean supercleanlist supercleanfiles warn everything

all: lib tools examples

lib: $(STATIC_NAME) $(DYNAMIC_NAME)

everything: $(EVERYTHING_TARGETS)

linecount:
	cloc --read-lang-def=$(PROJECT).cloc \
		src/$(PROJECT) include/$(PROJECT) tools examples \
		python matlab

lint: $(EMPTY_LINT_REPORT)

lintclean:
	@ $(RM) -r $(LINT_OUTPUT_DIR) $(EMPTY_LINT_REPORT) $(NONEMPTY_LINT_REPORT)

docs: $(DOXYGEN_OUTPUT_DIR)
	@ cd ./docs ; ln -sfn ../$(DOXYGEN_OUTPUT_DIR)/html doxygen

$(DOXYGEN_OUTPUT_DIR): $(DOXYGEN_CONFIG_FILE) $(DOXYGEN_SOURCES)
	$(DOXYGEN_COMMAND) $(DOXYGEN_CONFIG_FILE)

$(EMPTY_LINT_REPORT): $(LINT_OUTPUTS) | $(BUILD_DIR)
	@ cat $(LINT_OUTPUTS) > $@
	@ if [ -s "$@" ]; then \
		cat $@; \
		mv $@ $(NONEMPTY_LINT_REPORT); \
		echo "Found one or more lint errors."; \
		exit 1; \
	  fi; \
	  $(RM) $(NONEMPTY_LINT_REPORT); \
	  echo "No lint errors!";

$(LINT_OUTPUTS): $(LINT_OUTPUT_DIR)/%.lint.txt : % $(LINT_SCRIPT) | $(LINT_OUTPUT_DIR)
	@ mkdir -p $(dir $@)
	@ python $(LINT_SCRIPT) $< 2>&1 \
		| grep -v "^Done processing " \
		| grep -v "^Total errors found: 0" \
		> $@ \
		|| true

test: $(TEST_ALL_BIN) $(TEST_ALL_DYNLINK_BIN) $(TEST_BINS)

tools: $(TOOL_BINS) $(TOOL_BIN_LINKS)

examples: $(EXAMPLE_BINS)

py$(PROJECT): py

py: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY)

$(PY$(PROJECT)_SO): $(PY$(PROJECT)_SRC) $(PY$(PROJECT)_HXX) | $(DYNAMIC_NAME)
	@ echo CXX/LD -o $@ $<
	$(Q)$(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \
		-o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(PYTHON_LDFLAGS) \
		-Wl,-rpath,$(ORIGIN)/../../build/lib

mat$(PROJECT): mat

mat: $(MAT$(PROJECT)_SO)

$(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME)
	@ if [ -z "$(MATLAB_DIR)" ]; then \
		echo "MATLAB_DIR must be specified in $(CONFIG_FILE)" \
			"to build mat$(PROJECT)."; \
		exit 1; \
	fi
	@ echo MEX $<
	$(Q)$(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) \
			CXX="$(CXX)" \
			CXXFLAGS="\$$CXXFLAGS $(MATLAB_CXXFLAGS)" \
			CXXLIBS="\$$CXXLIBS $(STATIC_LINK_COMMAND) $(LDFLAGS)" -output $@
	@ if [ -f "$(PROJECT)_.d" ]; then \
		mv -f $(PROJECT)_.d $(BUILD_DIR)/${MAT$(PROJECT)_SO:.$(MAT_SO_EXT)=.d}; \
	fi

runtest: $(TEST_ALL_BIN)
	$(TOOL_BUILD_DIR)/caffe
	$(TEST_ALL_BIN) $(TEST_GPUID) --gtest_shuffle $(TEST_FILTER)

pytest: py
	cd python; python -m unittest discover -s caffe/test

mattest: mat
	cd matlab; $(MATLAB_DIR)/bin/matlab -nodisplay -r 'caffe.run_tests(), exit()'

warn: $(EMPTY_WARN_REPORT)

$(EMPTY_WARN_REPORT): $(ALL_WARNS) | $(BUILD_DIR)
	@ cat $(ALL_WARNS) > $@
	@ if [ -s "$@" ]; then \
		cat $@; \
		mv $@ $(NONEMPTY_WARN_REPORT); \
		echo "Compiler produced one or more warnings."; \
		exit 1; \
	  fi; \
	  $(RM) $(NONEMPTY_WARN_REPORT); \
	  echo "No compiler warnings!";

$(ALL_WARNS): %.o.$(WARNS_EXT) : %.o

$(BUILD_DIR_LINK): $(BUILD_DIR)/.linked

# Create a target ".linked" in this BUILD_DIR to tell Make that the "build" link
# is currently correct, then delete the one in the OTHER_BUILD_DIR in case it
# exists and $(DEBUG) is toggled later.
$(BUILD_DIR)/.linked:
	@ mkdir -p $(BUILD_DIR)
	@ $(RM) $(OTHER_BUILD_DIR)/.linked
	@ $(RM) -r $(BUILD_DIR_LINK)
	@ ln -s $(BUILD_DIR) $(BUILD_DIR_LINK)
	@ touch $@

$(ALL_BUILD_DIRS): | $(BUILD_DIR_LINK)
	@ mkdir -p $@

$(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
	@ echo LD -o $@
	$(Q)$(CXX) -shared -o $@ $(OBJS) $(VERSIONFLAGS) $(LINKFLAGS) $(LDFLAGS)
	@ cd $(BUILD_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT);   ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_NAME_SHORT)

$(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
	@ echo AR -o $@
	$(Q)ar rcs $@ $(OBJS)

$(BUILD_DIR)/%.o: %.cpp $(PROTO_GEN_HEADER) | $(ALL_BUILD_DIRS)
	@ echo CXX $<
	$(Q)$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
		|| (cat $@.$(WARNS_EXT); exit 1)
	@ cat $@.$(WARNS_EXT)

$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \
		| $(PROTO_BUILD_DIR)
	@ echo CXX $<
	$(Q)$(CXX) $< $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
		|| (cat $@.$(WARNS_EXT); exit 1)
	@ cat $@.$(WARNS_EXT)

$(BUILD_DIR)/cuda/%.o: %.cu | $(ALL_BUILD_DIRS)
	@ echo NVCC $<
	$(Q)$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -M $< -o ${@:.o=.d} \
		-odir $(@D)
	$(Q)$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ 2> $@.$(WARNS_EXT) \
		|| (cat $@.$(WARNS_EXT); exit 1)
	@ cat $@.$(WARNS_EXT)

$(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
		| $(DYNAMIC_NAME) $(TEST_BIN_DIR)
	@ echo CXX/LD -o $@ $<
	$(Q)$(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) \
		-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib

$(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \
	$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
	@ echo LD $<
	$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
		-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib

$(TEST_CXX_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CXX_BUILD_DIR)/%.o \
	$(GTEST_OBJ) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
	@ echo LD $<
	$(Q)$(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) \
		-o $@ $(LINKFLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib

# Target for extension-less symlinks to tool binaries with extension '*.bin'.
$(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
	@ $(RM) $@
	@ ln -s $(notdir $<) $@

$(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME)
	@ echo CXX/LD -o $@
	$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
		-Wl,-rpath,$(ORIGIN)/../lib

$(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME)
	@ echo CXX/LD -o $@
	$(Q)$(CXX) $< -o $@ $(LINKFLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
		-Wl,-rpath,$(ORIGIN)/../../lib

proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)

$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \
		$(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR)
	@ echo PROTOC $<
	$(Q)protoc --proto_path=$(PROTO_SRC_DIR) --cpp_out=$(PROTO_BUILD_DIR) $<

$(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \
		$(PY_PROTO_INIT) | $(PY_PROTO_BUILD_DIR)
	@ echo PROTOC \(python\) $<
	$(Q)protoc --proto_path=src --python_out=python $<

$(PY_PROTO_INIT): | $(PY_PROTO_BUILD_DIR)
	touch $(PY_PROTO_INIT)

clean:
	@- $(RM) -rf $(ALL_BUILD_DIRS)
	@- $(RM) -rf $(OTHER_BUILD_DIR)
	@- $(RM) -rf $(BUILD_DIR_LINK)
	@- $(RM) -rf $(DISTRIBUTE_DIR)
	@- $(RM) $(PY$(PROJECT)_SO)
	@- $(RM) $(MAT$(PROJECT)_SO)

supercleanfiles:
	$(eval SUPERCLEAN_FILES := $(strip \
			$(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)' \
			-not -path './data/*'))))

supercleanlist: supercleanfiles
	@ \
	if [ -z "$(SUPERCLEAN_FILES)" ]; then \
		echo "No generated files found."; \
	else \
		echo $(SUPERCLEAN_FILES) | tr ' ' '\n'; \
	fi

superclean: clean supercleanfiles
	@ \
	if [ -z "$(SUPERCLEAN_FILES)" ]; then \
		echo "No generated files found."; \
	else \
		echo "Deleting the following generated files:"; \
		echo $(SUPERCLEAN_FILES) | tr ' ' '\n'; \
		$(RM) $(SUPERCLEAN_FILES); \
	fi

$(DIST_ALIASES): $(DISTRIBUTE_DIR)

$(DISTRIBUTE_DIR): all py | $(DISTRIBUTE_SUBDIRS)
	# add proto
	cp -r src/caffe/proto $(DISTRIBUTE_DIR)/
	# add include
	cp -r include $(DISTRIBUTE_DIR)/
	mkdir -p $(DISTRIBUTE_DIR)/include/caffe/proto
	cp $(PROTO_GEN_HEADER_SRCS) $(DISTRIBUTE_DIR)/include/caffe/proto
	# add tool and example binaries
	cp $(TOOL_BINS) $(DISTRIBUTE_DIR)/bin
	cp $(EXAMPLE_BINS) $(DISTRIBUTE_DIR)/bin
	# add libraries
	cp $(STATIC_NAME) $(DISTRIBUTE_DIR)/lib
	install -m 644 $(DYNAMIC_NAME) $(DISTRIBUTE_DIR)/lib
	cd $(DISTRIBUTE_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT);   ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_NAME_SHORT)
	# add python - it's not the standard way, indeed...
	cp -r python $(DISTRIBUTE_DIR)/

-include $(DEPS)
cd python/

使用阿里云镜像安装依赖库:

for req in $(cat requirements.txt); do pip3 install $req -i https://mirrors.aliyun.com/pypi/simple/; done 
cd .. && sudo make clean
sudo make all -j16

 由于caffe最后支持的版本是cuDNN7.6.5,为了能在cuDNN8的环境下编译通过,需要修改两个cpp文件,路径为/caffe/src/caffe/layers下的cudnn_conv_layer.cpp和cudnn_deconv_layer.cpp两个文件,分别将他们内容替换为:

/**
 * @File Name : cudnn_conv_layer.cpp
 */

#ifdef USE_CUDNN
#include <algorithm>
#include <vector>

#include "caffe/layers/cudnn_conv_layer.hpp"

namespace caffe
{

// Set to three for the benefit of the backward pass, which
// can use separate streams for calculating the gradient w.r.t.
// bias, filter weights, and bottom data for each group independently
#define CUDNN_STREAMS_PER_GROUP 3

  /**
   * TODO(dox) explain cuDNN interface
   */
  template <typename Dtype>
  void CuDNNConvolutionLayer<Dtype>::LayerSetUp(
      const vector<Blob<Dtype> *> &bottom, const vector<Blob<Dtype> *> &top)
  {
    ConvolutionLayer<Dtype>::LayerSetUp(bottom, top);
    // Initialize CUDA streams and cuDNN.
    stream_ = new cudaStream_t[this->group_ * CUDNN_STREAMS_PER_GROUP];
    handle_ = new cudnnHandle_t[this->group_ * CUDNN_STREAMS_PER_GROUP];

    // Initialize algorithm arrays
    fwd_algo_ = new cudnnConvolutionFwdAlgo_t[bottom.size()];
    bwd_filter_algo_ = new cudnnConvolutionBwdFilterAlgo_t[bottom.size()];
    bwd_data_algo_ = new cudnnConvolutionBwdDataAlgo_t[bottom.size()];

    // initialize size arrays
    workspace_fwd_sizes_ = new size_t[bottom.size()];
    workspace_bwd_filter_sizes_ = new size_t[bottom.size()];
    workspace_bwd_data_sizes_ = new size_t[bottom.size()];

    // workspace data
    workspaceSizeInBytes = 0;
    workspaceData = NULL;
    workspace = new void *[this->group_ * CUDNN_STREAMS_PER_GROUP];

    for (size_t i = 0; i < bottom.size(); ++i)
    {
      // initialize all to default algorithms
      fwd_algo_[i] = (cudnnConvolutionFwdAlgo_t)0;
      bwd_filter_algo_[i] = (cudnnConvolutionBwdFilterAlgo_t)0;
      bwd_data_algo_[i] = (cudnnConvolutionBwdDataAlgo_t)0;
      // default algorithms don't require workspace
      workspace_fwd_sizes_[i] = 0;
      workspace_bwd_data_sizes_[i] = 0;
      workspace_bwd_filter_sizes_[i] = 0;
    }

    for (int g = 0; g < this->group_ * CUDNN_STREAMS_PER_GROUP; g++)
    {
      CUDA_CHECK(cudaStreamCreate(&stream_[g]));
      CUDNN_CHECK(cudnnCreate(&handle_[g]));
      CUDNN_CHECK(cudnnSetStream(handle_[g], stream_[g]));
      workspace[g] = NULL;
    }

    // Set the indexing parameters.
    bias_offset_ = (this->num_output_ / this->group_);

    // Create filter descriptor.
    const int *kernel_shape_data = this->kernel_shape_.cpu_data();
    const int kernel_h = kernel_shape_data[0];
    const int kernel_w = kernel_shape_data[1];
    cudnn::createFilterDesc<Dtype>(&filter_desc_,
                                   this->num_output_ / this->group_, this->channels_ / this->group_,
                                   kernel_h, kernel_w);

    // Create tensor descriptor(s) for data and corresponding convolution(s).
    for (int i = 0; i < bottom.size(); i++)
    {
      cudnnTensorDescriptor_t bottom_desc;
      cudnn::createTensor4dDesc<Dtype>(&bottom_desc);
      bottom_descs_.push_back(bottom_desc);
      cudnnTensorDescriptor_t top_desc;
      cudnn::createTensor4dDesc<Dtype>(&top_desc);
      top_descs_.push_back(top_desc);
      cudnnConvolutionDescriptor_t conv_desc;
      cudnn::createConvolutionDesc<Dtype>(&conv_desc);
      conv_descs_.push_back(conv_desc);
    }

    // Tensor descriptor for bias.
    if (this->bias_term_)
    {
      cudnn::createTensor4dDesc<Dtype>(&bias_desc_);
    }

    handles_setup_ = true;
  }

  template <typename Dtype>
  void CuDNNConvolutionLayer<Dtype>::Reshape(
      const vector<Blob<Dtype> *> &bottom, const vector<Blob<Dtype> *> &top)
  {
    ConvolutionLayer<Dtype>::Reshape(bottom, top);
    CHECK_EQ(2, this->num_spatial_axes_)
        << "CuDNNConvolution input must have 2 spatial axes "
        << "(e.g., height and width). "
        << "Use 'engine: CAFFE' for general ND convolution.";
    bottom_offset_ = this->bottom_dim_ / this->group_;
    top_offset_ = this->top_dim_ / this->group_;
    const int height = bottom[0]->shape(this->channel_axis_ + 1);
    const int width = bottom[0]->shape(this->channel_axis_ + 2);
    const int height_out = top[0]->shape(this->channel_axis_ + 1);
    const int width_out = top[0]->shape(this->channel_axis_ + 2);
    const int *pad_data = this->pad_.cpu_data();
    const int pad_h = pad_data[0];
    const int pad_w = pad_data[1];
    const int *stride_data = this->stride_.cpu_data();
    const int stride_h = stride_data[0];
    const int stride_w = stride_data[1];
#if CUDNN_VERSION_MIN(8, 0, 0)
    int RetCnt;
    bool found_conv_algorithm;
    size_t free_memory, total_memory;
    cudnnConvolutionFwdAlgoPerf_t fwd_algo_pref_[4];
    cudnnConvolutionBwdDataAlgoPerf_t bwd_data_algo_pref_[4];

    // get memory sizes
    cudaMemGetInfo(&free_memory, &total_memory);
#else
    // Specify workspace limit for kernels directly until we have a
    // planning strategy and a rewrite of Caffe's GPU memory mangagement
    size_t workspace_limit_bytes = 8 * 1024 * 1024;
#endif
    for (int i = 0; i < bottom.size(); i++)
    {
      cudnn::setTensor4dDesc<Dtype>(&bottom_descs_[i],
                                    this->num_,
                                    this->channels_ / this->group_, height, width,
                                    this->channels_ * height * width,
                                    height * width, width, 1);
      cudnn::setTensor4dDesc<Dtype>(&top_descs_[i],
                                    this->num_,
                                    this->num_output_ / this->group_, height_out, width_out,
                                    this->num_output_ * this->out_spatial_dim_,
                                    this->out_spatial_dim_, width_out, 1);
      cudnn::setConvolutionDesc<Dtype>(&conv_descs_[i], bottom_descs_[i],
                                       filter_desc_, pad_h, pad_w,
                                       stride_h, stride_w);

#if CUDNN_VERSION_MIN(8, 0, 0)
      // choose forward algorithm for filter
      // in forward filter the CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED is not implemented in cuDNN 8
      CUDNN_CHECK(cudnnGetConvolutionForwardAlgorithm_v7(handle_[0],
                                                         bottom_descs_[i],
                                                         filter_desc_,
                                                         conv_descs_[i],
                                                         top_descs_[i],
                                                         4,
                                                         &RetCnt,
                                                         fwd_algo_pref_));

      found_conv_algorithm = false;
      for (int n = 0; n < RetCnt; n++)
      {
        if (fwd_algo_pref_[n].status == CUDNN_STATUS_SUCCESS &&
            fwd_algo_pref_[n].algo != CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED &&
            fwd_algo_pref_[n].memory < free_memory)
        {
          found_conv_algorithm = true;
          fwd_algo_[i] = fwd_algo_pref_[n].algo;
          workspace_fwd_sizes_[i] = fwd_algo_pref_[n].memory;
          break;
        }
      }
      if (!found_conv_algorithm)
        LOG(ERROR) << "cuDNN did not return a suitable algorithm for convolution.";
      else
      {
        // choose backward algorithm for filter
        // for better or worse, just a fixed constant due to the missing
        // cudnnGetConvolutionBackwardFilterAlgorithm in cuDNN version 8.0
        bwd_filter_algo_[i] = CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0;
        // twice the amount of the forward search to be save
        workspace_bwd_filter_sizes_[i] = 2 * workspace_fwd_sizes_[i];
      }

      // choose backward algo for data
      CUDNN_CHECK(cudnnGetConvolutionBackwardDataAlgorithm_v7(handle_[0],
                                                              filter_desc_,
                                                              top_descs_[i],
                                                              conv_descs_[i],
                                                              bottom_descs_[i],
                                                              4,
                                                              &RetCnt,
                                                              bwd_data_algo_pref_));

      found_conv_algorithm = false;
      for (int n = 0; n < RetCnt; n++)
      {
        if (bwd_data_algo_pref_[n].status == CUDNN_STATUS_SUCCESS &&
            bwd_data_algo_pref_[n].algo != CUDNN_CONVOLUTION_BWD_DATA_ALGO_WINOGRAD &&
            bwd_data_algo_pref_[n].algo != CUDNN_CONVOLUTION_BWD_DATA_ALGO_WINOGRAD_NONFUSED &&
            bwd_data_algo_pref_[n].memory < free_memory)
        {
          found_conv_algorithm = true;
          bwd_data_algo_[i] = bwd_data_algo_pref_[n].algo;
          workspace_bwd_data_sizes_[i] = bwd_data_algo_pref_[n].memory;
          break;
        }
      }
      if (!found_conv_algorithm)
        LOG(ERROR) << "cuDNN did not return a suitable algorithm for convolution.";
#else
      // choose forward and backward algorithms + workspace(s)
      CUDNN_CHECK(cudnnGetConvolutionForwardAlgorithm(handle_[0],
                                                      bottom_descs_[i],
                                                      filter_desc_,
                                                      conv_descs_[i],
                                                      top_descs_[i],
                                                      CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT,
                                                      workspace_limit_bytes,
                                                      &fwd_algo_[i]));

      CUDNN_CHECK(cudnnGetConvolutionForwardWorkspaceSize(handle_[0],
                                                          bottom_descs_[i],
                                                          filter_desc_,
                                                          conv_descs_[i],
                                                          top_descs_[i],
                                                          fwd_algo_[i],
                                                          &(workspace_fwd_sizes_[i])));

      // choose backward algorithm for filter
      CUDNN_CHECK(cudnnGetConvolutionBackwardFilterAlgorithm(handle_[0],
                                                             bottom_descs_[i], top_descs_[i], conv_descs_[i], filter_desc_,
                                                             CUDNN_CONVOLUTION_BWD_FILTER_SPECIFY_WORKSPACE_LIMIT,
                                                             workspace_limit_bytes, &bwd_filter_algo_[i]));

      // get workspace for backwards filter algorithm
      CUDNN_CHECK(cudnnGetConvolutionBackwardFilterWorkspaceSize(handle_[0],
                                                                 bottom_descs_[i], top_descs_[i], conv_descs_[i], filter_desc_,
                                                                 bwd_filter_algo_[i], &workspace_bwd_filter_sizes_[i]));

      // choose backward algo for data
      CUDNN_CHECK(cudnnGetConvolutionBackwardDataAlgorithm(handle_[0],
                                                           filter_desc_, top_descs_[i], conv_descs_[i], bottom_descs_[i],
                                                           CUDNN_CONVOLUTION_BWD_DATA_SPECIFY_WORKSPACE_LIMIT,
                                                           workspace_limit_bytes, &bwd_data_algo_[i]));

      // get workspace size
      CUDNN_CHECK(cudnnGetConvolutionBackwardDataWorkspaceSize(handle_[0],
                                                               filter_desc_, top_descs_[i], conv_descs_[i], bottom_descs_[i],
                                                               bwd_data_algo_[i], &workspace_bwd_data_sizes_[i]));
#endif
    }
    // reduce over all workspace sizes to get a maximum to allocate / reallocate
    size_t total_workspace_fwd = 0;
    size_t total_workspace_bwd_data = 0;
    size_t total_workspace_bwd_filter = 0;

    for (size_t i = 0; i < bottom.size(); i++)
    {
      total_workspace_fwd = std::max(total_workspace_fwd,
                                     workspace_fwd_sizes_[i]);
      total_workspace_bwd_data = std::max(total_workspace_bwd_data,
                                          workspace_bwd_data_sizes_[i]);
      total_workspace_bwd_filter = std::max(total_workspace_bwd_filter,
                                            workspace_bwd_filter_sizes_[i]);
    }
    // get max over all operations
    size_t max_workspace = std::max(total_workspace_fwd,
                                    total_workspace_bwd_data);
    max_workspace = std::max(max_workspace, total_workspace_bwd_filter);
    // ensure all groups have enough workspace
    size_t total_max_workspace = max_workspace *
                                 (this->group_ * CUDNN_STREAMS_PER_GROUP);

    // this is the total amount of storage needed over all groups + streams
    if (total_max_workspace > workspaceSizeInBytes)
    {
      DLOG(INFO) << "Reallocating workspace storage: " << total_max_workspace;
      workspaceSizeInBytes = total_max_workspace;

      // free the existing workspace and allocate a new (larger) one
      cudaFree(this->workspaceData);

      cudaError_t err = cudaMalloc(&(this->workspaceData), workspaceSizeInBytes);
      if (err != cudaSuccess)
      {
        // force zero memory path
        for (int i = 0; i < bottom.size(); i++)
        {
          workspace_fwd_sizes_[i] = 0;
          workspace_bwd_filter_sizes_[i] = 0;
          workspace_bwd_data_sizes_[i] = 0;
          fwd_algo_[i] = CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM;
          bwd_filter_algo_[i] = CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0;
          bwd_data_algo_[i] = CUDNN_CONVOLUTION_BWD_DATA_ALGO_0;
        }

        // NULL out all workspace pointers
        for (int g = 0; g < (this->group_ * CUDNN_STREAMS_PER_GROUP); g++)
        {
          workspace[g] = NULL;
        }
        // NULL out underlying data
        workspaceData = NULL;
        workspaceSizeInBytes = 0;
      }

      // if we succeed in the allocation, set pointer aliases for workspaces
      for (int g = 0; g < (this->group_ * CUDNN_STREAMS_PER_GROUP); g++)
      {
        workspace[g] = reinterpret_cast<char *>(workspaceData) + g * max_workspace;
      }
    }

    // Tensor descriptor for bias.
    if (this->bias_term_)
    {
      cudnn::setTensor4dDesc<Dtype>(&bias_desc_,
                                    1, this->num_output_ / this->group_, 1, 1);
    }
  }

  template <typename Dtype>
  CuDNNConvolutionLayer<Dtype>::~CuDNNConvolutionLayer()
  {
    // Check that handles have been setup before destroying.
    if (!handles_setup_)
    {
      return;
    }

    for (int i = 0; i < bottom_descs_.size(); i++)
    {
      cudnnDestroyTensorDescriptor(bottom_descs_[i]);
      cudnnDestroyTensorDescriptor(top_descs_[i]);
      cudnnDestroyConvolutionDescriptor(conv_descs_[i]);
    }
    if (this->bias_term_)
    {
      cudnnDestroyTensorDescriptor(bias_desc_);
    }
    cudnnDestroyFilterDescriptor(filter_desc_);

    for (int g = 0; g < this->group_ * CUDNN_STREAMS_PER_GROUP; g++)
    {
      cudaStreamDestroy(stream_[g]);
      cudnnDestroy(handle_[g]);
    }

    cudaFree(workspaceData);
    delete[] stream_;
    delete[] handle_;
    delete[] fwd_algo_;
    delete[] bwd_filter_algo_;
    delete[] bwd_data_algo_;
    delete[] workspace_fwd_sizes_;
    delete[] workspace_bwd_data_sizes_;
    delete[] workspace_bwd_filter_sizes_;
  }

  INSTANTIATE_CLASS(CuDNNConvolutionLayer);

} // namespace caffe
#endif
/**
 * @File Name : cudnn_deconv_layer.cpp
 */

#ifdef USE_CUDNN
#include <algorithm>
#include <vector>

#include "caffe/layers/cudnn_deconv_layer.hpp"

namespace caffe
{

// Set to three for the benefit of the backward pass, which
// can use separate streams for calculating the gradient w.r.t.
// bias, filter weights, and bottom data for each group independently
#define CUDNN_STREAMS_PER_GROUP 3

  /**
   * TODO(dox) explain cuDNN interface
   */
  template <typename Dtype>
  void CuDNNDeconvolutionLayer<Dtype>::LayerSetUp(
      const vector<Blob<Dtype> *> &bottom, const vector<Blob<Dtype> *> &top)
  {
    DeconvolutionLayer<Dtype>::LayerSetUp(bottom, top);
    // Initialize CUDA streams and cuDNN.
    stream_ = new cudaStream_t[this->group_ * CUDNN_STREAMS_PER_GROUP];
    handle_ = new cudnnHandle_t[this->group_ * CUDNN_STREAMS_PER_GROUP];

    // Initialize algorithm arrays
    fwd_algo_ = new cudnnConvolutionFwdAlgo_t[bottom.size()];
    bwd_filter_algo_ = new cudnnConvolutionBwdFilterAlgo_t[bottom.size()];
    bwd_data_algo_ = new cudnnConvolutionBwdDataAlgo_t[bottom.size()];

    // initialize size arrays
    workspace_fwd_sizes_ = new size_t[bottom.size()];
    workspace_bwd_filter_sizes_ = new size_t[bottom.size()];
    workspace_bwd_data_sizes_ = new size_t[bottom.size()];

    // workspace data
    workspaceSizeInBytes = 0;
    workspaceData = NULL;
    workspace = new void *[this->group_ * CUDNN_STREAMS_PER_GROUP];

    for (size_t i = 0; i < bottom.size(); ++i)
    {
      // initialize all to default algorithms
      fwd_algo_[i] = (cudnnConvolutionFwdAlgo_t)0;
      bwd_filter_algo_[i] = (cudnnConvolutionBwdFilterAlgo_t)0;
      bwd_data_algo_[i] = (cudnnConvolutionBwdDataAlgo_t)0;
      // default algorithms don't require workspace
      workspace_fwd_sizes_[i] = 0;
      workspace_bwd_data_sizes_[i] = 0;
      workspace_bwd_filter_sizes_[i] = 0;
    }

    for (int g = 0; g < this->group_ * CUDNN_STREAMS_PER_GROUP; g++)
    {
      CUDA_CHECK(cudaStreamCreate(&stream_[g]));
      CUDNN_CHECK(cudnnCreate(&handle_[g]));
      CUDNN_CHECK(cudnnSetStream(handle_[g], stream_[g]));
      workspace[g] = NULL;
    }

    // Set the indexing parameters.
    bias_offset_ = (this->num_output_ / this->group_);

    // Create filter descriptor.
    const int *kernel_shape_data = this->kernel_shape_.cpu_data();
    const int kernel_h = kernel_shape_data[0];
    const int kernel_w = kernel_shape_data[1];
    cudnn::createFilterDesc<Dtype>(&filter_desc_,
                                   this->channels_ / this->group_,
                                   this->num_output_ / this->group_,
                                   kernel_h,
                                   kernel_w);

    // Create tensor descriptor(s) for data and corresponding convolution(s).
    for (int i = 0; i < bottom.size(); i++)
    {
      cudnnTensorDescriptor_t bottom_desc;
      cudnn::createTensor4dDesc<Dtype>(&bottom_desc);
      bottom_descs_.push_back(bottom_desc);
      cudnnTensorDescriptor_t top_desc;
      cudnn::createTensor4dDesc<Dtype>(&top_desc);
      top_descs_.push_back(top_desc);
      cudnnConvolutionDescriptor_t conv_desc;
      cudnn::createConvolutionDesc<Dtype>(&conv_desc);
      conv_descs_.push_back(conv_desc);
    }

    // Tensor descriptor for bias.
    if (this->bias_term_)
    {
      cudnn::createTensor4dDesc<Dtype>(&bias_desc_);
    }

    handles_setup_ = true;
  }

  template <typename Dtype>
  void CuDNNDeconvolutionLayer<Dtype>::Reshape(
      const vector<Blob<Dtype> *> &bottom, const vector<Blob<Dtype> *> &top)
  {
    DeconvolutionLayer<Dtype>::Reshape(bottom, top);
    CHECK_EQ(2, this->num_spatial_axes_)
        << "CuDNNDeconvolutionLayer input must have 2 spatial axes "
        << "(e.g., height and width). "
        << "Use 'engine: CAFFE' for general ND convolution.";
    bottom_offset_ = this->bottom_dim_ / this->group_;
    top_offset_ = this->top_dim_ / this->group_;
    const int height = bottom[0]->shape(this->channel_axis_ + 1);
    const int width = bottom[0]->shape(this->channel_axis_ + 2);
    const int height_out = top[0]->shape(this->channel_axis_ + 1);
    const int width_out = top[0]->shape(this->channel_axis_ + 2);
    const int *pad_data = this->pad_.cpu_data();
    const int pad_h = pad_data[0];
    const int pad_w = pad_data[1];
    const int *stride_data = this->stride_.cpu_data();
    const int stride_h = stride_data[0];
    const int stride_w = stride_data[1];
#if CUDNN_VERSION_MIN(8, 0, 0)
    int RetCnt;
    bool found_conv_algorithm;
    size_t free_memory, total_memory;
    cudnnConvolutionFwdAlgoPerf_t fwd_algo_pref_[4];
    cudnnConvolutionBwdDataAlgoPerf_t bwd_data_algo_pref_[4];

    // get memory sizes
    cudaMemGetInfo(&free_memory, &total_memory);
#else
    // Specify workspace limit for kernels directly until we have a
    // planning strategy and a rewrite of Caffe's GPU memory mangagement
    size_t workspace_limit_bytes = 8 * 1024 * 1024;
#endif
    for (int i = 0; i < bottom.size(); i++)
    {
      cudnn::setTensor4dDesc<Dtype>(&bottom_descs_[i],
                                    this->num_,
                                    this->channels_ / this->group_,
                                    height,
                                    width,
                                    this->channels_ * height * width,
                                    height * width,
                                    width,
                                    1);
      cudnn::setTensor4dDesc<Dtype>(&top_descs_[i],
                                    this->num_,
                                    this->num_output_ / this->group_,
                                    height_out,
                                    width_out,
                                    this->num_output_ * height_out * width_out,
                                    height_out * width_out,
                                    width_out,
                                    1);
      cudnn::setConvolutionDesc<Dtype>(&conv_descs_[i],
                                       top_descs_[i],
                                       filter_desc_,
                                       pad_h,
                                       pad_w,
                                       stride_h,
                                       stride_w);

#if CUDNN_VERSION_MIN(8, 0, 0)
      // choose forward algorithm for filter
      // in forward filter the CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED is not implemented in cuDNN 8
      CUDNN_CHECK(cudnnGetConvolutionForwardAlgorithm_v7(handle_[0],
                                                         top_descs_[i],
                                                         filter_desc_,
                                                         conv_descs_[i],
                                                         bottom_descs_[i],
                                                         4,
                                                         &RetCnt,
                                                         fwd_algo_pref_));

      found_conv_algorithm = false;
      for (int n = 0; n < RetCnt; n++)
      {
        if (fwd_algo_pref_[n].status == CUDNN_STATUS_SUCCESS &&
            fwd_algo_pref_[n].algo != CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED &&
            fwd_algo_pref_[n].memory < free_memory)
        {
          found_conv_algorithm = true;
          fwd_algo_[i] = fwd_algo_pref_[n].algo;
          workspace_fwd_sizes_[i] = fwd_algo_pref_[n].memory;
          break;
        }
      }
      if (!found_conv_algorithm)
        LOG(ERROR) << "cuDNN did not return a suitable algorithm for convolution.";
      else
      {
        // choose backward algorithm for filter
        // for better or worse, just a fixed constant due to the missing
        // cudnnGetConvolutionBackwardFilterAlgorithm in cuDNN version 8.0
        bwd_filter_algo_[i] = CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0;
        // twice the amount of the forward search to be save
        workspace_bwd_filter_sizes_[i] = 2 * workspace_fwd_sizes_[i];
      }

      // choose backward algo for data
      CUDNN_CHECK(cudnnGetConvolutionBackwardDataAlgorithm_v7(handle_[0],
                                                              filter_desc_,
                                                              bottom_descs_[i],
                                                              conv_descs_[i],
                                                              top_descs_[i],
                                                              4,
                                                              &RetCnt,
                                                              bwd_data_algo_pref_));

      found_conv_algorithm = false;
      for (int n = 0; n < RetCnt; n++)
      {
        if (bwd_data_algo_pref_[n].status == CUDNN_STATUS_SUCCESS &&
            bwd_data_algo_pref_[n].algo != CUDNN_CONVOLUTION_BWD_DATA_ALGO_WINOGRAD &&
            bwd_data_algo_pref_[n].algo != CUDNN_CONVOLUTION_BWD_DATA_ALGO_WINOGRAD_NONFUSED &&
            bwd_data_algo_pref_[n].memory < free_memory)
        {
          found_conv_algorithm = true;
          bwd_data_algo_[i] = bwd_data_algo_pref_[n].algo;
          workspace_bwd_data_sizes_[i] = bwd_data_algo_pref_[n].memory;
          break;
        }
      }
      if (!found_conv_algorithm)
        LOG(ERROR) << "cuDNN did not return a suitable algorithm for convolution.";
#else
      // choose forward and backward algorithms + workspace(s)
      CUDNN_CHECK(cudnnGetConvolutionForwardAlgorithm(
          handle_[0],
          top_descs_[i],
          filter_desc_,
          conv_descs_[i],
          bottom_descs_[i],
          CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT,
          workspace_limit_bytes,
          &fwd_algo_[i]));

      // We have found that CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM is
      // buggy. Thus, if this algo was chosen, choose winograd instead. If
      // winograd is not supported or workspace is larger than threshold, choose
      // implicit_gemm instead.
      if (fwd_algo_[i] == CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM)
      {
        size_t winograd_workspace_size;
        cudnnStatus_t status = cudnnGetConvolutionForwardWorkspaceSize(
            handle_[0],
            top_descs_[i],
            filter_desc_,
            conv_descs_[i],
            bottom_descs_[i],
            CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD,
            &winograd_workspace_size);
        if (status != CUDNN_STATUS_SUCCESS ||
            winograd_workspace_size >= workspace_limit_bytes)
        {
          fwd_algo_[i] = CUDNN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM;
        }
        else
        {
          fwd_algo_[i] = CUDNN_CONVOLUTION_FWD_ALGO_WINOGRAD;
        }
      }

      CUDNN_CHECK(cudnnGetConvolutionForwardWorkspaceSize(
          handle_[0],
          top_descs_[i],
          filter_desc_,
          conv_descs_[i],
          bottom_descs_[i],
          fwd_algo_[i],
          &(workspace_fwd_sizes_[i])));

      // choose backward algorithm for filter
      CUDNN_CHECK(cudnnGetConvolutionBackwardFilterAlgorithm(
          handle_[0],
          top_descs_[i],
          bottom_descs_[i],
          conv_descs_[i],
          filter_desc_,
          CUDNN_CONVOLUTION_BWD_FILTER_SPECIFY_WORKSPACE_LIMIT,
          workspace_limit_bytes,
          &bwd_filter_algo_[i]));

      // get workspace for backwards filter algorithm
      CUDNN_CHECK(cudnnGetConvolutionBackwardFilterWorkspaceSize(
          handle_[0],
          top_descs_[i],
          bottom_descs_[i],
          conv_descs_[i],
          filter_desc_,
          bwd_filter_algo_[i],
          &workspace_bwd_filter_sizes_[i]));

      // choose backward algo for data
      CUDNN_CHECK(cudnnGetConvolutionBackwardDataAlgorithm(
          handle_[0],
          filter_desc_,
          bottom_descs_[i],
          conv_descs_[i],
          top_descs_[i],
          CUDNN_CONVOLUTION_BWD_DATA_SPECIFY_WORKSPACE_LIMIT,
          workspace_limit_bytes,
          &bwd_data_algo_[i]));

      // get workspace size
      CUDNN_CHECK(cudnnGetConvolutionBackwardDataWorkspaceSize(
          handle_[0],
          filter_desc_,
          bottom_descs_[i],
          conv_descs_[i],
          top_descs_[i],
          bwd_data_algo_[i],
          &workspace_bwd_data_sizes_[i]));
#endif
    }

    // reduce over all workspace sizes to get a maximum to allocate / reallocate
    size_t total_workspace_fwd = 0;
    size_t total_workspace_bwd_data = 0;
    size_t total_workspace_bwd_filter = 0;

    for (size_t i = 0; i < bottom.size(); i++)
    {
      total_workspace_fwd = std::max(total_workspace_fwd,
                                     workspace_fwd_sizes_[i]);
      total_workspace_bwd_data = std::max(total_workspace_bwd_data,
                                          workspace_bwd_data_sizes_[i]);
      total_workspace_bwd_filter = std::max(total_workspace_bwd_filter,
                                            workspace_bwd_filter_sizes_[i]);
    }
    // get max over all operations
    size_t max_workspace = std::max(total_workspace_fwd,
                                    total_workspace_bwd_data);
    max_workspace = std::max(max_workspace, total_workspace_bwd_filter);
    // ensure all groups have enough workspace
    size_t total_max_workspace = max_workspace *
                                 (this->group_ * CUDNN_STREAMS_PER_GROUP);

    // this is the total amount of storage needed over all groups + streams
    if (total_max_workspace > workspaceSizeInBytes)
    {
      DLOG(INFO) << "Reallocating workspace storage: " << total_max_workspace;
      workspaceSizeInBytes = total_max_workspace;

      // free the existing workspace and allocate a new (larger) one
      cudaFree(this->workspaceData);

      cudaError_t err = cudaMalloc(&(this->workspaceData), workspaceSizeInBytes);
      if (err != cudaSuccess)
      {
        // force zero memory path
        for (int i = 0; i < bottom.size(); i++)
        {
          workspace_fwd_sizes_[i] = 0;
          workspace_bwd_filter_sizes_[i] = 0;
          workspace_bwd_data_sizes_[i] = 0;
          fwd_algo_[i] = CUDNN_CONVOLUTION_FWD_ALGO_FFT_TILING;
          bwd_filter_algo_[i] = CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0;
          bwd_data_algo_[i] = CUDNN_CONVOLUTION_BWD_DATA_ALGO_0;
        }

        // NULL out all workspace pointers
        for (int g = 0; g < (this->group_ * CUDNN_STREAMS_PER_GROUP); g++)
        {
          workspace[g] = NULL;
        }
        // NULL out underlying data
        workspaceData = NULL;
        workspaceSizeInBytes = 0;
      }

      // if we succeed in the allocation, set pointer aliases for workspaces
      for (int g = 0; g < (this->group_ * CUDNN_STREAMS_PER_GROUP); g++)
      {
        workspace[g] = reinterpret_cast<char *>(workspaceData) + g * max_workspace;
      }
    }

    // Tensor descriptor for bias.
    if (this->bias_term_)
    {
      cudnn::setTensor4dDesc<Dtype>(
          &bias_desc_, 1, this->num_output_ / this->group_, 1, 1);
    }
  }

  template <typename Dtype>
  CuDNNDeconvolutionLayer<Dtype>::~CuDNNDeconvolutionLayer()
  {
    // Check that handles have been setup before destroying.
    if (!handles_setup_)
    {
      return;
    }

    for (int i = 0; i < bottom_descs_.size(); i++)
    {
      cudnnDestroyTensorDescriptor(bottom_descs_[i]);
      cudnnDestroyTensorDescriptor(top_descs_[i]);
      cudnnDestroyConvolutionDescriptor(conv_descs_[i]);
    }
    if (this->bias_term_)
    {
      cudnnDestroyTensorDescriptor(bias_desc_);
    }
    cudnnDestroyFilterDescriptor(filter_desc_);

    for (int g = 0; g < this->group_ * CUDNN_STREAMS_PER_GROUP; g++)
    {
      cudaStreamDestroy(stream_[g]);
      cudnnDestroy(handle_[g]);
    }

    cudaFree(workspaceData);
    delete[] workspace;
    delete[] stream_;
    delete[] handle_;
    delete[] fwd_algo_;
    delete[] bwd_filter_algo_;
    delete[] bwd_data_algo_;
    delete[] workspace_fwd_sizes_;
    delete[] workspace_bwd_data_sizes_;
    delete[] workspace_bwd_filter_sizes_;
  }

  INSTANTIATE_CLASS(CuDNNDeconvolutionLayer);

} // namespace caffe
#endif


 由于cuDNN对代码进行了改版,在cudnn.h文件中不再指出cudnn的版本号,而是放在了cudnn_version.h文件中,所以,将cudnn_version.h中对于版本段的代码复制到cudnn.h文件中,代码如下:

locate cudnn_version.h
sudo gedit /usr/local/cuda-11.4/targets/x86_64-linux/include/cudnn_version.h

 

 复制其中的非注释部分:

sudo gedit /usr/local/cuda-11.4/targets/x86_64-linux/include/cudnn.h

粘贴到最开头:

 然后打开caffe包下的cudnn.hpp文件并指定cudnn.h路径:

 之后重新执行编译:

sudo make clean && make all -j16

生成以下静态库和共享库文件:

 测试,时间较慢,耐心等待~

sudo make test -j16
sudo make runtest -j16
sudo make pycaffe -j16

 可能会有报错,但问题不大,我们只是需要那些库文件~

24.安装libfreenect2

git clone https://github.com/OpenKinect/libfreenect2.git
cd libfreenect2 && mkdir build && cd build/
cmake -j16 .. -DENABLE_CXX11=ON 
sudo make -j16

sudo make install

sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/

25.安装vtk8.2.0及PCL1.9.1

https://vtk.org/download/https://vtk.org/download/下载VTK-8.2.0.zip

 解压之后,进入文件夹打开终端:

mkdir build && cd  build && cmake-gui

 

 单击Configure后勾选以下两项后单击Configure和Generate

 

 

sudo make -j16

sudo make install

接下来安装pcl:

git clone -b pcl-1.9.1 https://gitee.com/yubaoliu/pcl.git pcl-1.9.1

之后进入文件夹打开终端输入:

mkdir release && cd release
cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr \ -DBUILD_GPU=ON-DBUILD_apps=ON -DBUILD_examples=ON \ -DCMAKE_INSTALL_PREFIX=/usr ..

sudo make -j16

sudo make install

P.S:

推荐一些linux办公常用的软件(linux版,不包括wine环境下,全部下载deb格式的安装包,系统架构可通过命令uname -a查看):

百度网盘 客户端下载

向日葵远程控制app官方下载 - 贝锐向日葵官网

QQ Linux版-新不止步·乐不设限

下载中心-腾讯会议

WPS Office 2019 for Linux-支持多版本下载_WPS官方网站

搜狗输入法-首页(下载安装包后,官方会跳转至安装教程,严格按照步骤执行)

Documentation for Visual Studio Code(推荐打开Settings Sync,换电脑时设置可以同步)

195197efec704c98ba8f61ecc4c8370a.png

bd3b7b33a2744c5cb67011223648eabf.png

 可以水平和垂直分割的bash终端:

sudo apt-get install terminator

74c734b7ca9e4cc5a68246b4f8a73ee3.png

trash命令:

sudo apt-get install trash-cli

tree命令:

sudo apt-get install tree

5434b41e73244f8f941b795586faaea2.png

c344c03378a74cdca9e9585f3c3c14d8.png

查看系统信息:

sudo apt-get install neofetch

e86107d0003945a98d5335abf87680b4.png

rar文件解压工具:

sudo apt-get install unrar

 解决不能观看MP4文件:

sudo apt-get update
sudo apt-get install libdvdnav4 libdvdread4 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg
sudo apt-get install ubuntu-restricted-extras
sudo dpkg-reconfigure libdvd-pkg

 系统优化:

sudo apt-get update
sudo apt-get install gnome-tweak-tool

火狐浏览器优化:

地址栏输入:

about:config

full-screen-api.warning.timeout 

 设置为0~

browser.search.openintab
browser.urlbar.openintab
browser.tabs.loadBookmarksInTabs

都设置为true~

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

关于Ubuntu18.04安装后的一系列环境配置过程的总结 的相关文章

  • WIN7不能访问共享文件夹

    WIN7不能访问共享文件夹 1 确定同一网段 2 开启被访问电脑的Guest用户 windows启用guest用户一般又3种方式 xff0c 通过图形化界面或cmd命令行 xff1a 1 打开运行输入cmd回车 xff0c 输入 xff1a
  • docker 容器更新镜像发布和保存操作步骤

    1 修改容器 安装软件等修改操作 2 docker commit 提交更新并生成新的image sudo docker commit m 34 cuda 9 0 install 34 a 34 chengde 34 23ecb489cf78
  • 嵌入式linux学习----Makefile基础知识

    一 嵌入式linux学习 Makefile基础知识 1 1 Makefile作用 makefile关系到了整个工程的编译规则 一个工程中的源文件不计数 xff0c 其按类型 功能 模块分别放在若干个目录中 xff0c makefile定义了
  • Expert C Lanuage 学习笔记----1、穿越时空的迷雾(1)

    Expert C Lanuage 学习笔记 1 穿越时空的迷雾 xff08 1 xff09 1 First Mistake 几乎每个C语言编程新手都犯过下面错误 xff1a if i 61 3 正确应该是 if i 61 61 3 这种错误
  • vscode 保存代码自动格式化(vue)

    1 根据项目配置的eslint规则保存代码后 xff0c 自动格式化代码 2 需要安装prettier 和 vetur settings json 34 codestream serverUrl 34 34 https api codest
  • 理解互斥量和信号量

    互斥量 Mutex 互斥量表现互斥现象的数据结构 xff0c 也被当作二元信号灯 一个互斥基本上是一个多任务敏感的二元信号 xff0c 它能用作同步多任务的行为 xff0c 它常用作保护从中断来的临界段代码并且在共享同步使用的资源 Mute
  • 单链表逆序与排序

    xfeff xfeff xfeff xfeff xfeff xfeff include lt stdio h gt include lt stdlib h gt include lt string h gt typedef struct d
  • ubuntu apt-get update 失败解决。

    当运行apt get update后出现如下错误时 xff1a E Some index files failed to download they have been ignored or old ones used instead 可以
  • 深入理解句柄表

    涉及到句柄表的有以下这些概念 xff1a HANDLE TABLE HANDLE TABLE结构体中的TableCode变量 实际上啊 xff0c TableCode是指向句柄表项第一个句柄表项的指针 xff08 NULL句柄表项 xff0
  • LQR控制律设计

    LQR全称为Linear Quadratic Regulator xff0c 即线性二次型调节器 xff08 一 xff09 有限时域最优调节器设计 设线性系统 被控对象的离散化状态方程为 xff1a 初始条件 给定二次型性能指标函数 xf
  • 路径跟踪之LQR控制算法

    xff08 一 xff09 车辆建模 两自由度车辆模型为 xff1a 考虑恒定不变 xff0c 则上述模型可以看作一个输入为 状态变量为的控制系统 xff0c 可以表示为 xff1a 对于参考轨迹 xff0c 可以表示为 xff1a 将 x
  • Arrays.sort简单排序实例

    Arrays sort 方法实例 xff1a 用于对整形数组及字符串数组进行排序 这里写代码片 import java util ArrayList import java util Arrays import java util Coll
  • git rebase 成功之后如何撤销

    git rebase 过程中可以使用git abort continue来进行操作 xff0c 成功之后如何撤销呢 xff1f 首先执行git reflog查看本地记录 可知本次rebase之前的id 为 xff1a 02a3260 HEA
  • STM32---BOOT0和BOOT1

    文章目录 前言一 思维导图二 注意事项1 针对BOOT0和BOOT1的不同接线方式 xff08 高电平 xff0c 低电平 xff0c 不接线 xff09 xff0c 开发板的下载情况分析如下图 xff1a xff08 x 代表不接线 xf
  • Windowsxp主机下用Putty连接VirtualBox中的Debian

    参考网址 1 xff0c debian中需要安装openssh server xff0c 并开启ssh服务 2 xff0c VirtualBox的网络连接方式选择NAT xff08 可以连接外面的网络 xff09 xff0c 默认情况下 x
  • 设备接入天猫精灵教程(一)

    现在网上接入天猫精灵的教程基本都是云对云接入 xff0c 需要搭建服务器 xff0c 写硬件程序 xff0c 费时又复杂 这次结合之前的阿里云教程做一个通过阿里云物联网平台接入天猫精灵的教程 xff0c 免去了服务器开发 xff0c 大大的
  • 测试 使用 perf 进行性能分析时如何获取准确的调用栈

    测试 使用 perf 进行性能分析时如何获取准确的调用栈 ifonly 2020年02月27日 101 次阅读 目录 perf 是 Linux 下重要的性能分析工具 xff0c perf 可以通过采样获取很多性能指标 xff0c 其中最常用
  • Jetson Xavier NX 安装固态硬盘并挂载到/home目录下

    1 查看硬盘所有分区 指令 xff1a sudo fdisk lu xff12 对硬盘进行分区 指令 xff1a sudo fdisk dev nvme0n1 3 格式化分区为ext4 指令 xff1a sudo mkfs t ext4 d
  • 单目相机位姿求解之PNP算法原理剖析与实践

    对于视觉里程计中 xff0c 相机位姿的求解问题极为常见 对于双目相机 xff0c 由于其可以直接计算出深度信息 xff0c 所以在相机位姿求解上十分容易 但如果我们使用的是单目相机 xff0c 如何从二维图像中求解出相机相对三维物体的位姿
  • 计算器1.0

    数据结构让我们相遇 计算器1 0正式上线 xff1a define h span class token macro property span class token directive keyword include span span

随机推荐

  • 常用软件滤波方法及其示例程序

    常用软件滤波方法及其示例程序 作者 未知 来源 发布时间 2005 08 24 浏览次数 lt script language 61 34 Javascript 34 src 61 34 view php articleid 61 10 3
  • I2C协议调试总结

    1 协议总结 开始 xff1a 在SCL为高期间 xff0c SDA由高变低 结束 xff1a 在SCL为高期间 xff0c SDA由低变高 应答 xff1a 时钟脉冲 xff19 期间释放数据线 xff0c SCL为高期间 xff0c S
  • mtk6765上i2c-tools的使用

    1 下载i2c tools 从开源网站http dl lm sensors org i2c tools releases 下载i2c tools 几个版本都可以用 xff0c 可以选择下载i2c tools 4 3 xff12 到官网下载交
  • mt6762/mt6765平台i2c驱动能力修改与波形优化

    mt6762在连接一些外设时 xff0c i2c在低电平会拉不低的情况 xff0c 最低电平在0 4V左右 xff0e 这时需要去掉外设的上拉电阻或调整硬件i2c的驱动电流 xff0e 修改文件路径 xff1a vendor mediate
  • cmake find_package 原理简介以及使用说明

    下面简单介绍Cmake 如何使用find package命令对外部库进行查找 cmake本身不提供任何关于搜索库的便捷方法 xff0c 也不会对库本身的环境变量进行设置 它仅仅是按照优先级顺序在指定的搜索路径进行查找Findxxx cmak
  • MT6762平台NXP NFC代码移植要点

    xff11 找到官网 xff0c 获取源码包 NXP NFC移植源码 https github com NXPNFCProject 固件 https github com NXP nfc NXPNFCC FW tags 2 主要介绍源码移植
  • mt6762添加gpio按键方法与问题调试

    mt6762添加gpio按键方法与问题调试 1 配置dts文件 xff0e 定义gpio87为拍照键 对于keycode 61 212 gpio keys gpio keys compatible 61 34 gpio keys 34 in
  • GD33F303RTC6串口USART0重映射问题

    GD32F303RTC6的串口有多个 xff0c 其中USART0串口可以定义为PA9 PA10 xff0c 也可以映射定义为PB6 PB7 USART0默认是用PA9 PA10 xff0c 如果需要映射到PB6 PB7 则需要gpio p
  • APM32F103CBT6调试接口复用为GPIO配置问题

    APM32F103CBT6调试接口复用为GPIO配置问题 xff1a 可以通过调整复用配置 xff0c 改为GPIO口 xff0c xff08 注意 xff1a 改为上电默认为GPIO口后 xff0c 将无法再用调试功能 xff0c 慎重选
  • APM32F103 USB键盘如何唤醒PC机

    USB2 0全速设备的技术规范 xff0c 所以支持远程唤醒的功能 xff0c 本文简单介绍全速USB模式下 xff0c USB键盘如何休眠PC xff0c 唤醒PC机 描述符配置 APM32F103鼠标设备配置描述符源代码如下 xff0c
  • 搭建机器人电控系统——如何从零开发主控?——编译环境的选择KEIL、IAR、STM32CubeMX、ROS

    搭建机器人电控系统 如何从零开发主控 xff1f 编译环境的选择 主控的从零开发 编译环境的选择 我以我目前接触到的编译环境为例子 xff0c 目前机器人主控的编译环境一般有三种 xff1a KEIL STM32CubeMX IAR LIN
  • 计算机视觉实验三-全景图像拼接

    目录 一 图像映射与全景拼接 1 1 简介 1 2基础流程 1 3计算图像之间的变换结构 1 4图像拼接的几何原理 编辑 1 5变换类型选择 1 6 2D 图像变换原理 1 7 图像映射流程 1 8 图像拼接整体流程 二 全景拼接测试 2
  • 倒立摆系统

    倒立摆系统是典型的多变量 xff0c 非线性 xff0c 自不稳定和强耦合不确定系统 它可以有效反应控制过程中的许多关键问题 xff0c 是测试各种控制理论的理想模型 以倒立摆为控制对象 xff0c 研究者们已对各种控制理论进行了验证 xf
  • FREERTOS使用任务通知和队列进行串口实时通信实例

    1 xff0c 帧间隔小于10ms的批量数据刷新 采用接收中断 43 空闲中断配合任务通知实现定时处理 2 xff0c 批量大数据传输 采用接收中断 43 队列方式实现接收 3 xff0c 固定帧格式慢速数据 xff0c 采用空闲中断 43
  • ROS+openCV图像处理方法及案例

    本文内容环境Ubuntu20 04 首先 xff0c 我们需要安装openCV sudo apt get install ros noetic vision opencv libopencv dev python3 opencv 然后需要安
  • ubuntu c++使用eigen提示"fatal error: Eigen/Dense: No such file or directory"的解决办法

    include lt Eigen Dense gt 记得命名安装了eigen库啊 为啥提示找不到库文件啊 xff1f 初步怀疑环境的配置问题 xff0e 查到到eigen的安装路径为 xff1a usr include eigen3 Eig
  • C++学习之路(一):搭建C++开发环境

    文章目录 前言一 Windows平台下C 43 43 环境搭建1 1 Visual Studio安装1 2 创建C 43 43 项目 二 Linux平台下C 43 43 环境搭建2 1 安装编译工具2 2 cmake脚本编写 结束 前言 在
  • 为什么要使用事件而不是委托变量?

    用委托变量会让客户端Main方法里可以直接调用 用事件则提高了封装性 class Program static void Main string args Pub p 61 new Pub Sub s 61 new Sub p Number
  • FreeRTOS原理,在STM32下完成一个基于FreeRTOS的多任务程序

    一 学习FreeROTS 1 Free 即免费的 xff0c RTOS 全称是 Real Time Operating System xff0c 中文就是实时操作系统 注意 xff0c RTOS 不是指某一个确定的系统 xff0c 而是指一
  • 关于Ubuntu18.04安装后的一系列环境配置过程的总结

    Updating 目录 1 注意 2 更换国内源 3 设置 home文件夹下为英文 4 禁用Nouveau驱动 5 安装Nvidia驱动 xff08 有可能会损坏系统 xff0c 如果损坏可以重装并看看网上的其他教程 xff0c 除了这种安