CV Camera Matrix
Building a camera matrix by hand
- camera_matrix
A lot of OpenCV functions want a 3×3 intrinsic matrix K - solvePnP, projectPoints, undistort, stereoRectify, initUndistortRectifyMap - and there's no way to type a 3×3 into a graph. This node exists to fix that: four numbers in, one matrix out.
[ fx 0 cx ]
K = [ 0 fy cy ]
[ 0 0 1 ]
The honest use case is "I don't have a calibration and I'm not doing one today." A rough but workable guess for a phone-ish or webcam-ish camera is fx = fy = image width with (cx, cy) at the image centre. It's wrong in the way all uncalibrated guesses are wrong, and for a lot of work - projecting a 3D box onto a marker, sanity-checking a warp - it's wrong in a way you can live with. For anything you intend to trust, calibrate: CV Calibrate Camera (ChArUco) or the chessboard node will hand you a real K and distortion coefficients alongside it.
Inputs
All four required, all FLOAT:
fx- focal length along X, in pixels. Default 1000. For a 1080p-ish frame, the frame width is a decent order-of-magnitude guess.fy- focal length along Y. Usually equal tofx; on most sensors it is.cx- principal point X, in pixels, usually image width / 2.cy- principal point Y, usually image height / 2.
Output
One: camera_matrix, a 3×3 float64 NPARRAY.
That's a real type here - NPARRAY, this pack's array socket - so it only connects to nodes that declare they take an array. Feeding it into something expecting an IMAGE or a MASK won't work, and that's by design: matrices stay matrices instead of getting smuggled through image sockets.
Where it goes: CV ArUco Board Pose (Average) for a board pose with an approximate camera, CV Camera Pose To 3D View to drive a 3D preview camera, any of the pack's raw cv2.* wrappers that take cameraMatrix, or a pose solve. If you're doing this honestly, use K from a calibration node instead and keep this one for prototyping - swapping in the real matrix later is a one-wire change.
Install
Manager → ComfyUI CV, or:
cd ComfyUI/custom_nodes && git clone https://github.com/bmad4ever/comfyui_cv
pip install "opencv-contrib-python-headless~=5.0.0.93"
Python ≥ 3.12, recent ComfyUI on the V3 API. Nothing to download, no models - this node is four floats and a np.array.
Where people get burned
Units, again. fx and fy are in pixels, and cx/cy are in pixels of the image you're actually passing downstream. A matrix built for a 1024×1024 image and then used on a 512px downscaled copy places the principal point at twice the offset it should have - every projection is skewed in a way that's easy to blame on the pose node.
Focal length is not a property of the lens alone. It depends on the pixel pitch too, which is why "my camera is 35mm equivalent" tells you nothing usable here. If you're guessing, guess from the image width; if you need better, calibrate. There is no third option that's worth the time.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| fx | FLOAT | 1000.000.001–10000000 | Focal length along X in pixels. |
| fy | FLOAT | 1000.000.001–10000000 | Focal length along Y in pixels (usually = fx). |
| cx | FLOAT | 320.00-1000000–1000000 | Principal point X in pixels (usually image width / 2). |
| cy | FLOAT | 240.00-1000000–1000000 | Principal point Y in pixels (usually image height / 2). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| camera_matrix | NPARRAY | 3x3 float64 intrinsic matrix K. |