forked from artoolkitx/jsartoolkit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0310e0f
commit 4229ff6
Showing
6 changed files
with
150 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<html> | ||
<body> | ||
|
||
<img id="v1" src="Data/img.jpg"></img> | ||
<img id="v2" src="Data/chalk.jpg"></img> | ||
<img id="v3" src="Data/chalk_multi.jpg"></img> | ||
<img id="v4" src="Data/kuva.jpg"></img> | ||
<img id="v5" src="Data/armchair.jpg"></img> | ||
|
||
<script type='text/javascript'> | ||
var Module = {}; | ||
|
||
function downloadWasm(url) { | ||
return new Promise(function(resolve, reject) { | ||
var wasmXHR = new XMLHttpRequest(); | ||
wasmXHR.open('GET', url, true); | ||
wasmXHR.responseType = 'arraybuffer'; | ||
wasmXHR.onload = function() { resolve(wasmXHR.response); } | ||
wasmXHR.onerror = function() { reject('error ' + wasmXHR.status); } | ||
wasmXHR.send(null); | ||
}); | ||
} | ||
|
||
// var wasm = downloadWasm('../build/artoolkit.wasm.wasm'); | ||
|
||
// Module.instantiateWasm is a user-implemented callback which the Emscripten runtime calls to perform | ||
// the WebAssembly instantiation action. The callback function will be called with two parameters, imports | ||
// and successCallback. imports is a JS object which contains all the function imports that need to be passed | ||
// to the Module when instantiating, and once instantiated, the function should call successCallback() with | ||
// the WebAssembly Instance object. | ||
// The instantiation can be performed either synchronously or asynchronously. The return value of this function | ||
// should contain the exports object of the instantiated Module, or an empty dictionary object {} if the | ||
// instantiation is performed asynchronously, or false if instantiation failed. | ||
Module.instantiateWasm = async function(imports, successCallback) { | ||
console.log('instantiateWasm: instantiating synchronously'); | ||
var wasmBinary = await downloadWasm('../build/artoolkit_wasm.wasm'); | ||
console.log('wasm download finished, begin instantiating'); | ||
try { | ||
var wasmInstantiate = await WebAssembly.instantiate(new Uint8Array(wasmBinary), imports); | ||
console.log('wasm instantiation succeeded'); | ||
Module.testWasmInstantiationSucceeded = 1; | ||
successCallback(wasmInstantiate.instance); | ||
} catch(e) { | ||
console.log('wasm instantiation failed! ' + e); | ||
return false; | ||
} | ||
return {}; // Module has no exports. | ||
} | ||
if(!window.Module) { | ||
window.Module = Module; | ||
} | ||
// var script = document.createElement('script'); | ||
// script.src = "../build/artoolkit.wasm.js"; | ||
// document.body.appendChild(script); | ||
</script> | ||
<script src="../build/artoolkit_wasm.js"></script> | ||
|
||
<script> | ||
|
||
window.addEventListener('artoolkit-loaded', () => { | ||
var cameraParam = new ARCameraParam(); | ||
|
||
var ar1, ar2, ar3, ar4, ar5; | ||
|
||
cameraParam.onload = function() { | ||
ar1 = new ARController(v1, cameraParam); | ||
ar1.debugSetup(); | ||
|
||
ar2 = new ARController(v2, cameraParam); | ||
ar2.debugSetup(); | ||
|
||
ar3 = new ARController(v3, cameraParam); | ||
ar3.debugSetup(); | ||
ar3.process(); | ||
|
||
ar4 = new ARController(v4, cameraParam); | ||
ar4.debugSetup(); | ||
ar4.process(); | ||
|
||
ar5 = new ARController(v5, cameraParam); | ||
|
||
ar1.detectMarker(); | ||
ar1.debugDraw(); | ||
ar2.detectMarker(); | ||
ar2.debugDraw(); | ||
|
||
ar5.debugSetup(); | ||
ar5.detectMarker(); | ||
ar5.debugDraw(); | ||
|
||
var assertEq = function(message, value, shouldBe) { | ||
if (value !== shouldBe) { | ||
throw(message + ' ' + value + ' is not the expected ' + shouldBe); | ||
} | ||
}; | ||
|
||
ar5.setMarkerInfoDir(0, 1); | ||
assertEq('dir changed to 1', ar5.getMarker(0).dir, 1); | ||
ar5.setMarkerInfoDir(0, 2); | ||
assertEq('dir changed to 2', ar5.getMarker(0).dir, 2); | ||
|
||
// Test setter/getter pairs | ||
var methods = "DebugMode LogLevel ProjectionNearPlane ProjectionFarPlane ThresholdMode Threshold PatternDetectionMode PattRatio MatrixCodeType LabelingMode ImageProcMode".split(" "); | ||
for (var i=0; i<methods.length; i++) { | ||
var m = methods[i]; | ||
var v = ar5['get'+m](); | ||
var nv = v === 1 ? 0 : ((v < 1 && v > 0) ? 0.7848 : 1); | ||
ar5['set'+m](nv); | ||
assertEq(m + ' changed', ar5['get'+m](), nv); | ||
ar5['set'+m](v); | ||
assertEq(m + ' changed back', ar5['get'+m](), v); | ||
} | ||
console.log("Setter/Getter tests run successfully."); | ||
}; | ||
|
||
cameraParam.load('Data/camera_para.dat'); | ||
}); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters