TurboWarp-Camera-Calibration

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

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:

GuidanceMeaning
show-the-boardNothing is visible
wrong-boardMarkers are visible but fewer than six corners of the selected board: another board, or the right one at an unreadable angle
hold-steadierThe view is blurred
move-or-tiltThe view is too much like one already kept
tilt-moreThe kept views are not tilted enough to solve from
keep-goingThe background solve cannot reproduce even its own samples yet
vary-moreIt reproduces its own samples but not the held-back ones: the views are too alike
solving, completeWorking, or done

The person holding the board is often not looking at the screen. Three reporters are meant for continuous cues such as sounds:

Getting a usable result

Do thisWhy
Solve by hand from at least 8 accepted samples; automatic capture collects 12 or more and holds about a fifth backFewer 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 samplesViews 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 cornersDistortion 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 momentA blurred view is refused
Do not change resolution, camera device, mirroring, resize mode, focus, or zoom during a sessionThe 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 projectorsKeystone 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

BlockTypeDoes
start camera [CAMERA_ID] calibration [CALIBRATION_ID] board [COLUMNS] by [ROWS] square [SQUARE_METERS] m marker [MARKER_METERS] m max error [MAX_ERROR_PX] pxCommandLeases one shared camera and fixes its real capture resolution and conditions for a session
add calibration sample for camera [CAMERA_ID]CommandDetects the board in the current frame and keeps it when quality and novelty pass
start automatic calibration capture for camera [CAMERA_ID]CommandHands the shutter to the extension, which also solves and finishes the session
stop automatic calibration capture for camera [CAMERA_ID]CommandHands the shutter back; the session and its samples stay
automatic capture running for camera [CAMERA_ID]?BooleanWhether the shutter is still watching that camera
camera calibration guidance [CAMERA_ID]ReporterWhat the operator should do next
camera calibration novelty [CAMERA_ID]ReporterHow much the current view would add, 0 to 1
camera calibration tilt direction [CAMERA_ID]ReporterWhich way to turn the board next
camera calibration progress [CAMERA_ID]ReporterHow far the session has come, 0 to 16
solve calibration for camera [CAMERA_ID]CommandSolves the intrinsics from at least eight samples and releases the lease
cancel calibration for camera [CAMERA_ID]CommandReleases the lease and the samples, keeping the last validated profile
cleanup calibration for camera [CAMERA_ID]CommandAlso clears the in-memory profile for that camera
publish calibration profile for camera [CAMERA_ID]CommandRegisters 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]CommandMeasures where a board that has stopped moving is, in the calibrated camera's frame
import calibration profile [JSON] for camera [CAMERA_ID]CommandImports 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]?BooleanValidates a profile without replacing the stored one
camera [CAMERA_ID] calibration ready?BooleanWhether the session can accept a sample or a solve
camera calibration state [CAMERA_ID]Reporteridle, acquiring-camera, sampling, ready, solving, solved, cancelling, or error
camera calibration backendReporterThe pinned solver identifier
camera [CAMERA_ID] calibration sample countReporterAccepted samples in the current or last solved session
camera [CAMERA_ID] calibration sample qualityReporterThe latest accepted sample's score, from zero to one
camera [CAMERA_ID] calibration reprojection error pxReporterRMS reprojection error of the latest solve or imported profile
camera [CAMERA_ID] calibration pose spreadReporterHow varied the angles of the samples are; zero cannot be solved from
camera [CAMERA_ID] calibration holdout error pxReporterRMS reprojection error over the samples the solve was not fitted to
camera [CAMERA_ID] calibration holdout sample countReporterHow many samples were held back; zero means nothing was validated
camera [CAMERA_ID] calibration error codeReporterA stable code, or an empty string
camera [CAMERA_ID] calibration errorReporterThe detailed diagnostic
camera [CAMERA_ID] calibration profile JSONReporterThe stored intrinsic profile, or an empty string
camera [CAMERA_ID] board pose JSONReporterThe last measured board pose, or an empty string

Error codes

CodeMeaning
dependency-missingCamera Source is not loaded
api-version-mismatchCamera Source has no profile registry, or speaks another contract version
invalid-boardThe board size, square or marker size, or error limit is out of range
camera-unavailableCamera Source refused the lease
camera-endedThe camera stopped or the device disappeared
resolution-mismatchThe capture resolution changed after the session started
capture-condition-mismatchThe 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-foundNo markers and fewer than six corners of the board were visible
wrong-boardMarkers were visible but formed fewer than six corners of the selected board
sample-low-qualityThe board was too small in frame, or too blurred
sample-too-similarThe view is too close to one already kept
sample-limitForty samples are already retained (by hand only; automatic capture replaces one instead)
sample-insufficientFewer than eight samples have been accepted
sample-poses-degenerateThe samples were never tilted enough to separate focal length from distance
sample-failed, solve-failedThe solver itself failed
reprojection-too-highThe solve exceeded the session's error limit
invalid-calibrationThe profile does not match the schema
credential-forbiddenThe profile carries a pairing credential
calibration-not-applicableThe profile belongs to another camera or another capture size
not-calibratedThere is no profile to publish, or to measure a board pose with
board-pose-unavailableToo little of the board was in view to measure its pose
publish-failedCamera 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

PackageOwns
@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.

TurboWarp-Camera-Calibration: complete block reference

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault
CALIBRATION_IDSTRINGcalibration-1
COLUMNSNUMBER9
ROWSNUMBER6
SQUARE_METERSNUMBER0.025
MARKER_METERSNUMBER0.018
MAX_ERROR_PXNUMBER1.5

COLUMNS・ROWS・SQUARE_METERS・MARKER_METERS・MAX_ERROR_PXを固定フォームで編集します。数値は有限数値の完全なJSON表記を使用し、範囲と静的な関連入力を検証します。enumは既知候補から選択します。未変更の空白・大小文字・数値表記は原文を保持し、reporterは評価しません。対象外の入力は変更しません。COLUMNS/ROWSのmarker数は辞書50件以内、0

add calibration sample for camera [CAMERA_ID]

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault
COLUMNSNUMBER9
ROWSNUMBER6
SQUARE_METERSNUMBER0.025
MARKER_METERSNUMBER0.018
SCALE_SOURCESTRINGnominal

COLUMNS・ROWS・SQUARE_METERS・MARKER_METERS・SCALE_SOURCEを固定フォームで編集します。数値は有限数値の完全なJSON表記を使用し、範囲と静的な関連入力を検証します。enumは既知候補から選択します。未変更の空白・大小文字・数値表記は原文を保持し、reporterは評価しません。対象外の入力は変更しません。COLUMNS/ROWSのmarker数は辞書50件以内、0

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

ArgumentTypeDefault valueMenu choices
JSONSTRING{}
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
JSONSTRING{}
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

camera [CAMERA_ID] calibration error

Returns the detailed calibration diagnostic for that camera.

Block type: REPORTER. Opcode: cameraCalibrationError. Permanent link

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

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

ArgumentTypeDefault valueMenu choices
CAMERA_IDSTRINGdefault

Repository guide and examples