-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhcaculate.py
69 lines (61 loc) · 1.41 KB
/
hcaculate.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
# -*- coding: utf-8 -*-
# @Time : 2021/06/11 10:09
# @Author : yunshan
# @File : hcaculate.py
import cv2
import numpy as np
import rrcvutils
top_points = np.array(
[
[371, 439],
[1207, 377],
[2157, 404],
[2183, 966],
[1322, 1024],
[315, 1000],
[365, 1605],
[1335, 1652],
[2150, 1586],
]
)
bot_points = np.array(
[
[455, 1509],
[1148, 1561],
[1938, 1542],
[1962, 1075],
[1245, 1024],
[409, 1042],
[451, 539],
[1258, 502],
[1936, 559],
]
)
# 计算两个平面的转换矩阵
# Homography 是一个3*3的变换矩阵,将一张图中的点映射到另一张图中对应的点
result_H, status = cv2.findHomography(srcPoints=top_points, dstPoints=bot_points)
print(result_H)
# 验证
rep_bot_points = rrcvutils.project_pts(top_points.T, result_H)
h = rep_bot_points.T - bot_points
print(h)
"""
九个点对的变换矩阵
1 2 3
6 5 4
7 8 9
result_H:
[[ 8.28625828e-01 6.12449060e-04 1.46553810e+02]
[ 1.68468357e-03 -8.31006218e-01 1.87093418e+03]
[-6.50402462e-07 -1.41868511e-06 1.00000000e+00]]
验证结果:
[[-0.36428833 -0.94946289]
[ 0.4519043 0.73950195]
[-0.02331543 -0.11157227]
[-0.49121094 -0.14099121]
[ 0.5045166 0.58032227]
[-0.15283203 0.15063477]
[ 0.11950684 0.13970947]
[-0.17895508 -0.02670288]
[ 0.13452148 -0.38153076]]
"""