> For the complete documentation index, see [llms.txt](https://docs-en.kivicube.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-en.kivicube.com/ar-open-service/image-tracking.md).

# Image Tracking

## Summary

Provide a Class externally, owned relative functional API.

![](/files/-MEakve0nHIkVrEW3mDJ)

## Marker Tracking

### Init

Resources required to initialize tracking.

| Parameter    | Constraint | Available value      | Introduction                          |
| ------------ | ---------- | -------------------- | ------------------------------------- |
| Track Width  | Required   | Int. 320, 480 or 720 | Width value of tracked image data.    |
| Track Height | Required   | Int. Arbitrary value | Width value of tracked image data.    |
| Vertical FoV | Required   | Float. Suggest 40deg | Field of view of the tracking matrix. |

Return value: Promise. Resolve presents Initialization successful, reject presents Initialization failed.

### Set Marker

Set the identification map data to be tracked.

| Parameter | Constraint | Available value | Introduction                          |
| --------- | ---------- | --------------- | ------------------------------------- |
| Marker    | Required   | Array Buffer    | Identification map data to be tracked |

Return value: marker Id: Int. Identification map Id.

### Remove All Marker

Remove all identification map data.

| Parameter | Constraint | Available value | Introduction |
| --------- | ---------- | --------------- | ------------ |
| Null      |            |                 |              |

Return value: Null

### Do Track

Track a certain camera frame.

| Parameter    | Constraint | Available value | Introduction              |
| ------------ | ---------- | --------------- | ------------------------- |
| Camera Frame | Required   | Array Buffer    | Certain camera frame data |

Return value: track Matrix: Object { tx, ty, tz, rxx, rxy, rxz, ryx, ryy, ryz, rzx, rzy, rzz, marker Id } | null.&#x20;

When return to track Matrix, it presents identification map data to be tracked; when return to null, it presents identification map data not to be tracked.

## Sample Code

```
const markerTracking = new MarkerTracking();

const trackWidth = 320;
const trackHeight = 320 / (window.innerWidth / window.innerHeight);
await markerTracking.init(trackWidth, trackHeight, 40);

const markerAb = await fetch("https://domain.com/path/to/marker.marker").then(res => res.arraybuffer());
const markerId = markerTracking.setMarker(markerAb);

function getCameraFrameArrayBuffer() {
    const frame = new ArrayBuffer(trackWidth * trackHeight * 4);

    // @TODO Acquire camera frame data by yourself

    return frame;
}

function tracking() {
    const cameraFrame = getCameraFrameArrayBuffer();
    const trackInfo = markerTracking.doTrack(cameraFrame);
    if (trackInfo) {
        const matrix = new Matrix4();
        matrix.set(
            trackInfo.rxx, trackInfo.rxy, trackInfo.rxz, trackInfo.tx,
            -trackInfo.ryx, -trackInfo.ryy, -trackInfo.ryz, trackInfo.ty,
            -trackInfo.rzx, -trackInfo.rzy, -trackInfo.rzz, trackInfo.tz,
            0.0, 0.0, 0.0, 1.0);

        if (markerId === trackInfo.markerId) {
            // @TODO
        }
    }

    requestAnimationFrame(tracking);
};

tracking();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-en.kivicube.com/ar-open-service/image-tracking.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
