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 2 commits
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
126 changes: 126 additions & 0 deletions emscripten/FilterNFT.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* FilterNFT.c
* //from the original file ARMarkerNFT.c in this commit:
* https://github.com/kalwalt/jsartoolkit5/commit/6eb0cabd00ae7ad99053f70640936ad61543e38e#diff-43441e657d18818bd1f722c762b8460b
*
* ARToolKit5
*
* Disclaimer: IMPORTANT: This Daqri software is supplied to you by Daqri
* LLC ("Daqri") in consideration of your agreement to the following
* terms, and your use, installation, modification or redistribution of
* this Daqri software constitutes acceptance of these terms. If you do
* not agree with these terms, please do not use, install, modify or
* redistribute this Daqri software.
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, Daqri grants you a personal, non-exclusive
* license, under Daqri's copyrights in this original Daqri software (the
* "Daqri Software"), to use, reproduce, modify and redistribute the Daqri
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the Daqri Software in its entirety and
* without modifications, you must retain this notice and the following
* text and disclaimers in all such redistributions of the Daqri Software.
* Neither the name, trademarks, service marks or logos of Daqri LLC may
* be used to endorse or promote products derived from the Daqri Software
* without specific prior written permission from Daqri. Except as
* expressly stated in this notice, no other rights or licenses, express or
* implied, are granted by Daqri herein, including but not limited to any
* patent rights that may be infringed by your derivative works or by other
* works in which the Daqri Software may be incorporated.
*
* The Daqri Software is provided by Daqri on an "AS IS" basis. DAQRI
* MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
* THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE, REGARDING THE DAQRI SOFTWARE OR ITS USE AND
* OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
*
* IN NO EVENT SHALL DAQRI BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
* MODIFICATION AND/OR DISTRIBUTION OF THE DAQRI SOFTWARE, HOWEVER CAUSED
* AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
* STRICT LIABILITY OR OTHERWISE, EVEN IF DAQRI HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2015 Daqri LLC. All Rights Reserved.
* Copyright 2013-2015 ARToolworks, Inc. All Rights Reserved.
*
* Author(s): Philip Lamb.
* Modified version by @kalwalt Walter Perdan.
*
*/

#include "FilterNFT.h"

#include <stdio.h>
#include <string.h>
#ifdef _WIN32
# include <windows.h>
# define MAXPATHLEN MAX_PATH
#else
# include <sys/param.h> // MAXPATHLEN
#endif


const ARPose ARPoseUnity = {{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};

void filterNFTWithTransMat(ARMarkerNFT **markersNFT_out, int *markersNFTCount_out, int filterValue)
{
int tempI;
ARMarkerNFT *markersNFT;
int markersNFTCount;
ARdouble tempF;
int i;

if (!markersNFT_out || !markersNFTCount_out) return;

arMallocClear(markersNFT, ARMarkerNFT, tempI);
markersNFTCount = tempI;

for (i = 0; i < markersNFTCount; i++) {
markersNFT[i].valid = markersNFT[i].validPrev = FALSE;
markersNFT[i].pageNo = -1;
if (filterValue == 0){
markersNFT[i].filterCutoffFrequency = AR_FILTER_TRANS_MAT_CUTOFF_FREQ_DEFAULT;
markersNFT[i].filterSampleRate = AR_FILTER_TRANS_MAT_SAMPLE_RATE_DEFAULT;
} else {
markersNFT[i].filterCutoffFrequency = filterValue;
}

}

// If not all markers were read, an error occurred.
if (i < markersNFTCount) {

// Clean up.
for (; i >= 0; i--) {
if (markersNFT[i].ftmi) arFilterTransMatFinal(markersNFT[i].ftmi);
}
free(markersNFT);

*markersNFTCount_out = 0;
*markersNFT_out = NULL;
return;
}

*markersNFT_out = markersNFT;

}

void deleteMarkers(ARMarkerNFT **markersNFT_p, int *markersNFTCount_p)
{
int i;

if (!markersNFT_p || !*markersNFT_p || !*markersNFTCount_p || *markersNFTCount_p < 1) return;

for (i = 0; i < *markersNFTCount_p; i++) {
if ((*markersNFT_p)[i].ftmi) {
arFilterTransMatFinal((*markersNFT_p)[i].ftmi);
(*markersNFT_p)[i].ftmi = NULL;
}
}
free(*markersNFT_p);
*markersNFT_p = NULL;
*markersNFTCount_p = 0;
}
103 changes: 103 additions & 0 deletions emscripten/FilterNFT.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* FilterNFT.c
* //from the original file ARMarkerNFT.h in this commit:
* https://github.com/kalwalt/jsartoolkit5/commit/6eb0cabd00ae7ad99053f70640936ad61543e38e#diff-43441e657d18818bd1f722c762b8460b
*
* ARToolKit5
*
* Disclaimer: IMPORTANT: This Daqri software is supplied to you by Daqri
* LLC ("Daqri") in consideration of your agreement to the following
* terms, and your use, installation, modification or redistribution of
* this Daqri software constitutes acceptance of these terms. If you do
* not agree with these terms, please do not use, install, modify or
* redistribute this Daqri software.
*
* In consideration of your agreement to abide by the following terms, and
* subject to these terms, Daqri grants you a personal, non-exclusive
* license, under Daqri's copyrights in this original Daqri software (the
* "Daqri Software"), to use, reproduce, modify and redistribute the Daqri
* Software, with or without modifications, in source and/or binary forms;
* provided that if you redistribute the Daqri Software in its entirety and
* without modifications, you must retain this notice and the following
* text and disclaimers in all such redistributions of the Daqri Software.
* Neither the name, trademarks, service marks or logos of Daqri LLC may
* be used to endorse or promote products derived from the Daqri Software
* without specific prior written permission from Daqri. Except as
* expressly stated in this notice, no other rights or licenses, express or
* implied, are granted by Daqri herein, including but not limited to any
* patent rights that may be infringed by your derivative works or by other
* works in which the Daqri Software may be incorporated.
*
* The Daqri Software is provided by Daqri on an "AS IS" basis. DAQRI
* MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
* THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE, REGARDING THE DAQRI SOFTWARE OR ITS USE AND
* OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
*
* IN NO EVENT SHALL DAQRI BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
* MODIFICATION AND/OR DISTRIBUTION OF THE DAQRI SOFTWARE, HOWEVER CAUSED
* AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
* STRICT LIABILITY OR OTHERWISE, EVEN IF DAQRI HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2015 Daqri LLC. All Rights Reserved.
* Copyright 2013-2015 ARToolworks, Inc. All Rights Reserved.
*
* Author(s): Philip Lamb.
* Modified version by @kalwalt Walter Perdan.
*
*/

#ifndef __FilterNFT_h__
#define __FilterNFT_h__

#include <AR/ar.h>
#include <AR/arFilterTransMat.h>
#ifndef _MSC_VER
# include <stdbool.h>
#else
typedef unsigned char bool;
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
ARdouble v[3];
} ARVec3;

typedef struct {
ARdouble T[16]; // Position and orientation, column-major order. (position(x,y,z) = {T[12], T[13], T[14]}
} ARPose;

extern const ARPose ARPoseUnity;

typedef struct _ARMarkerNFT {
// ARMarker protected
//bool valid;
//bool validPrev;
ARdouble trans[3][4];
ARPose pose;
ARdouble marker_width;
ARdouble marker_height;
// ARMarker private
ARFilterTransMatInfo *ftmi;
ARdouble filterCutoffFrequency;
ARdouble filterSampleRate;
// ARMarkerNFT
int pageNo;
char *datasetPathname;
} ARMarkerNFT;

void filterNFTWithTransMat(ARMarkerNFT **markersNFT_out, int *markersNFTCount_out, int filterValue);

void deleteMarkers(ARMarkerNFT **markersNFT_p, int *markersNFTCount_p);

#ifdef __cplusplus
}
#endif
#endif // !__FilterNFT_h__
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
Loading