Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering feature #36

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
4,778 changes: 2,515 additions & 2,263 deletions build/artoolkit.debug.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions build/artoolkit.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkit_wasm.js

Large diffs are not rendered by default.

Binary file modified build/artoolkit_wasm.wasm
Binary file not shown.
41 changes: 29 additions & 12 deletions emscripten/ARToolKitJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ struct arController {

KpmHandle* kpmHandle;
AR2HandleT* ar2Handle;
ARFilterTransMatInfo *ftmi;
ARdouble filterCutoffFrequency = AR_FILTER_TRANS_MAT_CUTOFF_FREQ_DEFAULT;
ARdouble filterSampleRate = AR_FILTER_TRANS_MAT_SAMPLE_RATE_DEFAULT;

int detectedPage = -2; // -2 Tracking not inited, -1 tracking inited OK, >= 0 tracking online on page.

Expand Down Expand Up @@ -108,10 +111,12 @@ extern "C" {
int kpmResultNum = -1;

float trans[3][4];
ARdouble transF[3][4];
float err = -1;
if (arc->detectedPage == -2) {
kpmMatching( arc->kpmHandle, arc->videoLuma );
kpmGetResult( arc->kpmHandle, &kpmResult, &kpmResultNum );
arc->ftmi = arFilterTransMatInit(arc->filterSampleRate, arc->filterCutoffFrequency);
int i, j, k;
int flag = -1;
for( i = 0; i < kpmResultNum; i++ ) {
Expand Down Expand Up @@ -139,6 +144,14 @@ extern "C" {

if (arc->detectedPage >= 0) {
int trackResult = ar2TrackingMod(arc->ar2Handle, arc->surfaceSet[arc->detectedPage], arc->videoFrame, trans, &err);
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 4; k++) {
transF[j][k] = trans[j][k];
}
}
if (arFilterTransMat(arc->ftmi, transF, 1) < 0) {
Copy link
Owner Author

@kalwalt kalwalt Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The third argument of arFilterTransMat should a value that is zero or 1 as explained in the doc http://www.artoolkitx.org/artoolkit5/doc/apiref/arFilterTransMat_h/index.html#//apple_ref/c/func/arFilterTransMat
this needs to be changed.

ARLOGe("arFilterTransMat error with marker %d.\n", markerIndex);
}
if( trackResult < 0 ) {
ARLOGi("Tracking lost. %d\n", trackResult);
arc->detectedPage = -2;
Expand Down Expand Up @@ -179,20 +192,20 @@ extern "C" {
markerIndex,
err,

trans[0][0],
trans[0][1],
trans[0][2],
trans[0][3],
transF[0][0],
transF[0][1],
transF[0][2],
transF[0][3],

trans[1][0],
trans[1][1],
trans[1][2],
trans[1][3],
transF[1][0],
transF[1][1],
transF[1][2],
transF[1][3],

trans[2][0],
trans[2][1],
trans[2][2],
trans[2][3]
transF[2][0],
transF[2][1],
transF[2][2],
transF[2][3]
);
} else {
EM_ASM_({
Expand Down Expand Up @@ -347,6 +360,10 @@ extern "C" {
arPattDetach(arc->arhandle);
arDeleteHandle(arc->arhandle);
arc->arhandle = NULL;
if (arc->ftmi) {
arFilterTransMatFinal(arc->ftmi);
arc->ftmi = NULL;
}
}
if (arc->ar3DHandle != NULL) {
ar3DDeleteHandle(&(arc->ar3DHandle));
Expand Down
1 change: 1 addition & 0 deletions examples/nft_improved_worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h3>jsartoolkit5 demos with ar2Tracking</h3>
<ul>
<li><a href="threejs_worker_gltf.html">Show a 3D, animated model. Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="main_threejs_worker.html">Show a 3D sphere. Uses web worker. Has loader. Has interpolation. Asm version. (high framerate)</a></li>
<li><a href="main_threejs_filter_worker.html">Show a 3D sphere. Uses web worker. Has loader. No interpolation with filtering. Asm version. (high framerate)</a></li>
<li><a href="main_threejs_wasm_worker.html">Show a 3D sphere. Uses web worker. Has loader. Has interpolation. Uses web assembly</a></li>
<li><a href="main.html">Draw a red rectangle around the image. Single-threaded. No loader</a></li>
<li><a href="main_worker.html">Draw a red rectangle around the image. Uses web worker. No loader</a></li>
Expand Down
141 changes: 141 additions & 0 deletions examples/nft_improved_worker/main_threejs_filter_worker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>NFT marker example with a WebWorker and Three.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=1">
<link rel="stylesheet" href="../css/video-style.css">
</head>
<body class="loading">
<div id="loading" >
<img src="../Data/logo.gif"/>
<span class="loading-text">Loading, please wait</span>
</div>
<!--
==================
STATS
==================
-->

<div id="stats" class="ui stats">

<div id="stats1" class="stats-item">
<p class="stats-item-title">
Main
</p>
</div>

<div id="stats2" class="stats-item">
<p class="stats-item-title">
Worker
</p>
</div>

</div>

<!--
==================
CAMERA VIDEO & CANVAS
==================
-->

<div id="app">
<video
loop
autoplay
muted
playsinline
id="video">
</video>

<canvas id="canvas"></canvas>
</div>

<a
href="https://raw.githubusercontent.com/artoolkit/artoolkit5/master/doc/Marker%20images/pinball.jpg"
class="ui marker"
target="_blank">
🖼 Marker Image
</a>

<script src="../js/third_party/three.js/stats.min.js"></script>
<script src="../js/third_party/three.js/three.min.js"></script>
<script src="threejs_filter_worker.js"></script>

<script>

/**
* STATS
*/
var statsMain = new Stats();
statsMain.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
document.getElementById( 'stats1' ).appendChild( statsMain.dom );

var statsWorker = new Stats();
statsWorker.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
document.getElementById( 'stats2' ).appendChild( statsWorker.dom );

/**
* APP / ELEMENTS
*/
var container = document.getElementById( 'app' );
var video = document.getElementById( 'video' );
var canvas = document.getElementById( 'canvas' );

/**
* APP / VIDEO STREAM
*/

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
var hint = {
audio: false,
video: true
};
if( window.innerWidth < 800 ) {
var width = ( window.innerWidth < window.innerHeight ) ? 240 : 360;
var height = ( window.innerWidth < window.innerHeight ) ? 360 : 240;

var aspectRatio = window.innerWidth / window.innerHeight;

console.log( width, height );

hint = {
audio: false,
video: {
facingMode: 'environment',
width: { min: width, max: width }
},
};

console.log( hint );
}

navigator.mediaDevices.getUserMedia( hint ).then( function( stream ) {
video.srcObject = stream;
video.addEventListener( 'loadedmetadata', function() {
video.play();

console.log( 'video', video, video.videoWidth, video.videoHeight );

start(
container,
markers['pinball'],
video,
video.videoWidth,
video.videoHeight,
canvas,
function() {
statsMain.update()
},
function() {
statsWorker.update();
},
null
);
} );
} );
}
</script>
</body>

</html>
Loading