MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / _radTanApplyDistortion

Function _radTanApplyDistortion

src/utils/cameraUndistortion.ts:271–297  ·  view source on GitHub ↗
(uu: Vec2, i: CameraIntrinsics)

Source from the content-addressed store, hash-verified

269// This differs structurally from THIN_PRISM_FISHEYE (k1–k4 only; prism on uu).
270
271function _radTanApplyDistortion(uu: Vec2, i: CameraIntrinsics): Vec2 {
272 const theta2 = uu.x * uu.x + uu.y * uu.y;
273 const theta4 = theta2 * theta2;
274 const theta6 = theta4 * theta2;
275 const theta8 = theta4 * theta4;
276 const theta10 = theta8 * theta2;
277 const theta12 = theta10 * theta2;
278 // 6-coeff radial scale
279 const thRadial = 1 + i.k1 * theta2 + i.k2 * theta4 + i.k3 * theta6
280 + i.k4 * theta8 + i.k5 * theta10 + i.k6 * theta12;
281 const x = thRadial * uu.x;
282 const y = thRadial * uu.y;
283 const x2 = x * x;
284 const y2 = y * y;
285 const xy = x * y;
286 const r2 = x2 + y2;
287 const r4 = r2 * r2;
288 // Tangential on (x, y) — COLMAP convention: i.p1 = COLMAP p0, i.p2 = COLMAP p1
289 // COLMAP: dx = 2*p1*xy + p0*(r2+2*x2), dy = 2*p0*xy + p1*(r2+2*y2)
290 // Substituting our names: dxTang = i.p1*(r2+2*x2) + 2*i.p2*xy
291 const dxTang = i.p1 * (r2 + 2 * x2) + 2 * i.p2 * xy;
292 const dyTang = 2 * i.p1 * xy + i.p2 * (r2 + 2 * y2);
293 // Thin-prism: x-direction uses sx1,sy1; y-direction uses sx2,sy2
294 const dxTp = i.sx1 * r2 + i.sy1 * r4;
295 const dyTp = i.sx2 * r2 + i.sy2 * r4;
296 return { x: x + dxTang + dxTp, y: y + dyTang + dyTp };
297}
298
299/** 2D Newton to solve `_radTanApplyDistortion(uu) = p` for `uu` (numeric Jacobian). */
300function _radTanRemoveDistortion2D(p: Vec2, i: CameraIntrinsics): Vec2 {

Callers 2

forwardFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected