Repository navigation
feat(nft): move NFT tracking helpers from jsartoolkitNFT into WebARKitNFT (#75) #76
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f50e32f
feat(nft): import NFT tracking helpers from jsartoolkitNFT (#75)
kalwalt 1056044
fix(nft): make WebARKitNFT helpers build outside emscripten (#75)
kalwalt 98b0de1
build(nft): add WEBARKIT_BUILD_NFT CMake option and WebARKitNFT targe…
kalwalt 67feabb
fix(nft): return -1 from markerDecompress on errors instead of exit()
kalwalt d913c02
fix(nft): initialise icpHandle and cparamLT in ar2CreateHandleSubMod
kalwalt 95f3621
fix(kpm): add missing <limits> and <unordered_map> includes
kalwalt 8e22806
test(nft): add WebARKitNFT gtest suite and run it in CI (#75)
kalwalt 32366bc
docs: document the WebARKitNFT helpers and CMake options (#75)
kalwalt 99a2689
fix(nft): always build ARUtil thread helpers in WebARKitNFT
kalwalt fbb89d8
fix(nft): harden markerDecompress against malformed and large .zft files
kalwalt 480fdb9
fix(nft): guard trackingSub against overlapping scans and failed init
kalwalt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,94 @@ | ||
| # WebARKitNFT: NFT tracking helpers (trackingMod, markerDecompress, trackingSub) | ||
| # plus the ARToolKit sources they need (AR, ARICP, AR2, KPM, ARUtil). | ||
| # The source lists mirror jsartoolkitNFT/tools/makem.js. No OpenCV dependency. | ||
|
|
||
| option(WEBARKIT_NFT_THREADS "Build the threaded KPM worker (trackingSub); on Emscripten also enables -pthread" OFF) | ||
|
|
||
| get_filename_component(WEBARKITLIB_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. ABSOLUTE) | ||
| set(ARTK_SRC ${WEBARKITLIB_ROOT}/lib/SRC) | ||
|
|
||
| file(GLOB AR_SOURCES | ||
| ${ARTK_SRC}/AR/*.c | ||
| ${ARTK_SRC}/AR/arLabelingSub/*.c | ||
| ${ARTK_SRC}/ARICP/*.c | ||
| ) | ||
|
|
||
| set(ARUTIL_SOURCES | ||
| ${ARTK_SRC}/ARUtil/log.c | ||
| ${ARTK_SRC}/ARUtil/file_utils.c | ||
| # thread helpers: AR2 handle.c/tracking.c call them even without the KPM worker | ||
| ${ARTK_SRC}/ARUtil/thread_sub.c | ||
| # minizip, used by file_utils.c (zip/unzip helpers) | ||
| ${ARTK_SRC}/ARUtil/crypt.c | ||
| ${ARTK_SRC}/ARUtil/ioapi.c | ||
| ${ARTK_SRC}/ARUtil/unzip.c | ||
| ${ARTK_SRC}/ARUtil/zip.c | ||
| ) | ||
|
|
||
| set(AR2_SOURCES | ||
| handle.c imageSet.c jpeg.c marker.c featureMap.c featureSet.c | ||
| selectTemplate.c surface.c tracking.c tracking2d.c matching.c matching2.c | ||
| template.c searchPoint.c coord.c util.c | ||
| ) | ||
| list(TRANSFORM AR2_SOURCES PREPEND ${ARTK_SRC}/AR2/) | ||
|
|
||
| set(KPM_SOURCES | ||
| kpmHandle.cpp kpmRefDataSet.cpp kpmMatching.cpp kpmResult.cpp kpmUtil.cpp kpmFopen.c | ||
| FreakMatcher/detectors/DoG_scale_invariant_detector.cpp | ||
| FreakMatcher/detectors/gaussian_scale_space_pyramid.cpp | ||
| FreakMatcher/detectors/gradients.cpp | ||
| FreakMatcher/detectors/orientation_assignment.cpp | ||
| FreakMatcher/detectors/pyramid.cpp | ||
| FreakMatcher/facade/visual_database_facade.cpp | ||
| FreakMatcher/matchers/hough_similarity_voting.cpp | ||
| FreakMatcher/matchers/freak.cpp | ||
| FreakMatcher/framework/date_time.cpp | ||
| FreakMatcher/framework/image.cpp | ||
| FreakMatcher/framework/logger.cpp | ||
| FreakMatcher/framework/timers.cpp | ||
| ) | ||
| list(TRANSFORM KPM_SOURCES PREPEND ${ARTK_SRC}/KPM/) | ||
|
|
||
| set(NFT_SOURCES | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/trackingMod.c | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/trackingMod2d.c | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/markerDecompress.c | ||
| ) | ||
|
|
||
| if(WEBARKIT_NFT_THREADS) | ||
| list(APPEND NFT_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/trackingSub.c) | ||
| endif() | ||
|
|
||
| add_library(WebARKitNFT STATIC | ||
| ${AR_SOURCES} ${ARUTIL_SOURCES} ${AR2_SOURCES} ${KPM_SOURCES} ${NFT_SOURCES} | ||
| ) | ||
|
|
||
| target_include_directories(WebARKitNFT | ||
| PUBLIC | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/include | ||
| ${WEBARKITLIB_ROOT}/include | ||
| PRIVATE | ||
| ${ARTK_SRC}/KPM/FreakMatcher | ||
| ) | ||
|
|
||
| target_compile_definitions(WebARKitNFT PUBLIC HAVE_NFT) | ||
|
|
||
| if(EMSCRIPTEN) | ||
| # Emscripten has no fopen64/ftello64/fseeko64: let minizip use the plain calls. | ||
| set_source_files_properties( | ||
| ${ARTK_SRC}/ARUtil/ioapi.c ${ARTK_SRC}/ARUtil/unzip.c ${ARTK_SRC}/ARUtil/zip.c | ||
| PROPERTIES COMPILE_DEFINITIONS USE_FILE32API | ||
| ) | ||
| # libjpeg and zlib come from the Emscripten ports. | ||
| target_compile_options(WebARKitNFT PUBLIC -sUSE_LIBJPEG=1 -sUSE_ZLIB=1) | ||
| target_link_options(WebARKitNFT PUBLIC -sUSE_LIBJPEG=1 -sUSE_ZLIB=1) | ||
| if(WEBARKIT_NFT_THREADS) | ||
| target_compile_options(WebARKitNFT PUBLIC -pthread) | ||
| target_link_options(WebARKitNFT PUBLIC -pthread) | ||
| endif() | ||
| else() | ||
| find_package(JPEG REQUIRED) | ||
| find_package(ZLIB REQUIRED) | ||
| find_package(Threads REQUIRED) | ||
| target_link_libraries(WebARKitNFT PUBLIC JPEG::JPEG ZLIB::ZLIB Threads::Threads) | ||
| endif() | ||
22 changes: 22 additions & 0 deletions
22
WebARKit/WebARKitTrackers/WebARKitNFT/include/WebARKitTrackers/WebARKitNFT/NFTMarkerState.h
This file contains hidden or 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,22 @@ | ||
| #ifndef NFT_MARKER_STATE_H | ||
| #define NFT_MARKER_STATE_H | ||
|
|
||
| #include <AR/ar.h> | ||
| #include <AR/arFilterTransMat.h> | ||
|
|
||
| /** | ||
| * Tracking state for one NFT marker (page). | ||
| * | ||
| * The bindings keep one of these per loadable page (PAGES_MAX). It replaces the | ||
| * single `detectedPage` / `ftmi` pair that limited tracking to one marker at a | ||
| * time (#613, #611). | ||
| */ | ||
| struct NFTMarkerState { | ||
| bool tracking = false; // AR2 is locked on this page | ||
| ARdouble pose[3][4] = {}; // latest pose, filtered when filtering is on | ||
| float err = -1.0f; // AR2 tracking error for `pose` | ||
| ARFilterTransMatInfo *ftmi = nullptr; // this marker's pose filter, created on first use | ||
| bool filterNeedsReset = true; // restart the filter on (re)acquisition | ||
| }; | ||
|
|
||
| #endif // NFT_MARKER_STATE_H |
26 changes: 26 additions & 0 deletions
26
...RKit/WebARKitTrackers/WebARKitNFT/include/WebARKitTrackers/WebARKitNFT/markerDecompress.h
This file contains hidden or 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,26 @@ | ||
| #ifndef MARKER_DECOMPRESS_H | ||
| #define MARKER_DECOMPRESS_H | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef struct | ||
| { | ||
| char *iset_content; | ||
| char *fset_content; | ||
| char *fset3_content; | ||
| } markerContentStruct; | ||
|
|
||
| char* nameConcat(const char *s1, const char *s2); | ||
| FILE *openZFT( const char *filename, const char *ext); | ||
| int decompressMarkers(const char* src, const char* outTemp); | ||
| int extractDataAndSave(const char* str, const char* name); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // MARKER_DECOMPRESS_H |
83 changes: 83 additions & 0 deletions
83
WebARKit/WebARKitTrackers/WebARKitNFT/include/WebARKitTrackers/WebARKitNFT/trackingMod.h
This file contains hidden or 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,83 @@ | ||
| /* | ||
| * trackingMod.h modified version of ar2Tracking() | ||
| * from AR2/tracking.c | ||
| * ARToolKit5 | ||
| * | ||
| * This file is part of ARToolKit. | ||
| * | ||
| * ARToolKit is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * ARToolKit is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License | ||
| * along with ARToolKit. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * As a special exception, the copyright holders of this library give you | ||
| * permission to link this library with independent modules to produce an | ||
| * executable, regardless of the license terms of these independent modules, and to | ||
| * copy and distribute the resulting executable under terms of your choice, | ||
| * provided that you also meet, for each linked independent module, the terms and | ||
| * conditions of the license of that module. An independent module is a module | ||
| * which is neither derived from nor based on this library. If you modify this | ||
| * library, you may extend this exception to your version of the library, but you | ||
| * are not obligated to do so. If you do not wish to do so, delete this exception | ||
| * statement from your version. | ||
| * | ||
| * Copyright 2015 Daqri, LLC. | ||
| * Copyright 2006-2015 ARToolworks, Inc. | ||
| * | ||
| * Author(s): Hirokazu Kato, Philip Lamb | ||
| * Mod. by Walter Perdan @kalwalt | ||
| * | ||
| */ | ||
| /*! | ||
| @header tracking | ||
| @abstract ARToolKit NFT core routines. | ||
| @discussion | ||
| This header declares essential types and API for the NFT portion of the | ||
| ARToolKit SDK. | ||
|
|
||
| For compile-time per-machine and NFT configuration, see <AR2/config.h>. | ||
| @copyright 2015 Daqri, LLC. | ||
| */ | ||
|
|
||
| #ifndef __trackingMod_H__ | ||
| #define __trackingMod_H__ | ||
| #include <AR/ar.h> | ||
| #include <AR/icp.h> | ||
| #include <AR2/config.h> | ||
| #include <AR2/featureSet.h> | ||
| #include <AR2/template.h> | ||
| #include <AR2/marker.h> | ||
| #include <AR2/tracking.h> | ||
|
|
||
| #define AR2_TRACKING_6DOF 1 | ||
| #define AR2_TRACKING_HOMOGRAPHY 2 | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| int ar2Tracking2dSubMod ( AR2HandleT *handle, AR2SurfaceSetT *surfaceSet, AR2TemplateCandidateT *candidate, | ||
| ARUint8 *dataPtr, ARUint8 *mfImage, AR2TemplateT **templ, | ||
| AR2Tracking2DResultT *result ); | ||
|
|
||
| AR2HandleT *ar2CreateHandleMod( ARParamLT *cparamLT, AR_PIXEL_FORMAT pixFormat/*, int threadNum*/ ); | ||
| AR2HandleT *ar2CreateHandleSubMod( int pixFormat, int xsize, int ysize/*, int threadNum*/ ); | ||
|
|
||
| int ar2DeleteHandleMod( AR2HandleT **ar2Handle ); | ||
|
|
||
| int ar2TrackingMod ( AR2HandleT *ar2Handle, AR2SurfaceSetT *surfaceSet, | ||
| ARUint8 *dataPtr, float trans[3][4], float *err ); | ||
| int ar2SetInitTrans ( AR2SurfaceSetT *surfaceSet, float trans[3][4] ); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif |
95 changes: 95 additions & 0 deletions
95
WebARKit/WebARKitTrackers/WebARKitNFT/include/WebARKitTrackers/WebARKitNFT/trackingSub.h
This file contains hidden or 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,95 @@ | ||
| /* | ||
| * trackingSub.h | ||
| * 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 2010-2015 ARToolworks, Inc. All Rights Reserved. | ||
| * | ||
| * Author(s): Hirokazu Kato, Philip Lamb. | ||
| * | ||
| */ | ||
|
|
||
| #ifndef TRACKING_SUB_H | ||
| #define TRACKING_SUB_H | ||
|
|
||
| #include <ARUtil/thread_sub.h> | ||
| #include <KPM/kpm.h> | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| THREAD_HANDLE_T *trackingInitInit( KpmHandle *kpmHandle ); | ||
| int trackingInitStart( THREAD_HANDLE_T *threadHandle, ARUint8 *imagePtrLuma ); | ||
| /* Most pages one search can report. Must equal PAGES_MAX in ARToolKitNFT_js_td.h. */ | ||
| #define TRACKING_INIT_MAX_RESULTS 20 | ||
|
|
||
| typedef struct { | ||
| int page; /* page number of the matched marker */ | ||
| float trans[3][4]; /* its initial pose */ | ||
| float error; /* KPM pose error */ | ||
| int inlierNum; /* KPM inlier count: more means a better match */ | ||
| } TrackingInitResult; | ||
|
|
||
| /* | ||
| * Collect the result of the search started by trackingInitStart(): every page | ||
| * KPM matched, up to maxResults. | ||
| * Returns 0 while the search is still running, 1 once it has finished (with | ||
| * *resultNum set, possibly to 0), or -1 on error. | ||
| */ | ||
| int trackingInitGetResults( THREAD_HANDLE_T *threadHandle, TrackingInitResult results[], int maxResults, int *resultNum ); | ||
|
|
||
| /* | ||
| * Single-page form, kept for the legacy threaded binding (ARToolKitJS_td.cpp). | ||
| * Built on trackingInitGetResults(): reports only the best matched page, the | ||
| * one with the most KPM inliers (ties: the lowest KPM error), as the | ||
| * single-result KPM chose it. | ||
| * Returns 0 while the search is still running, 1 with trans and *page set, or | ||
| * -1 if the search matched no page or on error. | ||
| */ | ||
| int trackingInitGetResult( THREAD_HANDLE_T *threadHandle, float trans[3][4], int *page ); | ||
| int trackingInitQuit( THREAD_HANDLE_T **threadHandle_p ); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // !TRACKING_SUB_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.