Ubuntu启动盘
更新软件源
直接打开应用"Software&Updates",选择Source code 的 Download from : Server for China
或者直接替代文件 etc/apt/sources.list
:
deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
apt-get update
输入法改为智能中文输入:
先进入设置里面的Region&Language, 在Manage Installed language里安装中文,然后把系统的语言改为中文,重启后就可以在Region&Language里的Input source里面添加智能中文输入。如果要将系统语言改为英文,就把Region&Language里的language 把English拉到最上面,再重启。
安装库
CMake
- 安装
sudo apt install cmake
cmake -version # 查看版本
- 使用方法
cd PROJECT_PATH
mkdir build
cd build
cmake
g++
- 安装
sudo apt-get install g++
g++ --version # 版本
- 编译cpp文件
g++ Hello.cpp
- 执行
./ ***.out
Eigen
- 安装
sudo apt-get install libeigen3-dev
- 使用
不必用target_link_libraries, 因为它没有库文件,只需在CMakeLists中引入其头文件即可
# 添加Eigen头文件,地址不一定都是这个
include_directories("/usr/include/eigen3")
# 或者用find package 来搜索库
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
- 测试是否已经安装有Eigen
sudo updatedb
locate eigen3
OpenGL
- 安装
# 编译器与基本的函式库
sudo apt-get install build-essential
# OpenGL Library
sudo apt-get install libgl1-mesa-dev
# OpenGL Utilities,一组建构于 OpenGL Library 之上的工具组,提供许多很方便的函式,使 OpenGL 更强大且更容易使用
sudo apt-get install libglu1-mesa-dev
# OpenGL Utility Toolkit, 立在 OpenGL Utilities 上面的工具箱,除了强化了 OpenGL Utilities 的不足之外,也增加了 OpenGL 对于视窗介面支援
sudo apt-get install freeglut3-dev
- 测试
#include <GL/glut.h>
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(-5, 5, -5, 5, 5, 15);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
return;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0, 0);
glutWireTeapot(3);
glFlush();
return;
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(300, 300);
glutCreateWindow("OpenGL 3D View");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
- 编译执行
gcc -o test test.c -lGL -lGLU -lglut
./test
Pangolin
- 安装依赖
sudo apt-get install libglew-dev
sudo apt-get install cmake
# 建议的依赖
sudo apt-get install libpython3.8-dev
- 下载Pangolin
git clone https://github.com/stevenlovegrove/Pangolin.git
- 编译安装Pangolin
cd [path-to-pangolin(Pangolin路径)]//打开解压后的Pangolin文件夹
mkdir build
cd build
cmake ..
make(或者用cmake --build .)
sudo make install (.h默认安装到了/usr/local/include)
- 使用
# CMakeLists中添加:
find_package(Pangolin REQUIRED)
tinclude_directories(${Pangolin_INCLUDE_DIRS})
target_link_libraries(xxxxxx ${Pangolin_LIBRARIES})
OpenCV
- 安装依赖
GCC 4.4.x or later
CMake 2.8.7 or higher
Git
GTK+2.x or higher, including headers: libgtk2.0-dev
pkg-config
Python 2.6 or later and Numpy 1.5 or later with developer packages: python-dev, python-numpy
ffmpeg or libav development packages: libavcodec-dev libavformat-dev libswscale-devlibvtk5-dev libjpeg-dev libtbb2 libtbb-dev libjasper-dev libopenexr-dev libtiff-dev
- 下载
OpenCV3.4.1 下载地址: https://github.com/opencv/opencv/archive/3.4.1.zip
- 编译安装
cd OpenCV解压后所在的路径
mkdir build
cd build
cmake ..
make -j4
sudo make install
- 配置环境变量
sudo vim /etc/ld.so.conf.d/opencv.conf
# 在文件中添加‘/usr/local/lib’
sudo ldconfig
sudo vim /etc/bash.bashrc
# 在文件尾添加:‘PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH’
- 查看opencv是否安装成功
pkg-config --cflags opencv //头文件路径
pkg-config --libs opencv //安装库路径
- CMakeLists
project(imageBasics)
find_package( OpenCV REQUIRED )
add_executable(imageBasics imageBasics.cpp)
# 链接OpenCV库
target_link_libraries(imageBasics ${OpenCV_LIBS})
- 使用例子
#include <iostream>
#include <chrono>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
int main(int argc, char **argv) {
// 读取argv[1]指定的图像
cv::Mat image;
image = cv::imread(argv[1]); //cv::imread函数读取指定路径下的图像
// 判断图像文件是否正确读取
if (image.data == nullptr) { //数据不存在,可能是文件不存在
cerr << "文件" << argv[1] << "不存在." << endl;
return 0;
}
// 文件顺利读取, 首先输出一些基本信息
cout << "图像宽为" << image.cols << ",高为" << image.rows << ",通道数为" << image.channels() << endl;
cv::imshow("image", image); // 用cv::imshow显示图像
cv::waitKey(0); // 暂停程序,等待一个按键输入
// 判断image的类型
if (image.type() != CV_8UC1 && image.type() != CV_8UC3) {
// 图像类型不符合要求
cout << "请输入一张彩色图或灰度图." << endl;
return 0;
}
// 遍历图像, 请注意以下遍历方式亦可使用于随机像素访问
// 使用 std::chrono 来给算法计时
chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
for (size_t y = 0; y < image.rows; y++) {
// 用cv::Mat::ptr获得图像的行指针
unsigned char *row_ptr = image.ptr<unsigned char>(y); // row_ptr是第y行的头指针
for (size_t x = 0; x < image.cols; x++) {
// 访问位于 x,y 处的像素
unsigned char *data_ptr = &row_ptr[x * image.channels()]; // data_ptr 指向待访问的像素数据
// 输出该像素的每个通道,如果是灰度图就只有一个通道
for (int c = 0; c != image.channels(); c++) {
unsigned char data = data_ptr[c]; // data为I(x,y)第c个通道的值
}
}
}
chrono::steady_clock::time_point t2 = chrono::steady_clock::now();
chrono::duration<double> time_used = chrono::duration_cast < chrono::duration < double >> (t2 - t1);
cout << "遍历图像用时:" << time_used.count() << " 秒。" << endl;
// 关于 cv::Mat 的拷贝
// 直接赋值并不会拷贝数据
cv::Mat image_another = image;
// 修改 image_another 会导致 image 发生变化
image_another(cv::Rect(0, 0, 100, 100)).setTo(0); // 将左上角100*100的块置零
cv::imshow("image", image);
cv::waitKey(0);
// 使用clone函数来拷贝数据
cv::Mat image_clone = image.clone();
image_clone(cv::Rect(0, 0, 100, 100)).setTo(255);
cv::imshow("image", image);
cv::imshow("image_clone", image_clone);
cv::waitKey(0);
// 对于图像还有很多基本的操作,如剪切,旋转,缩放等,限于篇幅就不一一介绍了,请参看OpenCV官方文档查询每个函数的调用方法.
cv::destroyAllWindows();
return 0;
}
DBow3
- 下载
https://github.com/rmsalinas/DBow3.git
- cmake编译安装
mkdir build
cd build
cmake ..
make
sudo make install
- 可能报错
make[2]: *** 没有规则可制作目标“/usr/local/lib/libDBoW3.a”,由“feature_training” 需求。 停止。
make[1]: *** [CMakeFiles/Makefile2:76:CMakeFiles/feature_training.dir/all] 错误 2
make: *** [Makefile:84:all] 错误 2
解决方法:将CMakeList.txt中的libDBow3.so改为libDBow3.a即可
李代数库Sophus
- 下载
git clone https://github.com/strasdat/Sophus.git
- cmake编译安装
cd Sophus/
mkdir build
cd build
cmake ..
make
sudo make install
- 注意事项
在这里强调!不要回滚git checkout a621ff,否则会装成老版本的非模板sophus(网上大多教程都有回滚)千万不要回滚!!!!!且强调sudo make install一定要有!
因为sophus的使用必须依赖eigen库,因此先下载eigen,但是如果你有3.3以下的版本的eigen,那么请先卸载!
Ceres
- 安装依赖库
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3 libgflags-dev libgoogle-glog-dev libgtest-dev
- 下载
https://github.com/ceres-solver/ceres-solver
- 编译安装
mkdir build
cd build
cmake ..
make
sudo make install
g2o
- 安装依赖库
sudo apt-get install qt5-qmake qt5-default libqglviewer-dev-qt5 libsuitesparse-dev libcxsparse3 libcholmod3
- 下载
https://github.com/RainerKuemmerle/g2o
- 编译安装
mkdir build
cd build
cmake ..
make
sudo make install
安装显卡驱动
- 查看显卡型号及推荐驱动版本
ubuntu-drivers devices
输出
model : GP106M [GeForce GTX 1060 Mobile] # 显卡型号
driver : nvidia-driver-465 - distro non-free recommended # 推荐驱动
打开应用Software&Updates,点击Additional Drivers, 从列表里面选择推荐的驱动,然后Applying changes。
安装完毕,重启,输入命令如下命令,看到GPU显存等信息则说明驱动安装成功
nvidia-smi
CUDA
CUDA能安装的最高版本受到显卡驱动的限制,输入nvidia-smi,显示的信息中有 CUDA Version: 11.3,这是说CUDA最高只能到11.3
- 下载
https://developer.nvidia.com/cuda-toolkit-archive
- 安装
安装系统和驱动版本选择CUDA版本,选择下载runfile(local)类型的文件:
sudo sh cuda_11.1.1_455.32.00_linux.run
安装选项中选择不安装驱动,只选择安装CUDA Toolkit
- 设置环境变量:
vim ~/.bashrc
添加
export CUDA_HOME=/usr/local/cuda-11.1
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-11.1/bin:$PATH
查看版本
nvcc -V
cuDNN
-
下载
下载对应版本的cuDNN(需要注册)
-
解压 cudnn
tar -zxvf cudnn-10.1-linux-x64-v7.6.5.32.tgz
- 安装
复制文件到CUDA Toolkit安装目录下
sudo cp /home/lyq/Library/cudnn-10.2-linux-x64-v8.0.3.33/cuda/include/cudnn*.h /usr/local/cuda-10.2/include/
sudo cp -P /home/lyq/Library/cudnn-10.2-linux-x64-v8.0.3.33/cuda/lib64/libcudnn* /usr/local/cuda-10.2/lib64/
sudo chmod a+r /usr/local/cuda-10.2/include/cudnn*.h /usr/local/cuda-10.2/lib64/libcudnn*
- 查看cudnn版本
cat /usr/local/cuda-10.2/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
Anaconda
- 下载
https://www.anaconda.com/products/individual
- 安装
进入下载文件.sh所在的目录
bash Anaconda3-2021.05-Linux-x86_64.sh
根据提示输入命令即可
注意:提示信息“Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]”,输入no
若报错“conda: command not found”
source ~/.bashrc
Pytorch(GPU版本)
- 查看cuda版本
nvcc -V
- 安装
命令安装 官网
# CUDA 10.2
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cpuonly -c pytorch
如果报错:
用conda,出现了“Solving environment: failed with initial frozen solve. Retrying with flexible solve.”选择更新conda:
conda update
本地安装
根据python版本、cuda版本选择下载, pytorch\torchvision\torchaudio\cudatoolkit 的版本要对应。
- 其它常用库
numpy==1.16.0
Keras==2.2.5
opencv-python==4.3.0.36
opencv-contrib-python==4.3.0.36
matplotlib==3.1.2
imgaug==0.4.0
h5py==2.10.0
- conda源改为清华源
a. 指令添加
# 添加仓库
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
# 第三方源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
b. 直接添加到配置文件
vim ~/.condarc
将里面的channels的内容替换
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
show_channel_urls: True
.condarc以点开头,一般表示 conda 应用程序的配置文件,在用户的家目录(windows:C:\\users\\username\\,linux:/home/username/)。
但对于.condarc配置文件,是一种可选的(optional)运行期配置文件,其默认情况下是不存在的,
但当用户第一次运行 conda config命令时,将会在用户的家目录创建该文件。
加到配置文件
vim ~/.condarc
将里面的channels的内容替换
channels:
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
show_channel_urls: True
.condarc以点开头,一般表示 conda 应用程序的配置文件,在用户的家目录(windows:C:\\users\\username\\,linux:/home/username/)。
但对于.condarc配置文件,是一种可选的(optional)运行期配置文件,其默认情况下是不存在的,
但当用户第一次运行 conda config命令时,将会在用户的家目录创建该文件。