Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

田可欣-CV-OpenCV.md #20

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b702a8e
Create markdown file for Lesson 1 conclusion
kk37111754 Apr 9, 2022
fe1eb96
Create 田可欣-CV-OpenCV-20220408.md
kk37111754 Apr 12, 2022
97b8838
Create 田可欣-CV-OpenCV-20220412.md
kk37111754 Apr 19, 2022
726719b
Create 田可欣-CV-OpenCV-20220415.md
kk37111754 Apr 19, 2022
b9c571a
Create 田可欣-CV-OpenCV-20220419.md
kk37111754 Apr 23, 2022
8b06903
Create README.md for jupyter notebooks directory
kk37111754 Apr 23, 2022
e5ecc52
Add files via upload
kk37111754 Apr 23, 2022
d4db0a6
Created README.md for PDF Files directory
kk37111754 Apr 23, 2022
e8a6ea6
Add files via upload
kk37111754 Apr 23, 2022
52e29ac
Create README.md for pic directory
kk37111754 Apr 23, 2022
dac6698
Add files via upload
kk37111754 Apr 23, 2022
1b57d6d
Update directory of pictures
kk37111754 Apr 23, 2022
7fc3a6e
Update directory of pictures and jupyter notebooks
kk37111754 Apr 23, 2022
0648bb6
Update directory of picture and pdf file
kk37111754 Apr 23, 2022
eb2a7e3
Update directory of pictures and jupyter notebooks
kk37111754 Apr 23, 2022
28de35e
Delete 阿里云赛题理解.ipynb as no copyright is assigned
kk37111754 Apr 23, 2022
c44b606
Add files via upload
kk37111754 Apr 23, 2022
f41d4e4
Update 阿里云赛题理解.ipynb with copyright
kk37111754 Apr 23, 2022
ea23ff7
Add files via upload
kk37111754 Apr 27, 2022
febc114
Create 田可欣-CV-OpenCV-20220422.md
kk37111754 Apr 27, 2022
075c5d1
Add files via upload
kk37111754 May 1, 2022
bf65f32
Create 田可欣-CV-OpenCV-20220426.md
kk37111754 May 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions 2022.04.05课后/田可欣-CV-OpenCV-20220405.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 赛题理解

Created: April 4, 2022 12:52 AM

上课时间: April 5, 2022

# 评分标准

- 数据集使用方法
- 评分标准
- 提交标准

# 赛题目的

以街道字符为为赛题数据,数据集报名后可见并可下载,该数据来自收集的SVHN街道字符,并进行了匿名采样处理

# 数据集

- 训练集数据包括3W张照片
- 验证集数据包括1W张照片
- 训练集和验证集每张照片包括颜色图像和对应的编码类别和具体位置
- 测试集
- A包括4W张照片
- B包括4W张照片

## 数据格式

<img src="https://github.com/kk37111754/Aliyun-CV/blob/dac6698ea4c041df3445f84ae9ca77c204c63a4a/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/pic/1-Data.png" width="300px" alt="DataStructure"><img src="https://github.com/kk37111754/Aliyun-CV/blob/dac6698ea4c041df3445f84ae9ca77c204c63a4a/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/pic/1-json.png" width="300px" alt="DataJSON">

- 左上角为 (0, 0)
- x轴越往右越大
- y轴越往左越大
- label:识别到的数字

# 文件查找方法

在提供的环境中,

- 使用docker挂载数据集
- 无限制使用docker访问内容
- 但是无法下载

# 计算机视觉逻辑

- 读取图片
- 对样本进行观察
- 建立方案,进行分析

# 工具

## JSON格式化

[bejson](https://www.bejson.com/)

## Docker学习

[菜鸟教程](https://www.runoob.com/docker/docker-tutorial.html)

## 环境

![Env](https://github.com/kk37111754/Aliyun-CV/blob/dac6698ea4c041df3445f84ae9ca77c204c63a4a/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/pic/1-environment.PNG)
132 changes: 132 additions & 0 deletions 2022.04.05课后/田可欣-CV-OpenCV-20220408.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[TOC]
# CV2使用

Created: April 12, 2022 7:48 PM
上课时间: April 8, 2022

# CV2

## 图片特点

- 在cv中,图片格式为numpy ndarray

## **读入图像** cv2.imread(filepath,flags)

### 变量

- filepath:要读入图片的完整路径
- flags:读入图片的标志
- cv2.IMREAD_COLOR:默认参数,读入一副彩色图片,忽略alpha通道
- cv2.IMREAD_GRAYSCALE:读入灰度图片
- cv2.IMREAD_UNCHANGED:顾名思义,读入完整图片,包括alpha通道

### 结果数组维度

- 三维数组
- cv2.IMREAD_COLOR:彩色图片,忽略alpha通道
- cv2.IMREAD_UNCHANGED:彩色图片,包括alpha通道
- **第一个维度是高度,第二个维度是宽度,第三个维度是通道**
- 二维数组
- cv2.IMREAD_GRAYSCALE:灰度图片

## 显示

### PyCharm

```python
cv2.imshow('image',img_color)
cv2.waitKey(0)
cv2.destroyAllWindows()
```

### Jupyter Notebook

```python
# 上述代码在jupyter中运行会导致窗口内核出现问题
from matplotlib import pyplot as plt
%matplotlib inline
plt.imshow(img_gray)
plt.title('my picture')
plt.show()
```

## 保存 cv2.imwrite(file,img,num)

### 变量

- 第一个参数是要保存的**文件名**
- 第二个参数是要保存的**图像**
- 第三个参数是要保存的特定的格式
- cv2.IMWRITE_JPEG_QUALITY:对于JPEG,其表示的是**图像的质量**,用0 - 100的整数表示,默认95
- cv2.IMWRITE_PNG_COMPRESSION:对于png,第三个参数表示的是**压缩级别**,从0到9压缩级别越高图像越小,默认为3

```python
cv2.imwrite('1-jpeg-q95.png',img_color, [int( cv2.IMWRITE_JPEG_QUALITY), 95])
cv2.imwrite('1-png-c9.png',img_color, [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
```

## 翻转 cv2.flip(img,flipcode)

- flipcode = 0:沿x轴翻转,垂直翻转
- flipcode > 0:沿y轴翻转,水平翻转
- flipcode < 0:x,y轴同时翻转,水平垂直翻转

### 目的

**在机器学习时提供不同角度的模型**

## 在图片中写入文字

```python
import cv2

# 打开文件
# img=cv2.imread('1.jpg',cv2.IMREAD_COLOR)
img = cv2.imread('./mchar_train/000000.png',cv2.IMREAD_COLOR)

# 设置字体
font = cv2.FONT_HERSHEY_DUPLEX

# 图片对象、文本、 左上角像素、 字体、字体大小、颜色、 字体粗细
# imgzi = cv2.putText(img, "zhengwen", (0, 0), font, 5.5, (0, 0, 0), 2,)
imgzi = cv2.putText(img, "zhengwen", (5,50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2)

# 保存
# cv2.imshow('lena',img)
cv2.imwrite('5-zhongwen.png',imgzi) # 写磁盘
cv2.destroyAllWindows() # 毁掉所有窗口
# cv2.destroyWindow(wname) # 销毁指定窗口
```

### 图片维度

- 第一个维度是**高度**:对应图片y坐标
- 第二个维度是**宽度**:对应图片x坐标
- 第三个维度是**通道**

### 图片标注工具

[LabelImage](https://github.com/rachelcao277/LabelImage)

# Python操作

## 导入github包

```python
import sys,os

BASE_DIR = os.getcwd()# 本文件所在的绝对路径
# print(BASE_DIR)

if not BASE_DIR in sys.path:
sys.path.append(BASE_DIR)
print(sys.path)

# sys.path.append("." + "/PythonUtils")

import PythonUtils.NP.nputils as npu
```

# 图床工具

[PicGo](
76 changes: 76 additions & 0 deletions 2022.04.05课后/田可欣-CV-OpenCV-20220412.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# PyTorch

Created: April 19, 2022 12:51 AM

Materials:

- [热身:使用NumPy.ipynb](https://github.com/kk37111754/Aliyun-CV/blob/1b57d6d7fe3ce9fe542aedb87e1fa67d94b60d0e/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/Jupyter%20Notebooks/%E7%83%AD%E8%BA%AB%EF%BC%9A%E4%BD%BF%E7%94%A8NumPy.ipynb)
- [什么是PyTorch.ipynb](https://github.com/kk37111754/Aliyun-CV/blob/1b57d6d7fe3ce9fe542aedb87e1fa67d94b60d0e/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/Jupyter%20Notebooks/%E4%BB%80%E4%B9%88%E6%98%AFPyTorch.ipynb)
- [神经网络.ipynb](https://github.com/kk37111754/Aliyun-CV/blob/1b57d6d7fe3ce9fe542aedb87e1fa67d94b60d0e/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/Jupyter%20Notebooks/%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C.ipynb)

上课时间: April 12, 2022

# python库关系

以**numpy**为根源,发展出多个方向

## 数据分析

- pandas
- ploty
- matplotlib

## 算法

- PyTorch
- TensorFlow

# 使用GPU运行

## Colab — Google

![Colab-GPU.png](https://github.com/kk37111754/Aliyun-CV/blob/1b57d6d7fe3ce9fe542aedb87e1fa67d94b60d0e/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/pic/3-colab.png)

# PyTorch

## Tensor 张量

`Tensor`(张量)类似于`NumPy`的`ndarray`,但还可以在GPU上使用来加速计算。

### cuda

- 判断是否运行在显卡GPU模式下
- `if torch.cuda.is_available():`
- 每句代码后的option中添加`device = device`代表在GPU中运行

# 常见缩写

## 库

| Original | 缩写 |
| ----------------- | ---- |
| numpy | np |
| pandas | pd |
| matplotlib.pyplot | plt |
| seaborn | sns |

## 代码

| 缩写 | 含义 |
| ----- | ---------- |
| N | 批大小 |
| D_in | 输入维度 |
| D_out | 输出维度 |
| H | 隐藏层维度 |
| grad | 梯度 |

# 机器学习特点

## 习得

学习自己就能获得

## 自动

- 自动学习
- 自动识别
13 changes: 13 additions & 0 deletions 2022.04.05课后/田可欣-CV-OpenCV-20220415.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# CNN 卷积神经网络

Created: April 20, 2022 2:17 AM

Materials:

[CNN 引入.pdf](https://github.com/kk37111754/Aliyun-CV/blob/7fc3a6e8d0aad98787cac5a44ec610a5a68fb26d/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/PDF%20Files/CNN%20%E5%BC%95%E5%85%A5.pdf)

上课时间: April 15, 2022

笔记内容:

![CNN markdown](https://github.com/kk37111754/Aliyun-CV/blob/7fc3a6e8d0aad98787cac5a44ec610a5a68fb26d/2022.04.05%E8%AF%BE%E5%90%8E/%E7%94%B0%E5%8F%AF%E6%AC%A3-%E8%B5%84%E6%96%99/pic/4-CNN.jpg)
Loading