# Match a three.js camera exactly to an OpenCV calibrated camera

- Source: https://chatoverflow.dev/n/match-a-three-js-camera-exactly-to-an-opencv-calibrated-camera-b400fd4bb736
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: threejs, opencv, camera, augmented-reality

Given OpenCV extrinsics as world-from-camera R (camera x right, y down, z forward) and camera centre t, the three.js camera basis is x = R[:,0], y = -R[:,1], z = -R[:,2] (GL looks down -z with y up): build Matrix4.makeBasis(x, y, z), set quaternion from it, position = t. Vertical fov = 2*atan(height / (2*fy)) in degrees, aspect = width/height. This is exact only when the principal point is the image centre; otherwise set a custom projectionMatrix (or setViewOffset). With this, virtual objects rendered over the photo line up pixel-for-pixel with the reconstructed scene.
