MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / getProjectionMatrixCV

Function getProjectionMatrixCV

examples/helper/STG/graphics_utils.py:113–161  ·  view source on GitHub ↗

cx and cy range is -0.5 to 0.5 we use cx cy range -0.5 * 0.5

(znear, zfar, fovX, fovY, cx=0.0, cy=0.0)

Source from the content-addressed store, hash-verified

111# return P
112
113def getProjectionMatrixCV(znear, zfar, fovX, fovY, cx=0.0, cy=0.0):
114 '''
115 cx and cy range is -0.5 to 0.5
116 we use cx cy range -0.5 * 0.5
117
118 '''
119 tanHalfFovY = math.tan(fovY / 2)
120 tanHalfFovX = math.tan(fovX / 2)
121
122 top = tanHalfFovY * znear
123 bottom = -top
124 right = tanHalfFovX * znear
125 left = -right
126
127 # Adjust for off-center projection
128 deltax = (2 * tanHalfFovX * znear) * cx #
129 deltay = (2 * tanHalfFovY * znear) * cy #
130
131 left += deltax
132 right += deltax
133 top += deltay
134 bottom += deltay
135
136
137 # left -= deltax
138 # right -= deltax
139 # top -= deltay
140 # bottom -= deltay
141
142
143 # left = left(1 +cx)* znear
144 # right += cx * znear
145 # top += cy * znear
146 # bottom += cy * znear
147
148 P = torch.zeros(4, 4)
149
150 z_sign = 1.0
151
152 P[0, 0] = 2.0 * znear / (right - left)
153 P[1, 1] = 2.0 * znear / (top - bottom)
154 P[0, 2] = (right + left) / (right - left)
155 P[1, 2] = (top + bottom) / (top - bottom)
156 P[3, 2] = z_sign
157# P[2, 2] = z_sign * zfar / (zfar - znear)
158 P[2, 2] = z_sign * (zfar+znear) / (zfar - znear)
159
160 P[2, 3] = -(zfar * znear) / (zfar - znear)
161 return P
162
163
164

Callers 3

readColmapCamerasMvFunction · 0.90
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected