Camera_Parameters.js
3.26 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const PI = 3.1415926535898;
const EPS = 0.00000001;
//xyz 是指针类型
export var CalcRealCoor = function(point, invK, Objheight) {
var point_m = {
x:0,
y:0
}
var _xyz = {x:null,y:null,z:null};
point_m.x = (point.x-0.5);
point_m.y = (point.y-0.5);
_xyz.x = invK[0]*point_m.x+invK[1]*point_m.y+invK[2];
_xyz.y = invK[3]*point_m.x+invK[4]*point_m.y+invK[5];
_xyz.z = invK[6]*point_m.x+invK[7]*point_m.y+invK[8];
_xyz.x = _xyz.x/_xyz.y*Objheight;
_xyz.z = _xyz.z/_xyz.y*Objheight;
_xyz.y = Objheight;
return _xyz
}
export var CalcImgCoor = function(_point, K , xyz) {
var x_coor = K[0]*xyz.x+K[1]*xyz.y+K[2]*xyz.z;
var y_coor = K[3]*xyz.x+K[4]*xyz.y+K[5]*xyz.z;
var z_coor = K[6]*xyz.x+K[7]*xyz.y+K[8]*xyz.z;
x_coor /= z_coor;
y_coor /= z_coor;
x_coor += 0.5;
y_coor += 0.5;
_point.x = x_coor;
_point.y = y_coor;
return _point
}
export var CalcK = function(cK, fFocusX, fFocusY, fTilt, fRoll, fPan) {
var K = cK;
var theta = fTilt*PI/180,
gamma = fRoll*PI/180,
beta = fPan*PI/180,
sintheta = Math.sin(theta),
costheta = Math.cos(theta),
singamma = Math.sin(gamma),
cosgamma = Math.cos(gamma),
sinbeta = Math.sin(beta),
cosbeta = Math.cos(beta),
f_mat = [0,0,0,0,0,0,0,0,1],
theta_mat = [1,0,0,0,0,0,0,0,0],
gamma_mat = [0,0,0,0,0,0,0,0,1],
beta_mat = [0,0,0,0,1,0,0,0,0];
f_mat[0]=fFocusX;
f_mat[4]=fFocusY;
theta_mat[4]=costheta;
theta_mat[5]=-sintheta;
theta_mat[7]=sintheta;
theta_mat[8]=costheta;
gamma_mat[0]=cosgamma;
gamma_mat[1]=-singamma;
gamma_mat[3]=singamma;
gamma_mat[4]=cosgamma;
beta_mat[0]=cosbeta;
beta_mat[2]=-sinbeta;
beta_mat[6]=sinbeta;
beta_mat[8]=cosbeta;
K = Mat_Multiply(f_mat, theta_mat);
if ((fRoll > EPS)||(fRoll < -EPS))
{
K = Mat_Multiply(K, gamma_mat);
}
if ((fPan > EPS)||(fPan < -EPS))
{
K = Mat_Multiply(K, beta_mat);
}
return K
}
export var CalcInvK = function (cinvK, fFocusX, fFocusY, fTilt, fRoll, fPan) {
var InvK = cinvK,
theta = fTilt*PI/180,
gamma = fRoll*PI/180,
beta = fPan*PI/180,
sintheta = Math.sin(theta),
costheta = Math.cos(theta),
singamma = Math.sin(gamma),
cosgamma = Math.cos(gamma),
sinbeta = Math.sin(beta),
cosbeta = Math.cos(beta),
f_mat = [0,0,0,0,0,0,0,0,1],
theta_mat = [1,0,0,0,0,0,0,0,0],
gamma_mat = [0,0,0,0,0,0,0,0,1],
beta_mat = [0,0,0,0,1,0,0,0,0];
f_mat[0]= 1/fFocusX;
f_mat[4]= 1/fFocusY;
theta_mat[4]=costheta;
theta_mat[5]=sintheta;
theta_mat[7]=-sintheta;
theta_mat[8]=costheta;
gamma_mat[0]=cosgamma;
gamma_mat[1]=singamma;
gamma_mat[3]=-singamma;
gamma_mat[4]=cosgamma;
beta_mat[0]=cosbeta;
beta_mat[2]=sinbeta;
beta_mat[6]=-sinbeta;
beta_mat[8]=cosbeta;
if ((fRoll > EPS)||(fRoll < -EPS))
{
InvK = Mat_Multiply(beta_mat, gamma_mat);
InvK = Mat_Multiply(InvK, theta_mat);
InvK = Mat_Multiply(InvK, f_mat);
}
else if ((fPan > EPS)||(fPan < -EPS))
{
InvK = Mat_Multiply(beta_mat, theta_mat);
InvK = Mat_Multiply(InvK, f_mat);
}
else
{
InvK = Mat_Multiply(theta_mat, f_mat);
}
return InvK
}
function Mat_Multiply (m1, m2){
var mm = [], i, j, k,result = [];
for (var i=0;i<9;i++){
mm[i] = m1[i];
}
for (var i=0;i<3;i++) {
for (var j=0;j<3;j++){
result[i*3+j] = 0;
for (var k=0;k<3;k++){
result[i*3+j] += mm[i*3+k]*m2[k*3+j];
}
}
}
return result;
}