LYNX

Links

Tags

Categories

数据通信

1 数据通信,数据网络和因特网

  • T-1连接:1.544Mbps
  • T-3连接:44.736Mbps

3 数据传输

3.1 概念和术语

3.1.1 传输术语

  • 单工
  • 半双工
  • 全双工

3.1.2 频率,频谱和带宽

  • 数据率和带宽之间的关系

3.2 模拟和数字数据传输

3.2.1 模拟数据和数字数据

3.2.2 模拟信号和数字信号

  • 调制解调器
  • 解编码器
  • 数字传送器

3.2.3 模拟传输和数字传输

3.3 传输损伤

3.3.1 衰减

  • 衰减失真:频率越高,衰减越严重,并将导致失真

3.3.2 时延失真

3.3.3 噪声

假设噪声与频率的大小无关,在$B$Hz带宽内的热噪声为$N = kTB$

$k=$玻尔兹曼常量$=1.38 \times 10^{-23} J/K$

或用分贝-瓦表示$N=10 \lg k + 10 \lg T + 10 \lg B = -228.6dBW + 10 \lg T + 10 \lg B$

3.4 信道容量

  • 数据率:数据能够通信的速率,用比特每秒bps表示
  • 带宽:在发送器和传输媒体的特性限制下的带宽,用Hz或每秒的周数表示
  • 噪声
  • 误码率:即差错发生率

3.4.1 奈奎斯特带宽

$B$:信道带宽,为避免串扰,极限码元传输速率为$2B$Baud,$B$单位Hz,Baud为每秒钟传送码元的数目

奈奎斯特公式:$C = 2B \log_2 M$,$M$是离散信号的个数或电平的个数

3.4.2 香农容量公式

信噪比(SNR或S/N):$SNR_{dB} = 10 \lg \dfrac{\text{信号功率}}{\text{噪声功率}}$

信道的最大容量$C = B \log_2(1 + SNR)$,无误码容量

3.4.3 表达式$E_b/N_0$

每比特信号的能量与每赫兹噪声功率密度之比

$$ \dfrac{E_b}{N_0} = \dfrac{S / R}{N_0} = \dfrac{S}{kTR} $$

$S$是信号功率,$R$数据率

4 传输媒体

决定数据率和传输距离的许多设计因素都与传输媒体及信号有关

  • 带宽
  • 传输损伤
  • 干扰
  • 接收器的数量

4.1 导向传输媒体

4.1.1 双绞线

4.1.2 同轴电缆

4.1.3 光纤

4.2 无线传输

4.2.1 天线

  • 各向同性天线
  • 抛物面反射天线
  • 天线增益

4.2.2 地面微波

4.2.3 卫星微波

4.2.4 广播无线电

4.3 无线传播

4.3.1 地波传播

4.3.2 天波传播

4.3.3 视距传播

  • 折射

  • 光学视距和无线电视距

    • 在没有中间障碍物的情况下,光学视距$d = 3.57 \sqrt{h},h$是天线和地平线之间的距离,以km为单位
    • 到地平线的有效视距或无线电视距$d = 3.57 \sqrt{Kh},K$是折射引起的调整系数,经验值$K = 4/3a$
    • 因此,视距传播的两个天线之间的最大距离为$3.57(\sqrt{Kh_1} + \sqrt{Kh_2})$

4.4 视距传输

4.4.1 自由空间损耗

表示为发射率$P_t$与天线接收到的功率$P_r$的比值,$\dfrac{P_t}{P_r} = \dfrac{(4\pi d)^2}{\lambda^2} = \dfrac{(4\pi fd)^2}{c^2}$,其中

  • $P_t$:发送天线的信号功率
  • $P-r$:接收天线的信号功率
  • $\lambda$:载波波长
    可以被改写为$L_{dB} = 10\lg(\dfrac{4\pi d}{\lambda^2})^2$

4.4.2 大气吸收

4.4.3 多径

4.4.4 折射

5 信号编码技术

  • 模拟信号传输的基础是一种连续且频率恒定的信号,成为载波信号
  • 基带信号

5.1 数字数据,数字信号

术语 单位 定义
数据元素 比特(bit) 单个的二进制1或0
数据率 比特每秒(bps) 数据元素传输的速率
信号元素 数字:一个固定振幅的电压脉冲;模拟:一个具有固定频率,相位和振幅的脉冲 在一个信号传输编码中占据最短时间间隔的那部分信号
信号传输速率或调制速率 信号元素每秒(波特) 信号元素传输的速率

在其他条件保持不变的情况下:

  • 数据率增加,则比特差错率(BER,也成为误码率)增加
  • SNR增加,则差错率减小
  • 增加带宽可使数据率增加

数字信号编码格式的定义

  • 不归零电平(NRZ-L)
  • 不归零1制(NRZI)
  • 双极性AMI
  • 伪三进制码
  • 曼彻斯特编码
  • 差分曼彻斯特编码
  • 8零替换(B8ZS)
  • 双极性3零码(HDB3)

5.1.1 不归零码(NRZ)

5.1.2 多电平二进制

5.1.3 双相位

5.1.4 调制率

$$ D = \dfrac{R}{L} = \dfrac{R}{\log_2M} $$
其中

  • $D$:调制率,波特
  • $R$:数据率,bps
  • $M$:不通信号元素个数,$2^L$
  • $L$:每个信号元素中的比特数目

5.1.5 扰码技术

5.2 数字数据,模拟信号

5.2.1 振幅键控

5.2.2 频移键控

5.2.3 相移键控

5.2.4 性能

5.2.5 正交调幅

5.3 模拟数据,数字信号

5.3.1 脉码调制

5.3.2 增量调制

5.3.3 性能

5.4 模拟数据,模拟信号

5.4.1 调幅

5.4.2 角度调制

6 数字数据通信技术

6.1 异步和同步传输

6.1.1 异步传输

6.1.2 同步传输

6.2 差错类型

6.3 差错检测

6.3.1 奇偶校验

6.3.2 循环冗余校验

6.4 差错纠正

6.4.1 块码原理

6.5 线路配置

6.5.1 拓扑结构

6.5.2 全双工和半双工

7 数据链路控制

7.1 流量控制

7.1.1 停止等待流量控制

  • 链路的比特长度$B = R \times \dfrac{d}{V}$
    • $B$:以比特为单位的链路长度.即当比特流完全占满整个链路时,链路上的比特数量
    • $R$:链路的数据率,bps
    • $d$,链路的长度,m
    • $V$传播速率,m/s
  • 传输时间取归一化值1,并且传播时延用变量a表示,$a = \dfrac{B}{L} = \dfrac{d/V}{L/R}$

7.1.2 滑动窗口流量控制

  • 捎带
  • 数据帧
  • 确认帧

7.2 差错控制

7.2.1 停止等待ARQ

7.2.2 返回N ARQ

7.2.3 选择拒绝ARQ

7.3 高级数据链路控制(HDLC)

7.3.1 基本特点

7.3.2 帧结构

7.3.3 运行方式

8 复用

8.1 频分复用

8.1.1 特点

8.1.2 模拟载波系统

8.1.3 波分复用

8.2 同步时分复用

8.2.1 特点

8.2.2 TDM链路控制

8.2.3 数字载波系统

8.2.4 SONET/SDH

8.3 统计时分复用

8.3.1 特点

8.3.2 性能

8.3.3 电缆调制解调器

8.4 非对称数字用户线路

8.4.1 ADSL设计

8.4.2 离散多音调

8.4.3 宽带访问配置

8.5 xDSL

oj

树的遍历

morris算法(中序遍历)

空间复杂度$O(1)$

void print_out(node *cur);// 输出节点

node *find_prev(node *cur);// 寻找前驱节点

void morris(node *root) {
node *cur = root;
while (cur != NULL) {// 没有遍历完
if (cur->left == NULL) {// 1: cur没有左子节点
print_out(cur);
cur = cur->right;
} else {
node *prev = find_prev(cur);
if (prev->right == NULL) {// 2.1: prev没有右子节点
prev->right = cur;// 修改树结构
cur = cur->left
} else if (prev->right == cur) {// 2.2: prev的右子节点为cur
prev->right = NULL;// 恢复树结构
print_out(cur);
cur = cur->right;
} else {
assert(0);
}
}
}
}

图的遍历

DFS

void dfs(node u) {
u.visit = 1;
for (int i = 0; i < u.adj.size(); i ++) {
node v = u.adj[i];
if (v.visit == 0) {
dfs(v);
}
}
}

BFS

void bfs() {
q.push(s);
while (q.empty() == 0) {
node u = q.top();
q.pop();
for (int i = 0; i < u.adj.size(); i ++) {
node v = u.adj[i];
if (v.visit == 0) {
v.depth = u.depth + 1;
q.push(v);
}
}
}
}

连通度

tarjan算法

时间复杂度$O(V+E)$

void tarjan(int x) {
s.push(x);
depth ++;
dfn[x] = depth;// dfs标记
low[x] = depth;// tarjan标记
in_stack[x] = 1;// 是否入栈
int u, v;
for (int i = 0; i < near[x].size(); i ++) {
int v = near[x][i].v;
if (dfn[v] == 0) {// 未被标记过
tarjan(v);
low[x] = my_min(low[x], low[v]);
} else if (in_stack[v] == 1) {// 已经入栈
low[x] = my_min(low[x], dfn[v]);// my_min(low[x], low[v])l
}
}

if (dfn[x] == low[x]) {// 强连通分量
block ++;// 连通块数目
while (s.empty() == 0) {
v = s.top();
in_stack[v] = 0;
s.pop();
if (v == x) break;
}
}
}

网络流

EK算法

时间复杂度$O(VE^2)$

dinic算法

时间复杂度$O(V^2E)$

struct path {
public:
int u;// 起点
int v;// 终点
int c;// 容量
int f;// 流量
int back;// 反向边编号

path() {
f = 0;
}
};
int T, n, m;
int path_num;
int s, t;
int level[MAXN];// 分层
vector<int> near[MAXN];// 邻接表
path paths[MAXM];// 所有edge

void add_path(int u, int v, int c) {
// 正向边
paths[path_num].u = u;
paths[path_num].v = v;
paths[path_num].c = c;
paths[path_num].f = 0;
paths[path_num].back = path_num + 1;
near[u].push_back(path_num);
path_num ++;
// 反向边
paths[path_num].u = v;
paths[path_num].v = u;
paths[path_num].c = 0;
paths[path_num].f = 0;
paths[path_num].back = path_num - 1;
near[v].push_back(path_num);
path_num ++;
}

int dfs(int x, int flow) {
if (x == t) return flow;
int total_flow = 0;
for (int i = 0; i < near[x].size(); i ++) {
int forward = near[x][i];
int v = paths[forward].v;
int w = paths[forward].c - paths[forward].f;
if (w > 0 && level[v] == level[x] + 1) {
int extend = dfs(v, my_min(w, flow - total_flow));
if (extend > 0) {
int backward = paths[forward].back;
paths[forward].f += extend;
paths[backward].f -= extend;
total_flow += extend;
}
}
}
return total_flow;
}

int bfs() {
queue<int> que;
memset(level, 0, sizeof(level));
que.push(s);
level[s] = 1;
while (que.empty() == 0) {
int u = que.front();
que.pop();
for (int i = 0; i < near[u].size(); i ++) {
int forward = near[u][i];
int v = paths[forward].v;
int w = paths[forward].c - paths[forward].f;
if (w > 0 && level[v] == 0) {
level[v] = level[u] + 1;
que.push(v);
}
}
}
return level[t];
}

int dinic() {
int ans = 0;
while (1) {
if (bfs() == 0) break;// 没有增广路
ans += dfs(s, INF);
}
return ans;
}

匹配算法

最大匹配:匈牙利算法

时间复杂度$O(VE)$

vector<int> x_near[];// x的邻接表
int y_match[];// y的配对记录
int y_visit[];// 用于dfs的标记

void match() {
for (int i = 0; i < n; i ++) {// n为x个数
memset(y_visit, 0, sizeof(y_visit));
if (dfs(i)) {
ans ++;
}
}
}

int dfs(int x) {
for (int i = 0; i < x_near[x].size(); i ++) {
int index = x_near[x][i];
if (y_visit[index] == 0) {// 没有被dfs过的y
y_visit[index] = 1;
if (y_match[index] == -1 || dfs(y_match[index])) {
// 如果 (没有配对 || 已经配对的能够增广)
y_match[index] = x;// 为x找到新的配对
return 1;
}
}
}
return 0;
}

最优匹配:KM算法

int n;// 总数
int x_ex[MAXN];// x的期望
int y_ex[MAXN];// y的期望
int x_visit[MAXN];// 每轮配对时x的标记
int y_visit[MAXN];// 每轮配对时y的标记
int y_match[MAXN];// 与y配对的x
int y_slack[MAXN];// 每轮遍历x改变的期望
int near[MAXN][MAXN];// 邻接矩阵

int KM();
int dfs(int x);

int dfs(int x) {
assert(x > 0);
x_visit[x] = 1;
for (int i = 1; i <= n; i ++) {
if (y_visit[i] == 0) {
int gap = x_ex[x] + y_ex[i] - near[x][i];// 两者的期望和与实际值之差
if (gap == 0) {
// 符合要求
y_visit[i] = 1;// TODO
if (y_match[i] == 0 || dfs(y_match[i])) {
// 没有匹配 || 可以增广
y_match[i] = x;
return 1;
}
} else {
y_slack[i] = my_min(y_slack[i], gap);
}
}
}
return 0;
}

int KM() {
memset(x_ex, 0, sizeof(x_ex));
memset(y_ex, 0, sizeof(y_ex));// 无期望
memset(y_match, 0, sizeof(y_match));// 无配对

// 最大化x期望
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
x_ex[i] = my_max(x_ex[i], near[i][j]);
}
}

// 为每个x进行匹配
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {// 初始期望为无穷
y_slack[j] = INF;
}

while (1) {// 直到找到配对为止
memset(x_visit, 0, sizeof(x_visit));
memset(y_visit, 0, sizeof(y_visit));

int extend = dfs(i);
if (extend == 1) break;

// 找出最小的slack
int min_slack = INF;
for (int j = 1; j <= n; j ++) {
if (y_visit[j] == 0) {// 不符合要求的y(交错树之外)
min_slack = my_min(min_slack, y_slack[j]);
}
}

// 调整x, y的期望
for (int j = 1; j <= n; j ++) {
if (x_visit[j] == 1) {
x_ex[j] -= min_slack;
}
if (y_visit[j] == 1) {
y_ex[j] += min_slack;
}
}
}
}

// 计算和
int ans = 0;
for (int i = 1; i <= n; i ++) {
ans += near[y_match[i]][i];
}

return ans;
}

字符串匹配

KMP算法

void kmp() {// a[1], b[1]为起始项
// 计算前缀表
p_len = 0;
for (int i = 2; i <= m; i ++) {// 注意初始赋值
while (p_len && b[p_len + 1] != b[i]) {
p_len = kmp[p_len];
}
if (b[p_len + 1] == b[i]) {
p_len ++;
kmp[i] = p_len;
}
}
// 进行匹配
p_len = 0;
for (int i = 1; i <= n; i ++) {// 注意初始赋值
while (p_len && b[p_len + 1] != a[i]) {
p_len = kmp[p_len];
}
if (b[p_len + 1] == a[i]) {
p_len ++;
if (p_len == m) {
printf("%d\n", i - p_len + 1);
break;
}
}
}
}
vlfeat笔记

cpp(Linux)

官方C API

参考:https://www.vlfeat.org/gcc.html

/etc/ld.so.conf.d/下任意一个文件(如opencv.conf)添加so库的路径,然后sudo ldconfig

extern "C" {
#include
}

int main (int argc, const char * argv[]) {
VL_PRINT ("Hello world!") ;
return 0;
}
g++ vl_test.cpp -o test -I$(VL) -L$(VL)/bin/glnxa64 -lvl

编译

单独使用sift模块

使用源文件

  1. 保留vl目录下所有文件

  2. 保留src下的sift.cgeneric-driver.h

  3. 注释host.h部分代码(约665行)

    /* Linux: limit glibc to old versions for compatibility */
    // #if defined(VL_COMPILER_GNUC) & defined(VL_OS_LINUX) & ! defined(__DOXYGEN__)
    // __asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
    // #endif
  4. vl下创建一个头文件fuck.h

    #define FUCK_H

    #define VL_DISABLE_AVX
    #define VL_DISABLE_SSE2
  5. vl下的host.h,imopv_sse2.c头部添加

    #if ! defined(FUCK_H)
    #include "fuck.h"
    #endif
  6. CMakeLists.txt编写

    # vlfeat
    set(vlfeat_dir /home/lynx/fuck_mount/vlfeat/vlfeat_android)
    include_directories(${vlfeat_dir})
    aux_source_directory(/home/lynx/fuck_mount/vlfeat/vlfeat_android/src vl_src)
    aux_source_directory(/home/lynx/fuck_mount/vlfeat/vlfeat_android/vl vl_head)
    add_library(
    vlfeat_lib

    SHARED

    ${vl_src}
    ${vl_head}
    )

    # 添加目标文件/目标库
    add_executable(
    entry

    source.cpp )

    # 连接库文件
    target_link_libraries(
    entry

    ${OpenCV_LIBS}
    # ${vlfeat_lib}
    vlfeat_lib
    )

常见错误

  1. 找不到libiomp5.so
apt-file search libiomp5.so
sudo apt install libomp-7-dev
ubuntu使用

零散笔记

摄像头(webcam)

sudo apt install v4l-util cheese
sudo cheese

修改摄像头权限

ls -ltrh /dev/video*
sudo chmod 777 /dev/video0
cheese

重启驱动

  • 重启触摸板驱动
sudo modprobe -r psmouse
sudo modprobe psmouse

sudo rmmode psmouse
sudo modprobe psmouse

xinput list
xinput --disable {编号}
xinput --enable {编号}

在文件夹中执行脚本

文件$\to$首选项$\to$行为$\to$可执行文本文件

快捷键

不要出现fn+super的组合

截屏

  • 复制截图到剪切板:ctrl+print
  • 复制窗口截图到剪切板:ctrl+alt+print
  • 复制选区截图到剪切板:shift+ctrl+print
  • 保存截图到图片:print
  • 保存窗口截图到图片:alt+print
  • 保存选区截图到图片:shift+print
  • 录屏:shift+ctrl+alt+r

禁用快捷键

backspace

WLAN

wifi连接

参考:askubuntu

  • 查看网卡名:iwconfig

  • 扫描:nmcli dev wifi

  • 连接:nmcli dev wifi connect WLAN_NAME password PASSWORD

  • 忘记:nmcli c delete WLAN_NAME

  • 关闭热点:nmcli dev disconnect wlp2s0

  • 关闭wlan:nmcli radio wifi off

  • 开启wlan:nmcli radio wifi on

热点

nm-connection-editor
  1. +->Wifi->Mode:Hotspot

  2. 开启热点

    • 设置->(右上角)Connect to Hidden Network
    • 设置$\to$wifi$\to$打开wifi热点

共享wifi

误删PATH救急

  • Linux通用?
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH

不要忘记加:PATH

安装字体

sudo mkdir /usr/share/fonts/{name}
sudo cp {font}.ttf /usr/share/fonts/{name}
cd /usr/share/fonts/{name}
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv

文件编码


功能性软件

默认软件管理

  • exo-utils
    • 使用
      exo-preferred-applications

文件管理器

由于ubuntu自带的文件管理器太睿智,推荐以下文件管理器

  • pcmanfm
  • nemo
  • thunar
  • dolphin

修改默认文件管理器

TODO:/etc/gnome/defaults.list(直接修改好像没用)

# what's the current default file manager?
xdg-mime query default inode/directory

# set nautilus as a default file manager
xdg-mime default nautilus.desktop inode/directory # application/x-gnome-saved-search

软件对应/usr/share/applications下的desktop

matlab

离线激活

  1. 输入许可证路径license_standalone.lic

  2. 修改matlab所在目录的读写权限以及用户组

  3. 讲破解文件的lmgrimpl文件覆盖原matlab文件

许可证失效(无法打开matlab)

删除matlab/licenses下的文件

mathematica

报错

CRITICAL FAILURE: PrintIntroduction() Error
$ProductTitle not defined.

路径不能有空格

一个解决包依赖问题的软件

sudo apt install aptitude
  • (示例)卸载libreoffice
sudo aptitude purge libreoffice6.0

字体编辑

sudo add-apt-repository ppa:fontforge/fontforge
sudo apt-get update
sudo apt-get install fontforge

修改字体名称

  1. 打开字体文件
  2. 基础->字体信息
  3. 文件->生成字体->(可选)选择TrueType(ttf)

图像编辑

sudo apt install gimp
sudo apt install krita
sudo apt install krita-l10n

图像转换

sudo apt install sam2p
sam2p shit.png shit.gif

gif录屏

  • byzanz
sudo apt install byzanz 
byzanz-record --duration=50 --delay=3 --x=1030 --y=100 --height=500 demo1.gif

视频播放

  • mpv

快捷键:https://github.com/mpv-player/mpv/blob/master/etc/input.conf

视频转换

  • ffmpeg

gif转视频

ffmpeg -f gif -i draw1.gif draw1.mpg

视频合并

ffmpeg -i "concat:draw1.mpg|draw2.mpg|pen.mpg|edit.mpg|clip.mpg" demo.mp4
  • 注意添加concat
  • 只有特定格式的视频才能合并

桌面便签(Indicator Stickynotes)

sudo add-apt-repository ppa:umang/indicator-stickynotes
sudo apt-get update
sudo apt-get install indicator-stickynotes

下载器(TODO)

  • wget:单线程
  • curl:单线程
  • axel:多线程
  • aria2:可以设置线程
  • mwget:多线程版wget
  • Prozilla:多线程,cmd,gui
  • Downloader for X:多线程,gui
  • MyGet:多线程
  • Linuxdown:多线程,cmd
  • Transmission:磁力,gui(不会用)
  • Uget:cURL+aria2

网络监测

  • nethogs

基本没用

屏幕管理

  • arandr
sudo apt install arandr

镜像源

/etc/apt/sources.list

  • ubuntu 19.04
deb http://cn.archive.ubuntu.com/ubuntu/ disco main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ disco-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ disco universe
deb http://cn.archive.ubuntu.com/ubuntu/ disco-updates universe
deb http://cn.archive.ubuntu.com/ubuntu/ disco multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ disco-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ disco-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu disco-security main restricted
deb http://security.ubuntu.com/ubuntu disco-security universe
deb http://security.ubuntu.com/ubuntu disco-security multiverse
  • 中科大
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
  • 清华
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
  • 网易
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
  • 阿里
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

apt

系统监视器安装

sudo apt install gnome-system-monitor
cmake笔记

变量

参数

命令行

参考:CSDN

  • 指定生成器
cmake -G "Ninja"
  • 添加变量
cmake -DANROID
  • 删除CMakeCache.txt变量
cmake -UANDROID

CMakeList

  • 环境变量:$ENV{PATH}

  • 编译选项

    • CMAKE_CXX_FLAGS
  • 输出目录

    • CMAKE_ARCHIVE_OUTPUT_DIRECTORY
    • CMAKE_LIBRARY_OUTPUT_DIRECTORY
    • LIBRARY_OUTPUT_DIRECTORY
    • CMAKE_RUNTIME_OUTPUT_DIRECTORY

GUI的参数导出

在对应目录的CMakeCache.txt中查找

函数

add_custom_command

TODO

execute_process

execute_process(COMMAND <cmd1> [args1...]]
[COMMAND <cmd2> [args2...] [...]]
[WORKING_DIRECTORY <directory>]
[TIMEOUT <seconds>]
[RESULT_VARIABLE <variable>]
[OUTPUT_VARIABLE <variable>]
[ERROR_VARIABLE <variable>]
[INPUT_FILE <file>]
[OUTPUT_FILE <file>]
[ERROR_FILE <file>]
[OUTPUT_QUIET]
[ERROR_QUIET]
[OUTPUT_STRIP_TRAILING_WHITESPACE]
[ERROR_STRIP_TRAILING_WHITESPACE])

aux_source_directory

aux_source_directory(
dir variable
)

添加dir下所有源文件(c/cpp)至variable

add_library

add_library(
# 1
lib_name
# 2
STATIC | SHARED | MODULE
# 3
# 4
source.cpp
source.h)
  1. 库名
  2. 库文件类型
  3. TODO
  4. 源文件

TODO

target_link_libraries(
# 1
target
# 2
liba
libb
# 3
)
  1. 通过add_executableadd_library生成的目标文件
  2. 库文件,无后缀名
  3. TODO

find_library

TODO

find_package

参考:简书

对于要查找的package,名为package

  • 先要设置路径:set(package_DIR 路径)

  • 然后进行查找

    find_package (package REQUIRED)
  • 找到的lib将存放在package_LIBS

include_directories

include_directories(
# 1
./dir1
./dir2
# 2
)
  1. 添加头文件目录
  2. TODO

add_executable

# 1
target
# 2
# 3
# 4
source.cpp
source.h
  1. 目标文件
  2. TODO
  3. TODO
  4. 源文件

调试

cmake --debug-output
cmake --trace
openCV安装

AS和cmake笔记

android的cpu架构

  • android查看cpu架构(termux)
cat /proc/cpuinfo
  • AArch32ARMv7架构的一种执行状态
  • AArch64ARMv8架构的一种执行状态
  • 64位ARMv8包含上面两种状态

cmake在AS中的使用

不要把mkcmake两种方法混淆

输出控制(message)

(TODO)如果想直接看到打印信息,使用WARNING以上的级别进行打印

  • message(WARNING "fuck")
    • Build->Build Output->CMake warnings查看
    • Build->Build Output->Toggle View查看

Android

Android Studio版本为3.5

只使用java模块

3.x-3.4.7-3.x版本

  1. File->New->Import Module->选择opencv文件夹下的sdk/java文件夹,此时Android Studio会自动加载Module name
  2. File->Project Structure->Dependencies->选择app->添加Module Dependency->选择opencv
  3. 将opencv文件夹下的sdk/native/libs下自己手机cpu对应的架构文件夹复制到app/libs
  4. 将opencv模块的build.gradlecomplieSdkVersion,buildToolVersion,minSdkVersion,targetSdkVersion改成和appbuild.gradle一样
  5. appbuild.gradleandroid节点下添加
    sourceSets {
    main {
    jni.srcDirs = []
    jniLibs.srcDirs = ['libs']
    }
    }

然后点击sync now

  1. 在使用opencv前进行初始化
    static {
    if (!OpenCVLoader.initDebug()) {
    ...
    }
    }

常见错误

  1. Caused by: CvException [org.opencv.core.CvException: OpenCV(4.1.1) /build/master_pack-android/opencv/modules/java/generator/src/cpp/utils.cpp:101: error: (-215:Assertion failed)

MatBitmap互转的时候长宽设置不对

只使用native模块

3.x-3.4.7-3.x版本

方法一

  1. CMakeLists.txt编写
    1. include头文件目录
    2. 加载libopencv动态库(libopencv_worldlibopencv_java3),命名为opencv_lib
    3. opencv_lib加载至目标文件
set(opencv_dir /home/lynx/fuck_mount/opencv/build_dir/4_1_0_shared/OpenCV-android-sdk)
set(opencv_lib libopencv_world.so) # 或libopencv_java3.so

include_directories(${opencv_dir}/sdk/native/jni/include)
add_library(opencv_lib SHARED IMPORTED)
set_target_properties(opencv_lib PROPERTIES IMPORTED_LOCATION
${opencv_dir}/sdk/native/libs/${ANDROID_ABI}/${opencv_lib})

target_link_libraries(
# 目标文件

opencv_lib
# 其他库 )
  1. 修改app的build.gradle
    • android节点下插入,否则会报错找不到libopencv_world.solibopencv_java3.so
sourceSets {
main {
jniLibs.srcDirs = ['/sdk/native/libs 对应目录']
}
}

方法二

参考:CSDN

  1. CMakeLists.txt
    1. 设置OpenCV查找的目录
    2. 查找OpenCV
    3. include头文件目录
    4. 将OpenCV的库添加至目标文件
set(sdk_dir /home/lynx/fuck_mount/opencv/build_dir/4_1_0_shared)
set(OpenCV_DIR ${sdk_dir}/OpenCV-android-sdk/sdk/native/jni)
find_package(OpenCV REQUIRED)
include_directories(${sdk_dir}/OpenCV-android-sdk/sdk/native/jni/include)

target_link_libraries(
# 目标文件

${OpenCV_LIBS}
# 其他库 )
  • 如果不设置OpenCV_DIR将无法查找OpenCV
  1. 修改app的build.gradle
sourceSets {
main {
jniLibs.srcDirs = ['/home/lynx/fuck_mount/opencv/build_dir/4_1_0_shared/OpenCV-android-sdk/sdk/native/libs']
}
}
  • 此外,务必将minSdkVersion调至21以上,否则将会只有v8a架构才能成功编译
  • 在app的build.gradle中:minSdkVersion->ANDROID_PLATFORM
  • ndkandroid.toolchain.cmake中:ANDROID_PLATFORM->ANDROID_PLATFORM_LEVEL->ANDROID_NATIVE_API_LEVEL
  • 如果不设置minSdkVersion,由于以上的确定关系,ANDROID_NATIVE_API_LEVEL会被设置为16,find_package会失败

4.x-4.1.0-4.x版本

方法一

3.x版本的方法一

方法二

3.x版本的方法二

常见问题

  1. java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found(4.x版本)

stackoverflow

(不确定的解决方法)在app的gradle中修改

externalNativeBuild {
cmake {
cppFlags ""
arguments "-DANDROID_STL=c++_shared"
}
}

不要使用gnustl_sharedgnustl_static,已经过时

  1. java.lang.UnsatisfiedLinkError: dlopen failed: library "libopencv_java3.so" not found(或libopencv_java4.so)

这是由于忘记了上面的第2步.Android Studio默认的jni路径为app/src/main/jniLibs,除了在CMakeLists.txt中导入opencv的库以外还需要二选一

  • 将对应版本opencv的库(libs/下一级的各个${ANDROID_ABI}文件夹)移动到jniLibs
  • build.gradle中修改默认jni路径(见上面第2步)
  1. 各种undefined reference to *(3.x版本)

std::ios_base::Init::Init()

TODO

  1. 各类AndroidBitmap的问题(3.x版本)
undefined reference to `AndroidBitmap_getInfo'

CMakeLists.txt增加

target_link_libraries(
# TODO 解决 AndroidBitmap 报错
jnigraphics)

参考:CSDN,这是一个很小的库,展示一个稳定的,基于C语言的接口,使本机代码安全地访问Java对象的像素缓冲区的位图

source code(使用完整代码)

3.x-3.x版本(未成功,需要eclipse)

4.x-4.1.0-4.x版本

参考:CSDN

  1. 环境变量

    • JAVA_HOME

      export JAVA_HOME=/home/lynx/fuck_mount/Android_Studio/jre # 使用Android Studio的JDK位置
    • ANDROID_SDK(非必须)

      export ANDROID_SDK=/home/lynx/fuck_mount/Android_SDK
    • ANDROID_NDK(非必须)

      export ANDROID_NDK=/home/lynx/fuck_mount/Android_SDK/ndk/{版本}
  2. 调整结构

    • 修改toolchain:android ndk的ndk/build/cmake/android.toolchain.cmake(约112行)

      elseif(ANDROID_TOOLCHAIN_NAME MATCHES "-[0-9].[0-9]$")
      set(ANDROID_TOOLCHAIN clang) # 将gcc改成clang
      endif()
    • android stl,在源代码的/platforms/android/build_sdk.py(约113行)(非必须)

      self.cmake_vars = dict(
      ANDROID_STL="c++_static", # change `gnustl_static` to `c++_static` or `c++_shared`
      ANDROID_ABI=self.name,
      ANDROID_PLATFORM_ID=platform_id,
      )
    • Android Studio的android sdk文件夹下,创建软连接ln -s build-tools/{版本} tools,否则无法编译安卓模块

  3. 修改cmake参数(2选1,推荐world)

    • java
      • OPENCV_ENABLE_NONFREE:改为ON
      • BUILD_SHARED_LIBS:不动或者改为OFF,与生成java库冲突
      • BUILD_ANDROID_PROJECTS:不动或者改为ON
      • BUILD_FAT_JAVA_LIB:不动或者改为ON,保证生成libopencv_java4.so
      • BUILD_JAVA:不动或者改为ON
      • /samples/android/CMakeLists.txt中除了ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations)那一行,其他全部注释掉,否则android sdk会在编译sample时报错
    • world
      • OPENCV_ENABLE_NONFREE:改为ON
      • BUILD_SHARED_LIBS:改为ON
      • BUILD_ANDROID_PROJECTS:不动或者改为ON
      • BUILD_FAT_JAVA_LIB:改为OFF,生成libopencv_world.so
      • BUILD_JAVA:不动或者改为ON
      • /samples/android/CMakeLists.txt中除了ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations)那一行,其他全部注释掉,否则android sdk会在编译sample时报错
  4. 执行platforms/android/build_sdk.py,完成编译

./build_sdk.py --ndk_path {ndk路径} --sdk_path {android sdk路径} --extra_modules_path {path_to_contrib/modules} {目标位置} {opencv源码位置}
# example
/home/lynx/fuck_mount/opencv_4_1_0/opencv-4.1.0/platforms/android/build_sdk.py --ndk_path /home/lynx/fuck_mount/Android/SDK/ndk/18.1.5063045 --sdk_path /home/lynx/fuck_mount/Android/SDK --extra_modules_path /home/lynx/fuck_mount/opencv/source_code/opencv_contrib_4_1_0/modules /home/lynx/fuck_mount/opencv_4_1_0/android_build /home/lynx/fuck_mount/opencv_4_1_0/opencv-4.1.0

如果没有设置则默认为环境变量

  • sdk-path:Android Studio的SDK目录
  • ndk-path:Android Studio的SDK目录下ndk/{ndk版本号文件}
  1. 后续关于CMakeLists.txtbuild.gradle的修改同native方法

常见错误

  1. java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.stitch-sPWgBONIqUrdX9XLB1OY6w==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.stitch-sPWgBONIqUrdX9XLB1OY6w==/lib/arm64, /data/app/com.example.stitch-sPWgBONIqUrdX9XLB1OY6w==/base.apk!/lib/arm64-v8a, /system/lib64, /product/lib64]]] couldn't find "libnative-lib.so"

缺少相应ABI的so库(目前计时在gradle里加入abiFilters也没有用),上述报错是因为没有编译全ABI.ABI配置:opencv-4.x/platforms/android/ndk-18-api-level-21.config.py

  1. 没装cmake
Executing: ['ninja', '--version']
Failed: [Errno 2] No such file or directory

Android Studio需要在SDK Manager里面预先安装CMake,否则编译的时候会找不到ninja等程序

  1. 没有libopencv_java4.so

    • BUILD_FAT_JAVA_LIBBUILD_ANDROID_PROJECTS要设置ON(或默认)
    • 记得修改android sdk tools文件结构
    • 不能同时编译动态库
  2. 编译错误

Regex: 'command line option .* is valid for .* but not for C\+\+'

TODO,可能是编译器的问题或cmake参数设置错误

  1. android project报错
A problem occurred configuring project ':face-detection'.
> NDK not configured.
Download it with SDK manager.

samples/android/CMakeLists.txt对应代码注释掉

  1. ndk报错
CMake Error at /home/lynx/fuck_mount/Android_SDK/ndk/20.1.5948944/build/cmake/android.toolchain.cmake:169 (message):
GCC is no longer supported. See
https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration.md.

需要将ndkbuild/cmake/android.toolchain.cmakeset(ANDROID_TOOLCHAIN gcc)改为clang

  1. ninja报错
CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

将ndk的bin目录(包含ninja等程序)添加至$PATH

  1. ccache未安装(3.x版本,TODO:不确定是否为必须)

用apt安装ccache即可

  1. ld报错(3.x版本)
cannot open crtbegin_dynamic.o: 没有那个文件或目录
cannot open crtend_android.o: 没有那个文件或目录
cannot find -lstdc++
cannot find -lm
cannot find -lc
cannot find -ldl

TODO修改gcc参数(但很大程度上是由于cmake参数配置错误)

  1. 添加-nostdlib
  2. 修改--sysroot参数
  1. clang++报错
error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

使用apt安装libtinfo5

  1. 编译错误
error: use of undeclared identifier 'vcvt_f16_f32'
float16x4_t v_dst = vcvt_f16_f32(v_src);

ndk

  1. libopencv_java3.so没有生成(3.x版本)

TODO,很大程度上是由于cmake参数配置错误

  1. cmake报错
Android SDK: Can't build Android projects as requested by
BUILD_ANDROID_PROJECTS=ON variable.
  • 4.x:android sdk build tool版本过低
  • 3.x:需要sdk整合ant(ide为eclipse)
  1. java报错
opencv init failed

检查gradlelib路径是否正确加载

额外说明

4.x版本

  • 不需要额外安装的软件:jdk,ninja-build,ndk,直接使用android studio的即可
  • 成功编译的版本:
    • ndk:20.1.5948944
    • sdk tools:28.0.3
    • cmake:3.13.4
  • 失败的版本:
    • ndk:21.0.6113669(报错undefined referrence to '__write_chk')
    • sdk tools:25.0.3(不能configure android project)

3.x版本 目前还没能成功编译android project

  • 3.x成功编译的版本:
  • 失败的版本:
    • ndk:20.1.5948944(报错undefined referrence to '__vsnprintf_chk')

使用JavaCV

4.x版本

不同导入方法,import的class位置可能不同

opencv部分功能的初始化

github原文

Loader.load(opencv_java.class);// 不能直接放在class开头

使用远程导入

appbuild.gradle示例(最外节点)

ext {
versions = [
'javacv': '1.4.4',
'ffmpeg': '4.1',
'opencv': '4.0.1'
]
}

dependencies {
...
implementation(group: 'org.bytedeco', name: 'javacv-platform', version: versions.javacv) {
exclude group: 'org.bytedeco.javacpp-presets'
}
implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: "${versions.ffmpeg}-${versions.javacv}"
implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: "${versions.ffmpeg}-${versions.javacv}", classifier: 'android-arm'
implementation group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: "${versions.ffmpeg}-${versions.javacv}", classifier: 'android-arm64'
implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: "${versions.opencv}-${versions.javacv}"
implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: "${versions.opencv}-${versions.javacv}", classifier: 'android-arm'
implementation group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: "${versions.opencv}-${versions.javacv}", classifier: 'android-arm64'
}

作为lib导入

根据手机具体的cpu架构进行导入

appbuild.gradle

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}

将文件(视具体情况)

  • javacpp.jar
  • javacv.jar
  • openblas.jar
  • openblas-android-arm64.jar
  • opencv.jar
  • opencv-android-arm64.jar
    复制到app/libs/文件夹里

常见错误

  1. cpu架构错误/缺少(需添加-android-arm之类的库)
2019-10-27 16:01:32.439 29256-29322/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.github.crazyorr.ffmpegrecorder, PID: 29256
java.lang.RuntimeException: An error occurred while executing doInBackground()
  1. 没有对opencv初始化
2019-10-27 16:00:43.930 28933-28933/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.javacv, PID: 28933
java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat() (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__)
  1. 缺少openblas的相关jar
2019-10-27 15:59:23.158 28618-28618/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.javacv, PID: 28618
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/bytedeco/openblas/presets/openblas;

混用java+native模块

4.x native(或source code)+3.x java

参考:CSDN

  1. 加载native模块

  2. File->New->Import Module->选择opencv文件夹下的sdk/java文件夹,自己定义模块的名字

  3. 修改模块的gradle文件(TODO)

// 将原来的application改成library
apply plugin: 'com.android.library'

android {
// 将版本信息改得和`app`的`build.gradle`一样
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
// 删除applicationId
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
// 不改动
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
  1. 修改app的gradle文件,加载两者的lib,缺一不可
sourceSets {
main {
jniLibs.srcDirs = ['/home/lynx/fuck_mount/opencv/source_code/opencv_3_4_7_android/sdk/native/libs',
'/home/lynx/fuck_mount/opencv/build_dir/4_1_0_shared/OpenCV-android-sdk/sdk/native/libs']
}
}
  1. 修改app的gradle文件,添加java模块依赖

dependencies {
implementation project(path: ':openCVLibrary347')
}

Linux

OpenCV source code 3.x(3.4.7)

gui安装

4.x一样

常见错误

  1. fatal error: Eigen/Core: 没有那个文件或目录``#include <Eigen/Core>

    1. 修改WITH_EIGEN=OFF

    2. (或)

      • 先保证安装eigen:sudo apt install libeigen3-dev
      • 添加EIGEN_INCLUDE_PATH=/usr/include/eigen3(视具体情况)
  2. ippicv_linux_20141027.tgz下载失败

    CMake Error at 3rdparty/ippicv/downloader.cmake:71 (file):
    file DOWNLOAD HASH mismatch

    for file: [/home/lynx/fuck_mount/opencv_3_0_0/opencv/3rdparty/ippicv/downloads/linux-8b449a536a2157bcad08a2b9f266828b/ippicv_linux_20141027.tgz]
    expected hash: [8b449a536a2157bcad08a2b9f266828b]
    actual hash: [5c4f36bf7b2421d52289f0297ba1406f]
    status: [28;"Timeout was reached"]

TODO

  1. ippicv_2019_lnx_intel64_general_20180723.tgz下载超时

    IPPICV: Download: ippicv_2019_lnx_intel64_general_20180723.tgz
    CMake Warning at cmake/OpenCVDownload.cmake:193 (message):
    IPPICV: Download failed: 28;"Timeout was reached"
    1. opencv/opencv_3rdpartyippicv对应分支中下载对应的tgz

    2. tgz放入/home/lynx/Downloads/

    3. 修改opencv的source code: vi /3rdparty/ippicv/ippicv.cmake,将ippicvhttps地址改为file:/home/lynx/Downloads/

    4. 重新cmake-gui

OpenCV source code 4.x(4.1.0)

依赖包

sudo apt install libgtk2.0-dev pkg-config

一定要安装,否则会报错

  • 缺少gtk
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.1.0) /home/lynx/fuck_mount/opencv/source_code/opencv_4_1_0/modules/highgui/src/window.cpp:610: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'

命令行安装(TODO)

  1. cmake
cd {生成makefile的位置}
cmake {source的位置}
  1. make
cd {生成makefile的位置}
make
  1. make install
make install {安装的位置}

gui安装

参考:CSDN

  1. 安装cmake-gui
sudo apt install cmake-gui
  1. 启动cmake-gui
cd {build二进制文件的目录}
cmake-gui {opencv source code}
  1. Configure->Unix Makefiles:Use default native compilers->finish

  2. 狂点Configure知道没有红色区域

  3. 赋值

变量名 赋值
BUILD_EXAMPLES 勾选
CMAKE_BUILD_TYPE Release
CMAKE_INSTALL_PREFIX {自己定的cmake_install路径}
OPENCV_EXTRA_MODULES_PATH {opencv-contrib source code}/modules
OPENCV_GENERATE_PKGCONFIG 勾选
  1. 狂点Configure

  2. Generate,等到Generating done

  3. 在build路径make

sudo make -j4 # 具体看有多少cpu
cat /proc/cpuinfo | grep "processor" | wc -l # 查看cpu个数
sudo make install
  1. 配置opencv4.pc(2选1)

    • 修改PKG_CONFIG_PATH:增加{你cmake_install的路径}/lib/pkgconfig(opencv4.pc所在的路径)
    • (TODO,没试过)复制opencv4.pc/usr/lib/pkgconfig
  2. 配置库路径,(新建)/etc/ld.so.conf.d/opencv.conf

{你cmake_install路径}/lib/ # 自己的lib路径
sudo ldconfig
  1. 编译测试

如果是opencv.pcopencv4改成opencv

pkg-config --modversion opencv4
g++ a.cpp `pkg-config --cflags --libs opencv4` -o test && ./test

常见问题

  1. 在其他项目中用CMake导入OpenCV模块:
    find_package(OpenCV REQUIRED)
    include_directories(${OpenCV_INCLUDE_DIRS})

之后cmake出现By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH ...:

这是由于没有设置环境变量OpenCV_DIR,设置为OpenCV编译后的目录下含有OpenCVConfig.cmake的对应路径

gcc笔记

参数

the dynamic linking library,如果程序中使用dlopen,dlsym,dlclose,dlerror**加载动态库,需要设置选项-ldl

添加库/头文件

CSDN

gcc -I/include -L/lib -lsb
  • I:头文件位置
  • L:库位置
  • l:库名

查看可执行文件以来的动态链接库

ldd a.out
  • 显示系统信息
uname -r
  • 安装内核头文件
sudo apt install linux-headers-5.0.0-36-generic # 你的版本号
  • 定位头文件
locate slab.h
  • 查找头文件
sudo apt install apt-file
sudo apt-file update
apt-file search ".h"
Android Studio笔记

安装

官方文档
国内网站

Linux

  • 运行程序:android-studio/bin/studio.sh

  • 64位机器需要安装32位库

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
  • 设置代理(不推荐,会搞出一堆问题)

手动设置:mirrors.neusoft.edu.cn:80

汉化

教程

汉化包

使用

windows

配置文件夹位置:C:/Users/lynx/.AndroidStudio3.5

增加虚拟设备:Tools->AVD Manager

android device monitor位置:E:\Android\Sdk\tools\monitor.bat

memory monitor 打开:Run->Profiler

解决网络问题:Configure->Setting->System Setting->HTTP Proxy->Auto-detect proxy settings

布局编辑器打开:打开一个xml文件->底部选择Design

Linux

清除缓存:Build->Clear Project

快捷键

  • 向前/后跳转:alt+shift+left/right
  • 打开Logcat:alt+6
  • 重构:shift+f6
  • 运行:shift+f10

常见错误

  1. Android resource linking failed

查看app的gradle有没有缺少implementation

  1. SDK tools directory is missing

TODO

  1. SDK does not contain any platforms

SDK的目录下要有名为platforms的文件夹

  1. Connection failed

TODO

  1. Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-x.x.x-all.zip'

  2. Gradle sync failed: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request" (973 ms)

直接下载解压相应文件到本地,修改gradle配置:Setting->Build, Execution, Deployment->Gradle

  1. Could not GET ...

不使用代理(No proxy),同时在gradle目录下编辑gradle.properties,删除所有代理

Linux命令笔记

声卡驱动

  • 重启声卡
sudo /sbin/alsa force-reload

gnome

  • 重置桌面配置
dconf reset -f /org/gnome/
  • 重启桌面
sudo /etc/init.d/gdm3 restart

sudo

在sudo模式下使用用户的.vimrc

sudo -E vim file

当前目录,只保留file

  • xargs
find /当前目录 -type f ! -name "file"|xargs rm -f
  • find自带命令
find /当前目录 -type f ! -name "file" -exec rm -f {} \

递归删除

.java

find ./ -name "*.java" | xargs rm -rfv

批量修改文件名

rename 's/原内容/改后内容/' *

打包

tar czvf FileName.tar DirName
  • 计算目录大小
du -h --max-depth=1 .
  • 合并文件夹
cp -frp new/* old/

-f强制覆盖,-r递归,-p保持新文件的属性不变

dpkg

  • 查找已装软件?
dpkg -l|grep filename
  • 卸载软件
dpkg -r filename

或?

dpkg -P filename
  • 彻底删除标识为rc的配置信息

rc:软件已卸载,配置文件还在

dpkg -l | grep ^rc | cut -d' ' -f3 | sudo xargs dpkg --purge

目录分析(du)

示例

du -d1 -b -a .
du -d0 -m .

cat

  • 输出固定行数
cat $file | head -n +6
```

[详细](https://blog.csdn.net/NFR413/article/details/78966085)

## curl

- 下载`$file`

```bash
curl -O $pathtofile
  • 命令行中输出表达式的值
echo $[1 == 2]

Linux的算术运算

进程

  • 切换到后台
<ctrl+z>
  • 查看后台进程
jobs
  • 使第N个进程在前台/后台运行
fg %N
bg %N

不加N默认对最后一个进程操作

ctags

  • vim设定源

固定

set tags=$path

先当前目录,后向上找

set tags=tags;
set autochdir

ln链接

  • 文件夹软链接
ln -s $exists $new

wc统计行数

find -maxdepth 10 -type f | xargs wc -l
wc -l `find -name '*.*'`

更改用户/权限

sudo chmod -R 777 *
sudo chown -R user * # sudo chown -R user:usergroup *

parallel并行(TODO)

参考

eigen安装
gdb笔记
  • 设置main的参数

start之前,输入set args abc 123

ubuntu使用midi

所需软件

  • qsynth:支持soundfonts
  • jackd:qsynth需要的驱动程序
  • MuseScore:播放midi文件,midi转五线谱,五线谱编辑
  • vmpk:midi键盘模拟器

(待定)https://ywnz.com/linuxjc/352.html

软件配置

参考:https://blog.ghostry.cn/mood/688.html

MuseScore

  • 安装
sudo add-apt-repository ppa:mscore-ubuntu/mscore-stable
sudo apt-get update
sudo apt-get install musescore
ubuntu配置

分盘

  1. 安装失败
  • swap:1024M,主分区
  • /:10G,主分区
  • /boot:128M,主分区
  • /home:剩余,主分区
  1. 安装成功
  • swap:4096M,逻辑分区
  • /:剩余,主分区
  1. 未知
  • swap:4096M,逻辑分区
  • /boot:200M,主分区
  • /:10G,主分区
  • /home:剩余,逻辑分区
  1. 未知
  • /:全部,主分区

驱动

ubuntu安装mac设备驱动

总览:github
触摸板/键盘:github

参考代码(不适用于macbook8,1)

sudo echo -e "\n# applespi\napplespi\nspi_pxa2xx_platform\nintel_lpss_pci" >> /etc/initramfs-tools/modules
sudo
sudo apt install dkms
sudo git clone https://github.com/roadrunner2/macbook12-spi-driver.git /usr/src/applespi-0.1
sudo dkms install -m applespi -v 0.1

安装软件

基本

  • sublime
  • chromium:注意数据备份.config/chromium
    • tamper monkey
    • Adblock Plus
    • SwitchyOmega
    • crxMouse Top Gestures
    • hoxx
  • dukto:3系统互传软件
  • hyper:配置文件~/.hyper.js
  • vscode
  • gnome-tweak:如果还在用gnome
    • dash to panel
    • topicons plus
    • user themes
  • 搜狗输入法:CSDN
    • 官网下载deb
    • sudo apt install -f && sudo dpkg -i sougou.deb
    • 设置->区域和语言->键盘输入法系统(点击任务栏的输入法图标->Configure)
  • 日语输入法
    sudo apt install fcitx-mozc
    # sudo apt install fcitx-anthy
    # im-config -n fcitx

重启(fcitx configuration)

  • 片假名切换:f7
    • gparted:磁盘分区
    • exfat-utils:支持exfat格式的u盘

非基本

  • Indicator Stickynotes
  • QQ(见wine)
  • wps

deepin wine软件

  • QQ
  • TIM
  • QQ轻聊版
  • 微信
  • Foxmail
  • 百度网盘
  • 360压缩
  • WinRAR
  • 迅雷极速版

详细,github

软件的文件存放位置

  • QQ:

/home/lynx/.deepinwine/Deepin-QQ/dosdevices/c:/users/lynx/My Documents/Tencent Files/$account/FileRecv

deepin wine字体异常处理

修改注册表(TODO)
  1. 新建(任何位置,文件名随意)zh.reg
    1.1. 字体链接

    [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontLink\SystemLin]
    "字体名"="字体文件"

    1.2. 字体(强制)替换

    [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
    "字体名"="字体文件"

    1.3 字体(缺失)替换

    [HKEY_CURRENT_USER\Software\\Wine\\Fonts\\Replacements]
    "字体名"="字体文件"
  2. 修改注册表(貌似没用)

deepin-wine regedit zh.reg
补充字体文件
  • 字体文件存放位置:./deepin-wine/软件名/driver_c/windows/fonts/

wps软件

缺少字体的处理方法

该方法已失效

下载并解压字体文件夹wps-font-symbols

git clone https://github.com/pengphei/wps-font-symbols
sudo cp -r wps-font-symbols /usr/share/fonts
# cd /usr/share/fonts
# sudo chmod 755 wps-font-symbols
cd /usr/share/fonts/wps-font-symbols
# sudo chmod 644 *
sudo mkfontdir
sudo mkfontscale
fc-cache
或直接从windows复制对应字体

系统设置

笔记本行为设定

  • 合盖不休眠:/etc/systemd/logind.conf
HandleLidSwitch=ignore

CSDN

密钥环

  • ubuntu 18.x

密码和密钥$\to$默认密钥环$\overset{\mbox{右键}}{\to}$更改密码$\to$空白

  • ubuntu 19.x

密码和密钥$\to$登录$\overset{\mbox{右键}}{\to}$更改密码$\to$空白

grub配置

  • 位置

/etc/default/grub

  • 内容修改
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
  • 生效设置
sudo grub-set-default 2
sudo update-grub

数字任意

时间配置

sudo apt-get install ntpdate
sudo ntpdate time.windows.com
sudo hwclock --localtime --systohc

gnome-shell-entensions

chrome扩展

sudo apt-get install chrome-gnome-shell

chrome浏览器插件

重启gnome-shell

alt+f2$\to$r

extension位置

  • ~/.local/share/gnome-shell/extensions
  • /usr/share/gnome-shell/extensions

解决显示应用程序2个dock

cd /usr/share/gnome-shell/extensions
sudo rm -rf ubuntu-dock@ubuntu.com

解决桌面图标在重启后乱序

安装一个新的桌面图标扩展,关闭gnome-tweaks的桌面图标显示

外观修改

修改登录背景图片

/etc/alternatives/gdm3.css:

#lockDialogGroup {
background: url(file:///usr/share/backgrounds/Aatrox.jpg);
background-position: center;
background-size: cover; }

默认开机动画

sudo update-alternatives --config default.plymouth

修改开机动画

ubuntugeek
更多

  1. 创建新文件夹
sudo mkdir /usr/share/plymouth/themes/myTheme
  1. vi myTheme/myTheme.plymouth
[Plymouth Theme]
Name=MyTheme
Description=随你
ModuleName=script

[script]
ImageDir=/usr/share/plymouth/themes/myTheme
ScriptFile=/usr/share/plymouth/themes/myTheme.script
  1. 复制png(必须)图片到myTheme

  2. vi myTheme/myTheme.script

wallpaper_image = Image("Aatrox_1080.png");
screen_width = Window.GetWidth();
screen_height = Window.GetHeight();
resized_wallpaper_img = wallpaper_image.Scale(screen_width, screen_height);
wallpaper_sprite = Sprite(resized_wallpaper_img);
wallpaper_sprite.SetZ(-100);
  1. 安装主题
sudo update-alternatives --install /usr/share/plymouth/themes/default.plymouth default.plymouth /usr/share/plymouth/themes/myTheme/myTheme.plymouth 100
sudo update-alternatives --config default.plymouth
sudo update-initramfs -u

修改grub主题

  1. /boot/grub/themes文件夹创建
  2. 配置文件/etc/grub.d/00_header:
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.

GRUB_THEME="/boot/grub/themes/Vimix/theme.txt"
GRUB_GFXMODE="1920x1080x32"

可按照尺寸修改背景图片

  1. 更新配置
sudo update-grub

语言和文字

  • 对彩色表情的支持(TODO):

    • fonts-noto-color-emoji
    • fonts-emojione
  • 对特定软件使用特定语言打开(不能已经打开其他窗口)

sh -c "LANGUAGE=en /bin/chromium-browser %U"
  • 修改语言和编码

    • 位置:/etc/default/locale
    • 查看当前语言:locale
  • locale备份

LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:en_US:en
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
ubuntu英雄联盟

lutris运行美服等服务器(不包含国服,韩服)

  1. 安装lutris,并注册账号

https://lutris.net/downloads/

sudo sudo add-apt-repository ppa:lutris-team/lutris
sudo apt-get update
sudo apt-get install lutris
  1. 安装驱动

https://github.com/lutris/lutris/wiki/Installing-drivers

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install nvidia-driver-430 libnvidia-gl-430 libnvidia-gl-430:i386
  1. 安装wine

https://github.com/lutris/lutris/wiki/Wine-Dependencies

sudo dpkg --add-architecture i386 
wget -nc https://dl.winehq.org/wine-builds/winehq.key
sudo apt-key add winehq.key
sudo apt-get update

添加PPA

版本 对应命令
Ubuntu 19.10 sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ eoan main'
Ubuntu 19.04 sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ disco main'
Ubuntu 18.10 sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ cosmic main'
Ubuntu 18.04 Linux Mint 19.x sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'
Ubuntu 16.04 Linux Mint 18.x sudo apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ xenial main'

Install Wine (Ubuntu 19.10 使用 wine-stable):

sudo apt-get install --install-recommends winehq-stable
  1. 安装英雄联盟

https://lutris.net/games/league-of-legends/

在安装过程中所有弹出的安装信息全部点取消

国服

forum.ubuntu
ubuntukylin
bbs.deepin

TODO

ubuntu配置ss和ssr

shadowsocks

参考

命令行

TODO

gui

安装shadowsocks-qt5

  1. github

  2. PPA

sudo add-apt-repository ppa:hzwhuang/ss-qt5
sudo apt-get update
sudo apt-get install shadowsocks-qt5

配置浏览器插件

firefox

TODO

chrome

  • 下载地址:https://github.com/FelisCatus/SwitchyOmega/releases/

  • 设置新的情景模式(其他的不用管)->代理服务器:

    • 代理协议:socks5
    • 代理服务器:127.0.0.1
    • 代理端口:1080
    • 不代理的地址列表:<local>
    • ->应用选项
  • 编辑auto switch

    • 规则列表网址:https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt->立即更新情景模式
    • 规则列表规则情景模式改为代理服务器对应的模式
    • ->应用选项
  • 在浏览器插件部分切换auto switch

shadowsocksR

参考

  1. 安装依赖
sudo apt install libcanberra-gtk-module libcanberra-gtk3-module gconf2 gconf-service libappindicator1
PyQt5笔记

安装

报错

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-n2fvey5k/PyQt5/
  1. 下载easy_install,网址https://pypi.org/project/setuptools/#files
  2. 安装:进入目录,sudo python3 setup.py install
  3. sudo easy_install -U setuptools
Command "/usr/bin/python3 -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-y3vn2gdm --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- "sip >=5.0.1, <6" "PyQt-builder >=1.1.0, <2"" failed with error code 1 in None
  1. pip3 install --upgrade pip
tikz笔记

overleaf:https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ:_A_Tutorial_for_Beginners_(Part_3)%E2%80%94Creating_Flowcharts

\begin{tikzpicture}[very thick]
\draw[style={draw=blue!50, fill=blue!20,}] (0,0) ellipse [x radius=2cm, y radius=2cm];
\coordinate [label=center:{$G$}] (A) at (-1.2,0);
\draw[style={draw=red!50, fill=red!20, opacity=0.7,}] (0.2,-0.7) ellipse [x radius=1.2cm, y radius=1.1cm];
\coordinate [label=center:{$N$}] (A) at (0.2,-0.9);
\draw[style={draw=green!50, fill=green!20, opacity=0.7,}] (0.2,0.7) ellipse [x radius=1.2cm, y radius=1.1cm];
\coordinate [label=center:{$H$}] (A) at (0.2,0.9);
\coordinate [label=center:{$H\cap N$}] (A) at (0.2,0);
\end{tikzpicture}
\begin{tikzpicture}[
%overlay, remember picture
]
\coordinate (a0) at ( 0.3, 0.2);
\coordinate (b0) at ( 3.3, 1.2);
\coordinate (c0) at ( 4.1,-1.3);
\coordinate (d0) at ( 8.1,-0.3);
\draw (c0) -- (a0);
\draw (c0) -- (d0);
\draw[style={draw=green!50, fill=green!20,}](a0)ellipse[radius=1];
\draw[style={draw=green!50, fill=green!20,}](b0)ellipse[radius=1];
\draw[style={draw=green!50, fill=green!20,}](c0)ellipse[radius=1.3];
\draw[style={draw=green!50, fill=green!20,}](d0)ellipse[radius=1.3];

%\draw[style={draw=red!50, fill=red!20,}] (2,-4) ellipse [radius=0.2];
%\coordinate [label=center:{表示牛逼的点}] (info1) at (2,-5);
%\draw[style={draw=blue!50, fill=blue!20,}] (8,-4) ellipse [radius=0.2];
%\coordinate [label=center:{表示不牛逼的点}] (info2) at (8,-5);
\coordinate (a1) at ( 0 , 0 );
\coordinate (b1) at ( 0 , 0.7);
\coordinate (c1) at ( 0.8, 0.5);
\coordinate (d1) at ( 0.5,-0.2);
\draw (a1) -- (b1);
\draw (a1) -- (c1);
\draw (a1) -- (d1);
\coordinate (a2) at ( 0 +3, 0 +1);
\coordinate (b2) at ( 0 +3, 0.7+1);
\coordinate (c2) at ( 0.8+3, 0.5+1);
\coordinate (d2) at ( 0.5+3,-0.2+1);
\draw (a2) -- (b2);
\draw (a2) -- (c2);
\draw (a2) -- (d2);
\coordinate (a3) at (-3.9+8,-1.1);
\coordinate (b3) at (-3.2+8,-2.0);
\coordinate (c3) at (-4.5+8,-0.9);
\coordinate (d3) at (-4.4+8,-2.1);
\coordinate (e3) at (-3.0+8,-1.1);
\draw (a3) -- (b3);
\draw (a3) -- (c3);
\draw (a3) -- (d3);
\draw (a3) -- (e3);
\coordinate (a4) at (12-3.9,-1.1+1);
\coordinate (b4) at (12-3.2,-2.0+1);
\coordinate (c4) at (12-4.5,-0.9+1);
\coordinate (d4) at (12-4.4,-2.1+1);
\coordinate (e4) at (12-3.0,-1.1+1);
\draw (a4) -- (b4);
\draw (a4) -- (c4);
\draw (a4) -- (d4);
\draw (a4) -- (e4);

\draw[style={draw=blue!50, fill=blue!20,}](a1)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](b1)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](c1)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](d1)ellipse[radius=0.2];

\draw[style={draw= red!50, fill= red!20,}](a2)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](b2)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](c2)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](d2)ellipse[radius=0.2];

\draw[style={draw= red!50, fill= red!20,}](a3)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](b3)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](c3)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](d3)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](e3)ellipse[radius=0.2];

\draw[style={draw=blue!50, fill=blue!20,}](a4)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](b4)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](c4)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](d4)ellipse[radius=0.2];
\draw[style={draw=blue!50, fill=blue!20,}](e4)ellipse[radius=0.2];
\end{tikzpicture}
\begin{tikzpicture}[
a/.style={circle,draw=blue!50,fill=blue!20,very thick,minimum size=10mm},
b/.style={circle,draw=green!50,fill=green!20,very thick,minimum size=10mm}
]
\node[a,label={[shift={(0,-2)}]1}] (n1) at (0, 0){a};
\node[a,label={[shift={(0,-2)}]2}] (n2) at (2, 0){a};
\node[b,label={[shift={(0,-2)}]3}] (n3) at (4, 0){b};
\node[a,label={[shift={(0,-2)}]4}] (n4) at (6, 0){a};
\node[b,label={[shift={(0,-2)}]5}] (n5) at (8, 0){b};
\draw[->,thick](n1) to (n2);
\draw[->,thick](n2) to (n3);
\draw[->,thick](n3) to (n4);
\draw[->,thick](n4) to (n5);
\draw[shorten >= 0pt,->,thick](n2) to[in=150,out=30,loop,looseness=4.8]node[midway,above]{a}(n2);
\draw[->,thick](n4) to[in=-30,out=-150]node[midway,below]{a}(n2);
\end{tikzpicture}
\newfontfamily\DejaVu{DejaVu Sans Mono for Powerline}
\def\Font#1{\fontsize{#1}{\baselineskip}\DejaVu\textbf}
\begin{tikzpicture}[remember picture, overlay]
\node [shift={(0cm,-3cm)}] at (current page.north west)
{%
\begin{tikzpicture}[remember picture, overlay]
\draw [fill=gray] (0,3) -- (3,3) -- (0,0) -- cycle ;
\draw [fill=white] (0,3) -- (2,3) -- (0,1) -- cycle ;
\draw (0,0) to node[midway, above, rotate=45] {\textcolor{white}{\Font{9}{fork me on github}}} (3,3) ;
\draw (0,1) to node[midway, above, rotate=45] {\includegraphics[width=.05\textwidth]{pictures/github}} (2,3) ;
\end{tikzpicture}
};
\end{tikzpicture}
python爬虫

requests(静态html/json)

参数设置

cookies

headers

headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/79.0.3945.79 Chrome/79.0.3945.79 Safari/537.36',
'Host':'music.163.com',
'Referer':'https://music.163.com'
}

selenium + phantomjs(js渲染)

安装

sudo apt install phantomjs
python3 -m pip install selenium # 不要直接用pip3
cpp笔记

二分搜索,默认升序

lower_bound(a,a + n,b,cmp)

前闭后开[first, last)区间进行二分查找,返回大于或等于val的第一个元素位置
如果所有元素都小于val,则返回last的位置,且last的位置是越界的

upper_bound(a,a + n,b,cmp)

返回序列[first, last)中的第一个大于值val的位置

binary_search(a,a + n,b,cmp)

在已排序的[first, last)中寻找元素val,如果[first, last)内有等于val的元素,它会返回true,否则返回false,它不返回查找位置

全排列,默认next升序

next_permutation(a, a + n, b, cmp);
prev_permutation(a, a + n, b, cmp);

循环?

运算符重载?

=重载的例子(class之外)

sb& sb::operator=(const sb& a)
{
if (this == &a)
return *this;
x = a.y;
y = a.x;
return *this;
}

==重载

bool operator==(sb a, sb b)
{
if (a.x == b.x&&a.y == b.y)
return 1;
return 0;
}

浮点数精度控制

cout << fixed << setprecision(9) << a << endl;
cout << setiosflags(ios::scientific) << setprecision(4) << a << endl;

vector使用

vector <fuck> edge[100];
edge[1].push_back(temp);
for (int i = 0; i < edge[1].size(); i ++)
{
edge[1].at(i).u = 1;
}
edge[1].clear();

queue

queue<int> q;
q.front();

priority_queue

struct vfuck
{
long long dis;
}vnode[50001];
struct cmp
{
bool operator()(vfuck a, vfuck b)
{
return a.dis > b.dis;
}
};
priority_queue <vfuck, vector<vfuck>, cmp> pq;// 最小堆
while (pq.empty() == 0)
{
tmp = pq.top();
pq.push(tmp);
pq.pop();
}
struct path {
int len;// 长度
friend bool operator < (path a, path b) {// 不能是 >
return a.len > b.len;// 最小堆
}
};

priority_queue <path> paths;// 最小堆

map

赋值/输出

map <string, int> fuck;
map <string, int>::iter;
for (iter = fuck.begin(); iter != fuck.end(); iter ++)
{
fuck["***"] = 1;
cout << iter->first << iter->second;
}

其他

cnblog

mysql笔记

通用

建表

create table if not exists customers(
cid char(4) not null,
cname char(20) not null,
city char(20),
discnt real,
primary key ( cid )
) character set = utf8 -- 支持中文;

修改并查看注释(comment)

alter table customers
change column cid
cid char(4) not null comment '编号',
change column cname
cname char(20) not null comment '姓名',
change column city
city char(20) comment '城市',
change column discnt
discnt real comment '折扣';
show full columns from customers;

insert去重

  • ignore
insert ignore into table (column)
values
...
  • on duplicate key update

TODO

  • replace into

TODO

更新表数据

update table_name set item="shit" where fuck="fuck";

每组前n

参考

计算时间差

SELECT TIMESTAMPDIFF(MONTH,'2009-10-01','2009-09-01');
SELECT TIMESTAMPDIFF(MONTH,'2009-10-01','2009-09-01') as a;

其中MONTH部分可以更改为

  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • MONTH
  • YEAR

通配符

select season_id, id, title, p_year, c_year from season
where title like '%鲁路修%'
order by p_year;

其他

添加用户

insert

use mysql
insert into user ( Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv, Create_view_priv, Show_view_priv, Create_routine_priv, Alter_routine_priv, Create_user_priv, Event_priv, Trigger_priv, Create_tablespace_priv, ssl_type, ssl_cipher, x509_issuer, x509_subject, max_questions, max_updates, max_connections, max_user_connections, plugin, authentication_string, password_expired, password_last_changed, password_lifetime, account_locked )
values
('localhost', 'niabie', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', password(''), 'N', '2019-11-07 15:17:00', null, 'N');
flush privileges;# 更新

用户具有创建数据库等的权限,authentication_string不需要则填null

create

参考

create user lynx;
update user set Host='localhost', authentication_string=password('1111') where User='lynx';
flush privileges;# 更新
grant all on database.table to 'lynx'@'localhost';# 分配database的table权限给用户
show grants for lynx@localhost;# 显示用户权限

用户没有创建数据库的权限

修改数据库位置

  • 查看数据库存放位置
show variables like '%dir%';
-- 或
select @@datadir

修改数据库存放位置

参考:digitalocean

  1. 暂停mysql服务
sudo systemctl stop mysql
sudo systemctl status mysql
  1. 转移目录
sudo rsync -av /var/lib/mysql {dir}
sudo mv /var/lib/mysql /var/lib/mysql.bak
  1. 修改mysql配置

/etc/mysql/mysql.conf.d/mysqld.cnf

[mysqld]
datadir = {dir}/mysql/
  1. 修改apparmor访问rules

/etc/apparmor.d/tunables/alias

alias /var/lib/mysql -> {dir}/mysql/,
sudo systemctl restart apparmor
  1. 创建mysql所需的的最小文件结构
sudo mkdir /var/lib/mysql/mysql -p
  1. 重启mysql
sudo systemctl start mysql
sudo systemctl status mysql
# sudo rm -Rf /var/lib/mysql.bak
# sudo systemctl restart mysql

其他

  • 创建数据库并选择
create database homework3;
show databases;
use homework3;
show tables;
  • 查看版本等
select version();
select now();
select user();
  • 查看端口
show variables like 'port';

1 / 6