-
Notifications
You must be signed in to change notification settings - Fork 20
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
8071d19
2aee370
0c76369
c971a84
6f4446c
0d04071
298ed62
546ae82
d97349b
d7f738a
a835960
a987c47
753a833
dd00af0
40fbe23
a81c6f6
a1f545b
727bc28
e7e7f24
42347a8
86fb0a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,9 @@ struct arController { | |
|
||
KpmHandle* kpmHandle; | ||
AR2HandleT* ar2Handle; | ||
ARFilterTransMatInfo *ftmi; | ||
ARdouble filterCutoffFrequency = 25.0; | ||
ARdouble filterSampleRate = 50.0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also filterSampleRate |
||
|
||
int detectedPage = -2; // -2 Tracking not inited, -1 tracking inited OK, >= 0 tracking online on page. | ||
|
||
|
@@ -96,6 +99,14 @@ extern "C" { | |
NFT API bindings | ||
*/ | ||
|
||
void matrixLerp(ARdouble src[3][4], ARdouble dst[3][4], float interpolationFactor) { | ||
kalwalt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (int i=0; i<3; i++) { | ||
for (int j=0; j<4; j++) { | ||
dst[i][j] = dst[i][j] + (src[i][j] - dst[i][j]) / interpolationFactor; | ||
} | ||
} | ||
} | ||
|
||
int getNFTMarkerInfo(int id, int markerIndex) { | ||
if (arControllers.find(id) == arControllers.end()) { return ARCONTROLLER_NOT_FOUND; } | ||
arController *arc = &(arControllers[id]); | ||
|
@@ -108,10 +119,14 @@ extern "C" { | |
int kpmResultNum = -1; | ||
|
||
float trans[3][4]; | ||
ARdouble transF[3][4]; | ||
ARdouble transFLerp[3][4]; | ||
memset( transFLerp, 0, 3 * 4 * sizeof(ARdouble) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this is not needed but not sure of this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is needed, without it the interpolation give weird results. |
||
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++ ) { | ||
|
@@ -139,6 +154,25 @@ 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]; | ||
} | ||
} | ||
|
||
bool reset; | ||
if (trackResult < 0) { | ||
reset = 1; | ||
} else { | ||
reset = 0; | ||
} | ||
|
||
if (arFilterTransMat(arc->ftmi, transF, reset) < 0) { | ||
ARLOGe("arFilterTransMat error with marker %d.\n", markerIndex); | ||
} | ||
|
||
matrixLerp(transF, transFLerp, 24.0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try with another interpolationFactor, maybe 12.0 instead of 24.0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we have to try different values |
||
|
||
if( trackResult < 0 ) { | ||
ARLOGi("Tracking lost. %d\n", trackResult); | ||
arc->detectedPage = -2; | ||
|
@@ -179,20 +213,20 @@ extern "C" { | |
markerIndex, | ||
err, | ||
|
||
trans[0][0], | ||
trans[0][1], | ||
trans[0][2], | ||
trans[0][3], | ||
transFLerp[0][0], | ||
transFLerp[0][1], | ||
transFLerp[0][2], | ||
transFLerp[0][3], | ||
|
||
trans[1][0], | ||
trans[1][1], | ||
trans[1][2], | ||
trans[1][3], | ||
transFLerp[1][0], | ||
transFLerp[1][1], | ||
transFLerp[1][2], | ||
transFLerp[1][3], | ||
|
||
trans[2][0], | ||
trans[2][1], | ||
trans[2][2], | ||
trans[2][3] | ||
transFLerp[2][0], | ||
transFLerp[2][1], | ||
transFLerp[2][2], | ||
transFLerp[2][3] | ||
); | ||
} else { | ||
EM_ASM_({ | ||
|
@@ -347,6 +381,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)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<!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="../js/third_party/gpu.js/gpu-browser.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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to increase filterCutoffFrequency