Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/webarkit_ES6_wasm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/webarkit_ES6_wasm.simd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/WebARKit.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions emscripten/WebARKitJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,11 @@ emscripten::val WebARKit::getCorners() {

bool WebARKit::isValid() { return manager.isValid(); }

// Load real camera calibration from a camera_para.dat buffer (a JS Uint8Array).
// Call after construction and before reading getCameraProjectionMatrix().
bool WebARKit::loadCameraParam(emscripten::val data_buffer) {
auto u8 = emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
return manager.getTracker()->loadCameraParam(u8.data(), (int)u8.size());
}

#include "bindings.cpp"
1 change: 1 addition & 0 deletions emscripten/WebARKitJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class WebARKit {
emscripten::val getGLViewMatrix();
emscripten::val getCameraProjectionMatrix();
emscripten::val getCorners();
bool loadCameraParam(emscripten::val data_buffer);
bool isValid();

private:
Expand Down
1 change: 1 addition & 0 deletions emscripten/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ EMSCRIPTEN_BINDINGS(constant_bindings) {
.function("getTransformationMatrix", &WebARKit::getTransformationMatrix)
.function("getCameraProjectionMatrix", &WebARKit::getCameraProjectionMatrix)
.function("getCorners", &WebARKit::getCorners)
.function("loadCameraParam", &WebARKit::loadCameraParam)
.function("isValid", &WebARKit::isValid);
};
Binary file added examples/data/camera_para.dat
Binary file not shown.
12 changes: 11 additions & 1 deletion examples/threejs_static_image_worker_ES6.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ function start(markerUrl, image, input_width, input_height, render_update, track
// Decode the marker JPEG into RGBA pixels with a 2D canvas. The tracker's
// initTrackerGray() treats the buffer as raw pixels (no JPEG decode), so we
// must hand it decoded data, not the compressed file bytes.
// Optional real camera calibration: fetch camera_para.dat in parallel.
// If absent (404) we fall back to the synthetic FOV camera. Returns a
// Uint8Array of the file bytes, or null.
const cameraParaPromise = fetch('data/camera_para.dat')
.then(r => (r.ok ? r.arrayBuffer() : null))
.then(buf => (buf ? new Uint8Array(buf) : null))
.catch(() => null);

const loadMarker = (URL) => {
const markerImg = new Image();
markerImg.onload = () => {
markerImg.onload = async () => {
const mw = markerImg.naturalWidth;
const mh = markerImg.naturalHeight;
const markerCanvas = document.createElement('canvas');
Expand All @@ -113,6 +121,7 @@ function start(markerUrl, image, input_width, input_height, render_update, track
const markerCtx = markerCanvas.getContext('2d', {willReadFrequently: true});
markerCtx.drawImage(markerImg, 0, 0, mw, mh);
const markerData = markerCtx.getImageData(0, 0, mw, mh);
const cameraPara = await cameraParaPromise; // Uint8Array or null
worker.postMessage({
type: "initTracker",
trackerType: type,
Expand All @@ -121,6 +130,7 @@ function start(markerUrl, image, input_width, input_height, render_update, track
imgHeight: mh,
videoWidth: vw,
videoHeight: vh,
cameraPara: cameraPara,
});
};
markerImg.src = URL;
Expand Down
7 changes: 7 additions & 0 deletions examples/worker_threejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function initTracker(msg) {
// Allocate the persistent WASM frame buffer once — avoids convertJSArrayToNumberVector on every frame.
wark.initFrameBuffer(WebARKit.WebARKitController.RGBA);

// Optional: override the synthetic FOV camera with real calibration from a
// camera_para.dat (Uint8Array) before the projection matrix is read.
if (msg.cameraPara) {
const ok = wark.loadCameraParam(msg.cameraPara);
console.log('loadCameraParam:', ok ? 'real camera_para.dat loaded' : 'FAILED (using default camera)');
}

const cameraProjMat = wark.getCameraProjectionMatrix();
console.log("camera proj Mat: ", cameraProjMat);

Expand Down
11 changes: 11 additions & 0 deletions src/WebARKitController.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ export default class WebARKitController {
return this.webarkit.initTrackerGray(imgData, width, height, trackerType);
}

/**
* Override the synthetic FOV-based camera with real calibration from an
* ArtoolkitX camera_para.dat file. Pass a Uint8Array of the file's bytes.
* Call after init_raw and before reading getCameraProjectionMatrix().
* @param {Uint8Array} buffer the camera_para.dat bytes
* @return {boolean} true if the parameters were loaded successfully
*/
loadCameraParam(buffer) {
return this.webarkit.loadCameraParam(buffer);
}

initFrameBuffer(colorSpace) {
this.webarkit.initFrameBuffer(colorSpace);
this._frameBufferPtr = this.webarkit.getFrameBufferPtr();
Expand Down
9 changes: 8 additions & 1 deletion tools/makem.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ var webarkit_sources = [
'WebARKitOpticalTracking/TrackingPointSelector.cpp',
'WebARKitOpticalTracking/WebARKitHomographyInfo.cpp',
'WebARKitOpticalTracking/WebARKitTracker.cpp',
'WebARKitOpticalTracking/WebARKitConfig.cpp'
'WebARKitOpticalTracking/WebARKitConfig.cpp',
// ArtoolkitX camera_para.dat (ARParam) loading — minimal set (WebARKitLib#35
// follow-up). paramFile.c is self-contained (arParamVersionInfo[], byteswap,
// paramdtof are internal); paramChangeSize.c is pure arithmetic; log.c
// provides arLog() for the ARLOG* macros.
'../../lib/SRC/AR/paramFile.c',
'../../lib/SRC/AR/paramChangeSize.c',
'../../lib/SRC/ARUtil/log.c'
].map(function (src) {
return path.resolve(__dirname, WEBARKITLIB_ROOT + '/WebARKit/WebARKitTrackers/', src);
});
Expand Down