@ar-js-org/artoolkit5-js

中文文档
0.3.2发布于 2025/11/01LGPL-3.0TypeScriptCommonJS近 30 天下载 3065

ES6 module port of artoolkit5

原始使用文档
文档目录10 节
  1. Installation
  2. Browser
  3. Node.js
  4. ES6 Import
  5. Usage
  6. 1) Create controller instance
  7. 2) Add markers you want to track
  8. 3) Start tracking
  9. Other ARToolkit API methods
  10. Current limitations

@ar-js-org/artoolkit5-js

This is the artoolkit5-js fork for the AR.js project.

ES6 module port of artoolkit5. Based on the (now defunct) original Emscripten to JavaScript port and improved by Walter Perdan.

This build is uses WASM for best possible performance and is designed to be (more or less) a drop-in replacement for the previous jsartoolkit5. Some parts of the previous API have been refactored to implement an async interface instead of the previous callback based interface.

Installation

The @ar-js-org/artoolkit5-js package can be installed via NPM:

npm install @ar-js-org/artoolkit5-js

The module is built in UMD format and can be used in different environments:

Browser

<script src="/path/to/ARToolkit.js"></script>

Node.js

const ARToolkit = require('artoolkit5-js');

ES6 Import

import ARToolkit from 'artoolkit5-js';

Usage

1) Create controller instance

First you need to create an instance of ARController:

ARController.initWithDimensions(640, 480, '/data/camera_para.dat').then(controller => { ... });

This will create an ARController instance expecting source images of dimensions 640x480. The second parameter is a camera definition file which describes the characteristics of your image / video input device. If you don't know which file to use just use the default camera_para.dat included with this repository.

There is an alternative initializer initWithImage available as convenience method which accepts an HTMLImageElement or HTMLVideoElement instead of width / height. However this obviously only works in Browser (or MonkeyPatched) environments.

2) Add markers you want to track

Next you need to load the marker files to track with your controller. In this example the pattern file for the "Hiro" marker is loaded:

controller.artoolkit.addMarker(controller.id, '/data/hiro.patt').then(hiroMarkerId => { ... });

3) Start tracking

// track with 60 FPS
const FPS = 60;

setInterval(() => {

  const result = controller.detectMarker();
  if(result !== 0) {
    // ARToolkit returning a value !== 0 means an error occured
    console.log('Error detecting markers');
    return;
  }

  // get the total number of detected markers in frame
  const markerNum = controller.getMarkerNum();
  let hiroFound = false;

  // check if one of the detected markers is the "Hiro" marker
  for(let i = 0; i < markerNum; i++) {
    const markerInfo = controller.getMarker(i);
    if(markerInfo.idPatt == hiroMarkerId) {
      // store the marker ID from the detection result
      hiroFound = i;
      break;
    }
  }

  if(hiroFound !== false) {
    console.log("You have found the HIRO marker");
  }

}, 1000 / FPS);

Other ARToolkit API methods

You can access all public ARToolkit methods and class constants like this:

  // for the full API documentation see
  // https://github.com/artoolkit/artoolkit5
  artoolkit.detectMarker( ... );

  console.log(artoolkit.AR_LOG_LEVEL_DEBUG);

Current limitations

Due to time constraints this build does not implement multimarker support (yet). Adding support should be trivial though as all the groundwork has already been laid out. I will implement it once time allows but PRs are of course welcome!

版本与发布记录

@ar-js-org/artoolkit5-js 共发布 8 个版本,首次发布于 2021/04/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.2latest2025/11/011 年前
0.3.12024/11/261.9 年前
0.3.02023/01/253 年前
0.2.02022/10/294 年前
0.1.32022/02/164 年前
0.1.22021/11/184 年前

关于 @ar-js-org/artoolkit5-js 的常见问题

@ar-js-org/artoolkit5-js 是什么?

ES6 module port of artoolkit5

如何安装 @ar-js-org/artoolkit5-js?

在项目目录运行 npm install @ar-js-org/artoolkit5-js,或使用 pnpm add / yarn add / bun add。

@ar-js-org/artoolkit5-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ar-js-org/artoolkit5-js 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@ar-js-org/artoolkit5-js 可以商用吗?

@ar-js-org/artoolkit5-js 使用 LGPL-3.0 许可。弱 Copyleft:作为库被调用时通常不要求开源你自己的代码,但修改库本身需以 LGPL 开源;前端打包合并后的适用边界存在不同理解。以上为概括,不构成法律意见,请以许可原文为准。

@ar-js-org/artoolkit5-js 的下载量有多少?

根据 npm 官方下载统计,@ar-js-org/artoolkit5-js 在 2026/10/07 – 2026/11/05 这 30 天内被下载 3,065 次,日均约 102 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ar-js-org/artoolkit5-js 还在维护吗?

最新版本 0.3.2 发布于 2025/11/01(1 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。