Skip to content

Tracear

The core tracker. Import from the package root:

ts
import { Tracear } from "@tracear/sdk";

Tracear.create(config)

ts
static async create(config: TracearConfig): Promise<Tracear>

Fetches/compiles nothing — it loads the given .tracear targets, boots the tracking worker, and resolves when the engine is ready. Does not touch the camera yet.

TracearConfig

FieldTypeDefaultDescription
containerHTMLElementElement the managed <video> is appended to. Position it yourself (e.g. position: relative).
targets(string | ArrayBuffer | Uint8Array)[]Compiled .tracear targets: URLs or raw bytes. A file may hold one marker or a multi-marker pack; packs expand in place.
targetWidthsMetersnumber[]1 per markerPhysical width of each marker (in expanded pack order) — poses come out in the same unit.
maxProcessSizenumber640Long-side cap for the processed frame.
maxTrackednumberunlimitedCap on simultaneously tracked targets. 1 = exclusive session (like MindAR's maxTrack: 1): once a target is acquired, all other detection pauses until it is lost — cheapest and steadiest when only one target should be active at a time.
lostAfterMissesnumber8Consecutive misses before targetLost.
videoConstraintsMediaTrackConstraintsExtra getUserMedia video constraints, merged over the defaults (environment camera, 1280×720 ideal).

Methods

start()

ts
async start(): Promise<void>

Requests the camera (getUserMedia), attaches the video to container, and begins processing frames. Rejects if the user denies permission.

stop()

Stops frame processing and releases the camera. The tracker can start() again later.

dispose()

stop() plus: terminates the worker, removes the video element, clears all listeners. The instance is done after this.

on(event, callback)

ts
on<K extends keyof TracearEvents>(event: K, cb: (e: TracearEvents[K]) => void): () => void

Subscribes to an event; returns an unsubscribe function.

poseAt()

ts
poseAt(index: number, timestamp: number): Float32Array | null

The filtered pose blended and extrapolated to a render timestamp (performance.now() domain). Returns a column-major 4×4 marker-object → OpenCV-camera matrix, or null while the target isn't tracked. This is the method to render from — TracearThree calls it for you and converts to WebGL axes. See Tracking & poses.

intrinsics()

ts
intrinsics(): CameraIntrinsics | null

Latest self-calibrated pinhole intrinsics, in processed-frame pixels. null before the first result.

ts
interface CameraIntrinsics {
  fx: number; fy: number;
  cx: number; cy: number;
  width: number; height: number; // the frame size fx/cx are expressed in
}

detectImage()

ts
async detectImage(source: ImageBitmapSource): Promise<(UpdateEvent | null)[]>

One-shot detection on a still image — no camera involved, no events emitted. One entry per configured target, null where not found. Useful for marker validation and automated tests.

Properties

PropertyTypeDescription
videoHTMLVideoElementThe managed video element (created in create(), attached on start()).

Events

ts
type TracearEvents = {
  targetFound: { index: number };
  targetLost:  { index: number };
  update:      UpdateEvent;
  error:       { message: string };
};

UpdateEvent

FieldTypeDescription
indexnumberWhich target.
homographyFloat64ArrayRow-major 3×3, maps marker px → processed-frame px.
markerWidth / markerHeightnumberCompiled marker size in marker px.
trackingbooleantrue when the sub-pixel tracker produced this pose; false for full detection (first acquire / re-acquire / detectImage).
inliersnumberDetection: RANSAC inliers. Tracking: surviving patches.
matchesnumberDetection: total matches. Tracking: attempted patches.
qualitynumber0..1 confidence.
posePoseData?Filtered 6DoF pose; undefined if pose estimation failed this frame.
timestampnumberFrame capture time (performance.now() domain).
processWidth / processHeightnumberProcessed-frame size the homography maps into.
workerMsnumberCV processing time inside the worker (ms).

PoseData

Conventions: object frame origin at the marker center, X right, Y up, Z out of the marker; camera frame is OpenCV (X right, Y down, Z forward).

FieldTypeDescription
position[x, y, z]Filtered object → camera translation (physical units).
quaternion[x, y, z, w]Filtered object → camera rotation.
velocity[x, y, z]Filtered linear velocity, units/s.
angularVelocity[x, y, z]Body-frame angular velocity, rad/s.
posLagS / rotLagSnumberGroup delay (s) of the translation / rotation filter.
rawPosition / rawQuaternionThis frame's unfiltered pose: zero lag, more noise.

Released under the MIT License.