-
Notifications
You must be signed in to change notification settings - Fork 0
/
imutils_use.py
81 lines (71 loc) · 2.01 KB
/
imutils_use.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import numpy as np
import cv2 as cv
import imutils
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 平移图像
def translate():
img = cv.imread('./img/matou.png')
translated = imutils.translate(img, 100, 50)
plt.figure()
plt.subplot(121)
plt.imshow(img[:,:,::-1])
plt.title('原图')
plt.subplot(122)
plt.imshow(translated[:,:,::-1])
plt.title('平移')
plt.show()
# 缩放图像,会自动根据指定宽或高自动缩放
def resize():
img = cv.imread('./img/matou.png')
resize = imutils.resize(img, width=200)
plt.figure()
plt.subplot(121)
plt.imshow(img[:,:,::-1])
plt.title('原图')
plt.subplot(122)
plt.imshow(resize[:,:,::-1])
plt.title('缩放')
plt.show()
# 旋转
def rotated():
img = cv.imread('./img/matou.png')
rotated = imutils.rotate(img, 90)
rotated_round = imutils.rotate_bound(img, 90)
plt.figure()
plt.subplot(131)
plt.imshow(img[:,:,::-1])
plt.title('原图')
plt.subplot(132)
plt.imshow(rotated[:,:,::-1])
plt.title('逆时针')
plt.subplot(133)
plt.imshow(rotated_round[:,:,::-1])
plt.title('正时针')
plt.show()
# 骨架图
def skeletonize():
img = cv.imread('./img/matou.png')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
skeleton = imutils.skeletonize(gray, size=(7, 7))
plt.figure()
plt.subplot(131)
plt.imshow(img[:,:,::-1])
plt.title('原图')
plt.subplot(132)
plt.imshow(skeleton, cmap="gray")
plt.title('骨架图')
plt.show()
if __name__ == '__main__':
img = cv.imread('./img/matou.png')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
skeleton = imutils.skeletonize(gray, size=(7, 7))
plt.figure()
plt.subplot(131)
plt.imshow(img[:,:,::-1])
plt.title('原图')
plt.subplot(132)
plt.imshow(skeleton, cmap="gray")
plt.title('骨架图')
plt.show()