-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.2_image_clibration.py
95 lines (76 loc) · 2.63 KB
/
1.2_image_clibration.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import numpy as np
from tqdm import tqdm
from datetime import datetime
from pathlib import Path
from skimage.io import imread, imshow
import matplotlib.pyplot as plt
from skimage import transform
def show_cmp_img(original_img, transform_img):
plt.rcParams["font.sans-serif"] = ["Palatino Linotype", "times new roman"]
plt.rcParams['axes.unicode_minus'] = False
# label字体大小
plt.rcParams['font.size'] = 8
# label位置靠右
plt.rcParams['legend.loc'] = 'upper right'
# 分辨率
plt.rcParams['figure.dpi'] = 500
# 大小
plt.rcParams['figure.figsize'] = (4, 4)
_, axes = plt.subplots(1, 2)
axes[0].imshow(original_img)
axes[1].imshow(transform_img)
axes[0].set_title("original image")
axes[1].set_title("transform image")
plt.show()
def main():
image_path = './dataset/RiverIceFixedCamera/3/4/3_4_30700.jpg'
save_path = './dataset'
image = imread(image_path)
# Source points
src = np.array([270, 130, # top left
0, 660, # bottom left
685, 125, # top right
960, 660]).reshape((4, 2)) # bottom right
# Destination points
dst = np.array([
[400, 500], # top left
[400, 2000], # bottom left
[600, 500], # top right
[600, 2000], # bottom right
])
tform = transform.estimate_transform('projective', src, dst)
print(tform)
tf_img = transform.warp(image, tform.inverse, output_shape=(2000, 1000))
# fig, ax = plt.subplots(figsize=(20, 20))
# ax.imshow(tf_img)
# _ = ax.set_title('projective transformation')
plt.rcParams["font.sans-serif"] = ["Palatino Linotype", "times new roman"]
plt.rcParams['axes.unicode_minus'] = False
# label字体大小
plt.rcParams['font.size'] = 8
# label位置靠右
plt.rcParams['legend.loc'] = 'upper right'
# 分辨率
plt.rcParams['figure.dpi'] = 500
# 大小
plt.rcParams['figure.figsize'] = (4, 4)
plt.xlabel('x/m')
plt.ylabel('y/m')
# show_cmp_img(image, tf_img)
fig, ax = plt.subplots(figsize=(3.5, 3.5))
ax.imshow(tf_img)
_ = ax.set_title('Projective Transform')
plt.savefig(os.path.join(save_path, os.path.basename(image_path)))
# image_path = 'd:/aa.png'
#
# image = imread(image_path)
#
# fig, ax = plt.subplots(figsize=(4, 4))
# ax.imshow(image)
# _ = ax.set_title('Original Image')
# plt.xlabel('x/pixel')
# plt.ylabel('y/pixel')
# plt.savefig(os.path.join(save_path, os.path.basename(image_path)))
if __name__ == '__main__':
main()