Calibrate a camera shared through TurboWarp-Camera-Source against a ChArUco board, and publish its intrinsic calibration profile.
Every block is available as soon as the extension is loaded; there is nothing to switch on. The solver runs on a Web Worker and is created on first use, so loading the extension costs nothing until a calibration starts.
Requirements
TurboWarp Desktop, Web, or Packager.
@kubohiroya/turbowarp-camera-source loaded first. This extension never opens a camera itself.
A ChArUco board, flat and unglossy: a chessboard with an ArUco marker inside each light square. The block arguments count inner corners, not printed squares: a 10×7 square board is 9 by 6. Supported boards are 9×6, 7×5, and 5×4 inner corners; draw them with the package's ./runtime helpers so the markers match.
The extension must run without the sandbox.
Calibrating a camera
The simplest way is to let the extension take the samples:
start shared camera [default]
start camera [default] calibration [calibration-1] board [9] by [6] square [0.025] m marker [0.018] m max error [1.5] px
start automatic calibration capture for camera [default]
repeat until <not <automatic capture running for camera [default]?>>
say (camera calibration guidance [default])
if <(camera calibration state [default]) = [solved]> then
publish calibration profile for camera [default]
Automatic capture looks at the frame every 250 ms and keeps a view only when it would be accepted. Once it has enough views it solves in the background, and it finishes the session when the error on views held back from the fit is within the limit. At 40 views it does not stop; the view most like the others makes room for the new one.
To take the samples by hand instead:
start camera [default] calibration [calibration-1] board [9] by [6] square [0.025] m marker [0.018] m max error [1.5] px
repeat until <(camera [default] calibration sample count) = 12>
add calibration sample for camera [default]
solve calibration for camera [default]
publish calibration profile for camera [default]
Each shared camera has its own session, profile, and diagnostics. Cancelling one camera never stops another consumer of the same shared camera.
Guiding the operator
During automatic capture a frame that cannot be used is not an error. camera calibration guidance says what to do instead:
Guidance
Meaning
show-the-board
Nothing is visible
wrong-board
Markers are visible but fewer than six corners of the selected board: another board, or the right one at an unreadable angle
hold-steadier
The view is blurred
move-or-tilt
The view is too much like one already kept
tilt-more
The kept views are not tilted enough to solve from
keep-going
The background solve cannot reproduce even its own samples yet
vary-more
It reproduces its own samples but not the held-back ones: the views are too alike
solving, complete
Working, or done
The person holding the board is often not looking at the screen. Three reporters are meant for continuous cues such as sounds:
camera calibration tilt direction: top-near, top-far, left-near, or right-near, whichever direction the kept views reach least.
camera calibration novelty: 0 to 1, how much the view in front of the camera would add. It is measured on tilt, so sliding the board does not raise it.
camera calibration progress: 0 to 16, four gates of four steps — enough views to solve, enough tilt among them, enough to hold some back, and an answer that holds on the held-back views. It never goes down.
Getting a usable result
Do this
Why
Solve by hand from at least 8 accepted samples; automatic capture collects 12 or more and holds about a fifth back
Fewer views leave the distortion terms under-determined, and a solve with nothing held back cannot be validated
Tilt the board roughly 20°–45° in different directions across samples
Views that are all fronto-parallel cannot separate focal length from distance. Sliding the board sideways does not help
Vary the distance and fill different parts of the frame, including the corners
Distortion is strongest away from the image center. The markers name the corners, so a board that runs off the frame still counts when at least six corners are visible
Keep the board in focus and hold it still for a moment
A blurred view is refused
Do not change resolution, camera device, mirroring, resize mode, focus, or zoom during a session
The session is fixed to the conditions it started with, and a change ends it with an error rather than a profile that does not fit the camera
Prefer a printed board or a display set to 1:1; avoid projectors
Keystone correction, oblique projection, and the projector's own lens distort the board in ways the reprojection error does not show
Compare the reprojection error with the hold-out error. A low error on the calibration samples alone does not prove the result generalizes; the two agreeing is the evidence that it does.
Blocks
Block
Type
Does
start camera [CAMERA_ID] calibration [CALIBRATION_ID] board [COLUMNS] by [ROWS] square [SQUARE_METERS] m marker [MARKER_METERS] m max error [MAX_ERROR_PX] px
Command
Leases one shared camera and fixes its real capture resolution and conditions for a session
add calibration sample for camera [CAMERA_ID]
Command
Detects the board in the current frame and keeps it when quality and novelty pass
start automatic calibration capture for camera [CAMERA_ID]
Command
Hands the shutter to the extension, which also solves and finishes the session
stop automatic calibration capture for camera [CAMERA_ID]
Command
Hands the shutter back; the session and its samples stay
automatic capture running for camera [CAMERA_ID]?
Boolean
Whether the shutter is still watching that camera
camera calibration guidance [CAMERA_ID]
Reporter
What the operator should do next
camera calibration novelty [CAMERA_ID]
Reporter
How much the current view would add, 0 to 1
camera calibration tilt direction [CAMERA_ID]
Reporter
Which way to turn the board next
camera calibration progress [CAMERA_ID]
Reporter
How far the session has come, 0 to 16
solve calibration for camera [CAMERA_ID]
Command
Solves the intrinsics from at least eight samples and releases the lease
cancel calibration for camera [CAMERA_ID]
Command
Releases the lease and the samples, keeping the last validated profile
cleanup calibration for camera [CAMERA_ID]
Command
Also clears the in-memory profile for that camera
publish calibration profile for camera [CAMERA_ID]
Command
Registers the profile with Camera Source, which owns the contract
measure camera [CAMERA_ID] board pose board [COLUMNS] by [ROWS] square [SQUARE_METERS] m marker [MARKER_METERS] m scale [SCALE_SOURCE]
Command
Measures where a board that has stopped moving is, in the calibrated camera's frame
import calibration profile [JSON] for camera [CAMERA_ID]
Command
Imports a profile after schema, credential, and applicability checks. Reads the ROS camera_info YAML file Camera Source writes, as well as JSON
calibration profile [JSON] valid for camera [CAMERA_ID]?
Boolean
Validates a profile without replacing the stored one
camera [CAMERA_ID] calibration ready?
Boolean
Whether the session can accept a sample or a solve
camera calibration state [CAMERA_ID]
Reporter
idle, acquiring-camera, sampling, ready, solving, solved, cancelling, or error
camera calibration backend
Reporter
The pinned solver identifier
camera [CAMERA_ID] calibration sample count
Reporter
Accepted samples in the current or last solved session
camera [CAMERA_ID] calibration sample quality
Reporter
The latest accepted sample's score, from zero to one
camera [CAMERA_ID] calibration reprojection error px
Reporter
RMS reprojection error of the latest solve or imported profile
camera [CAMERA_ID] calibration pose spread
Reporter
How varied the angles of the samples are; zero cannot be solved from
camera [CAMERA_ID] calibration holdout error px
Reporter
RMS reprojection error over the samples the solve was not fitted to
camera [CAMERA_ID] calibration holdout sample count
Reporter
How many samples were held back; zero means nothing was validated
camera [CAMERA_ID] calibration error code
Reporter
A stable code, or an empty string
camera [CAMERA_ID] calibration error
Reporter
The detailed diagnostic
camera [CAMERA_ID] calibration profile JSON
Reporter
The stored intrinsic profile, or an empty string
camera [CAMERA_ID] board pose JSON
Reporter
The last measured board pose, or an empty string
Error codes
Code
Meaning
dependency-missing
Camera Source is not loaded
api-version-mismatch
Camera Source has no profile registry, or speaks another contract version
invalid-board
The board size, square or marker size, or error limit is out of range
camera-unavailable
Camera Source refused the lease
camera-ended
The camera stopped or the device disappeared
resolution-mismatch
The capture resolution changed after the session started
capture-condition-mismatch
The camera device or mirroring changed after the session started, or its resize mode, zoom or focus changed before the solve. The session ends in an error rather than solved.
board-not-found
No markers and fewer than six corners of the board were visible
wrong-board
Markers were visible but formed fewer than six corners of the selected board
sample-low-quality
The board was too small in frame, or too blurred
sample-too-similar
The view is too close to one already kept
sample-limit
Forty samples are already retained (by hand only; automatic capture replaces one instead)
sample-insufficient
Fewer than eight samples have been accepted
sample-poses-degenerate
The samples were never tilted enough to separate focal length from distance
sample-failed, solve-failed
The solver itself failed
reprojection-too-high
The solve exceeded the session's error limit
invalid-calibration
The profile does not match the schema
credential-forbidden
The profile carries a pairing credential
calibration-not-applicable
The profile belongs to another camera or another capture size
not-calibrated
There is no profile to publish, or to measure a board pose with
board-pose-unavailable
Too little of the board was in view to measure its pose
publish-failed
Camera Source rejected the profile
A refused publication records its code without changing the calibration state: a solved profile stays solved.
The calibration profile
The profile is intrinsics only: an intrinsic matrix, a distortion model and its coefficients, the calibrated image size, its quality, and when it was measured. It also records the capture conditions the camera reported when the session started (resize mode, zoom, focus mode and distance, frame rate, facing mode) and the camera's own name, so Camera Source can later answer whether the profile fits the camera in front of it. A value the camera did not report is left out rather than guessed.
It never carries a world pose, and a pose that was not measured is never filled in with identity. Preview mirroring is a display concern; profile coordinates are always the unmirrored capture coordinates.
Profiles written by @kubohiroya/turbowarp-realtime-motion-capture are accepted on import; their world pose is dropped rather than reinterpreted.
Calibration files
A calibration leaves the PC as a ROS camera_info YAML file. Publish the profile and read Camera Source's camera profile YAML for [CAMERA_ID] to write one; ROS and OpenCV-based tools read the standard part, and the capture conditions compatibility needs travel under turbowarp_camera_source. import calibration profile reads that file back through Camera Source's own reader, so it is accepted or refused for the same reasons there and here.
Board pose
A calibration needs the board to move, so where a board sits is measured separately, after calibration, once the board has stopped. The result is the board in the camera's frame, never a world pose. Its scale comes from the declared square size, so the block asks whether that size was measured with a ruler or is nominal, and records the answer. The observed corners are kept with it so a placement tool can re-solve the measurement into a shared frame.
How the packages divide the work
Package
Owns
@kubohiroya/turbowarp-camera-source
Camera acquisition, lease sharing, preview, capture conditions, and the calibration profile contract
@kubohiroya/turbowarp-camera-calibration
The calibration procedure: board drawing and detection, manual and automatic sampling, solving and hold-out validation, board pose measurement, and profile publication
Detecting a ChArUco board and solving a calibration needs OpenCV, and a TurboWarp extension ships as a single standalone bundle. Keeping the solver in its own extension lets Camera Source stay small enough for every camera consumer to load. The OpenCV inside is built for this extension to run in a Web Worker and to carry only the functions it calls; the whole extension is about 3.9 MB.
Safety
Calibration reads camera frames only to detect the board. Nothing is uploaded. A profile that carries a pairing credential is rejected rather than stored. Load unsandboxed extension code only from a source you trust.
Development
See the repository README and architecture documentation for build, test, release, and compatibility details.
All 29 blocks are documented below, including compatibility blocks and blocks available through optional features. Select a block to read its behavior, arguments, default values, and menu choices. Each block has a permanent link.
start camera [CAMERA_ID] calibration [CALIBRATION_ID] board [COLUMNS] by [ROWS] square [SQUARE_METERS] m marker [MARKER_METERS] m max error [MAX_ERROR_PX] px
Leases one shared Camera Source camera and fixes its real capture resolution and capture conditions for a ChArUco calibration session. The board is a chessboard with an ArUco marker inside each light square, so a view that runs off the frame still contributes the corners it shows. The board is measured in inner corners, not printed squares.
Block type: COMMAND. Opcode: startCameraCalibration. Permanent link
Detects the board in the current shared frame and retains it when its quality and its novelty against the retained samples both pass. The whole board need not be visible: a view that shows at least six of its corners counts, which is what lets the board reach the edges of the frame.
Block type: COMMAND. Opcode: addCameraCalibrationSample. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
start automatic calibration capture for camera [CAMERA_ID]
Watches the shared frame and retains views as the board reaches positions worth retaining, re-solving in the background as the set grows and finishing the session once the answer reproduces views it was not fitted to. Use after starting a session; a frame that cannot be used leaves guidance rather than an error.
Block type: COMMAND. Opcode: startAutomaticCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
stop automatic calibration capture for camera [CAMERA_ID]
Hands the shutter back. The session stays open with everything collected so far, so sampling and solving can continue by hand.
Block type: COMMAND. Opcode: stopAutomaticCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
automatic capture running for camera [CAMERA_ID]?
Reports whether the shutter is watching that camera on its own. It stops by itself when the session finishes, when the capture conditions change, and when the camera goes away. It does not stop at the sample limit: the retained view most like the others makes room for the new one.
Block type: BOOLEAN. Opcode: automaticCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera calibration guidance [CAMERA_ID]
Returns what the operator should do next while automatic capture runs: show-the-board, wrong-board, hold-steadier, move-or-tilt, tilt-more, keep-going, vary-more, solving, or complete. Empty when the shutter is not watching. This is not an error: most frames are declined, because most of the time the board is between two useful positions. wrong-board means markers are in frame that do not make the board being calibrated. vary-more means the answer reproduces the views it was fitted to and not the ones it was not, which more of the same views cannot fix.
Block type: REPORTER. Opcode: cameraCalibrationGuidance. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera calibration novelty [CAMERA_ID]
Returns how much the view automatic capture is looking at would add, from 0 to 1. One is a view turned as far from every retained view as the whole set is required to spread; zero means nothing usable is in frame. Measured in tilt, not in where the corners landed: sliding the board moves every corner and adds nothing a solve can use. Meant to drive something continuous -- a tone, a bar, a click rate -- because the operator is holding the board and not reading the screen.
Block type: REPORTER. Opcode: cameraCalibrationNovelty. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera calibration tilt direction [CAMERA_ID]
Returns which way the board still has to be turned: top-near, top-far, left-near, right-near, or empty outside a live session. The direction least represented in what has been collected, so that "tilt it more" -- an instruction the operator has to interpret -- becomes one they can carry out.
Block type: REPORTER. Opcode: cameraCalibrationTiltDirection. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera calibration progress [CAMERA_ID]
Returns how far the session has come, from 0 to 16. Four gates of four steps: enough views to solve from, enough tilt among them, enough views to hold some back, and the answer holding up on the views it was not fitted to. Counted in order and stopped at the first unfinished gate, so the number says which gate is being worked on as well as how far into it. Never falls. Sixteen because that is enough to sound like progress and few enough to hear as distinct.
Block type: REPORTER. Opcode: cameraCalibrationProgress. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
solve calibration for camera [CAMERA_ID]
Solves the intrinsic matrix and distortion coefficients from at least eight accepted samples, then releases the camera lease. No external pose is produced.
Block type: COMMAND. Opcode: solveCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
cancel calibration for camera [CAMERA_ID]
Releases the camera lease and the retained samples while preserving the last validated profile.
Block type: COMMAND. Opcode: cancelCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
cleanup calibration for camera [CAMERA_ID]
Releases the session and also clears the in-memory calibration profile for that camera.
Block type: COMMAND. Opcode: cleanupCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
publish calibration profile for camera [CAMERA_ID]
Registers the solved profile with Camera Source, which owns the profile contract. Reports an explicit error when Camera Source is absent, speaks another contract version, or has no profile to publish.
Block type: COMMAND. Opcode: publishCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
measure camera [CAMERA_ID] board pose board [COLUMNS] by [ROWS] square [SQUARE_METERS] m marker [MARKER_METERS] m scale [SCALE_SOURCE]
Measures where the board is, in the camera's own frame, using the calibration already solved for that camera. Take it after the board is where it will stay: a calibration needs the board to move, so while one is being collected there is no single position to report. This is not a world pose. Scale comes entirely from the square size, so say whether that was measured or nominal.
Block type: COMMAND. Opcode: measureCameraBoardPose. Permanent link
import calibration profile [JSON] for camera [CAMERA_ID]
Imports a calibration profile after schema, credential, and applicability checks. Accepts a calibration file as Camera Source writes it -- ROS camera_info YAML, or twcs/camera-intrinsics JSON -- read through Camera Source's own reader, as well as this extension's profile JSON. Pre-migration profiles are accepted and their world pose is dropped rather than reinterpreted.
Block type: COMMAND. Opcode: importCameraCalibration. Permanent link
Argument
Type
Default value
Menu choices
JSON
STRING
{}
CAMERA_ID
STRING
default
calibration profile [JSON] valid for camera [CAMERA_ID]?
Validates a profile and records why it failed, without replacing the stored profile.
Block type: BOOLEAN. Opcode: cameraCalibrationJsonValid. Permanent link
Argument
Type
Default value
Menu choices
JSON
STRING
{}
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration ready?
Reports whether a fixed-resolution session for that camera can accept a sample or solve.
Block type: BOOLEAN. Opcode: cameraCalibrationReady. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera calibration state [CAMERA_ID]
Returns the calibration session state for one shared Camera Source camera: idle, acquiring-camera, sampling, ready, solving, solved, cancelling, or error. A camera that has never been calibrated reports idle.
Block type: REPORTER. Opcode: cameraCalibrationState. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera calibration backend
Returns the pinned solver identifier. Reading it does not load the solver.
Block type: REPORTER. Opcode: cameraCalibrationBackend. Permanent link
This block has no arguments.
camera [CAMERA_ID] calibration sample count
Returns the accepted sample count for the current or last solved session.
Block type: REPORTER. Opcode: cameraCalibrationSampleCount. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration sample quality
Returns the latest accepted sample's combined board coverage and sharpness score, from zero to one.
Block type: REPORTER. Opcode: cameraCalibrationSampleQuality. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration reprojection error px
Returns the RMS reprojection error in pixels for the latest solve or imported profile.
Block type: REPORTER. Opcode: cameraCalibrationReprojectionError. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration pose spread
Returns how varied the angles of the collected samples are. Zero means every sample was taken from the same direction, which cannot be solved from: focal length and distance stay inseparable. Solving is refused below the required spread.
Block type: REPORTER. Opcode: cameraCalibrationPoseSpread. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration holdout error px
Returns the RMS reprojection error over the samples the solve was not fitted to. Compare it with the reprojection error: the two agreeing is the evidence that the calibration generalizes, and the two disagreeing says the set was too small or too alike.
Block type: REPORTER. Opcode: cameraCalibrationHoldoutErrorPx. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration holdout sample count
Returns how many samples held back from the solve were validated: the ones a pose could be solved for with its answer. Zero means nothing was validated, so the holdout error says nothing.
Block type: REPORTER. Opcode: cameraCalibrationHoldoutSampleCount. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration error code
Returns a stable code for dependency, board, camera, sample, solve, reprojection, profile, or publication errors, or an empty string.
Block type: REPORTER. Opcode: cameraCalibrationErrorCode. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration error
Returns the detailed calibration diagnostic for that camera.
Block type: REPORTER. Opcode: cameraCalibrationError. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] calibration profile JSON
Returns the stored intrinsic profile in this extension's own JSON shape, or an empty string when none exists. To write a calibration to a file or a QR code, publish it and use Camera Source's camera profile YAML, which other tools read.
Block type: REPORTER. Opcode: cameraCalibrationJson. Permanent link
Argument
Type
Default value
Menu choices
CAMERA_ID
STRING
default
camera [CAMERA_ID] board pose JSON
Returns the last measured board pose as JSON, or an empty string when none was measured. The pose is the board in the camera's frame, never a world pose, and it carries the observed corners and whether its scale was measured or nominal so it can be re-solved elsewhere.
Block type: REPORTER. Opcode: cameraBoardPoseJson. Permanent link