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

Feature webarkit trackers stable #17

Merged
merged 30 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
70eb898
restoring ARMulti
kalwalt May 14, 2020
0947a3a
video.c for javascript5 and similar
kalwalt May 14, 2020
c315ed5
removing other not necessary files
kalwalt May 15, 2020
6773be1
android.h is not necessary
kalwalt May 15, 2020
7946e7a
removing AR/gsub_es.h, gsub_es2.h, gsub_lite.h
kalwalt May 15, 2020
c390f77
removing Eden lib
kalwalt May 15, 2020
f04ec81
removing gsub.h and gsubConfig.h
kalwalt May 15, 2020
fcf13e2
Merge branch 'dev'
kalwalt Jan 17, 2022
683d401
Merge branch 'fix-webarkitLog'
kalwalt Apr 1, 2022
1462dd4
merge dev with auto_ptr fix
kalwalt Nov 12, 2022
0f4a704
removing dynamic throw's see #11
kalwalt Nov 28, 2022
6074362
adding try catch to avoid dynamic throw #11
kalwalt Nov 28, 2022
8f42e14
removing dymanic throw from image.h & .cpp see #11
kalwalt Nov 29, 2022
20c369f
Eigen 3.4.0 version
kalwalt Jun 30, 2022
0472a3d
added fatal log errors
kalwalt Nov 30, 2022
07baf8b
updated Readme
kalwalt Nov 30, 2022
0eb8bc1
removing config.h
kalwalt Nov 30, 2022
63d3f05
WebARKitTrackers from
kalwalt Apr 25, 2023
1de18a2
free() is not needed at all
kalwalt Apr 27, 2023
018c055
better processFrame functions
kalwalt May 1, 2023
5237407
move track method to WebARKitTracker class
kalwalt May 1, 2023
323b6df
simplified code: removing WebARKitAkazeTracker and
kalwalt May 1, 2023
3c33128
clang-formatting
kalwalt May 2, 2023
0029a16
default destructor
kalwalt May 4, 2023
210a7ed
implementing pImpl pattern - WebARKitTracker class
kalwalt May 4, 2023
03b8f4e
copy and move constructors
kalwalt May 4, 2023
f134d2e
New WebARKitLog functionality
kalwalt May 14, 2023
be7ae15
removing couts and using WEBARKIT_LOG instead
kalwalt May 14, 2023
0114d0f
Some library informations
kalwalt May 14, 2023
0656e37
Merge branch 'dev' into feature-webarkit-trackers-stable
kalwalt May 14, 2023
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# WebARKitLib

The C/C++ source code of WebARKit, from Artoolkit5 and extended.
Updated to [Eigen](https://eigen.tuxfamily.org) 3.4.0 and Emscripten emsdk 3.1.26.

Updated to [Eigen](https://eigen.tuxfamily.org) 3.4.0 and Emscripten emsdk 3.1.26.

## Features

The library containes the following features:
**Artoolkit5** C/C++ code used by [jsartoolkitNFT](https://github.com/webarkit/jsartoolkitNFT) and [ARnft](https://github.com/webarkit/ARnft) (see lib and include folders). Note that is not the full Artoolkit5 library, but only the code needed by jsartoolkitNFT and ARnft. The code is updated to Eigen 3.4.0 and can be compiled with Emscripten emsdk 3.1.26.
**WebARKit** C++ code, which is our experimental code for WebAR. It is completetly independent from Artoolkit5 and can be used as a standalone library. It can be compiled with Emscripten emsdk 3.1.26.
212 changes: 212 additions & 0 deletions WebARKit/WebARKitLog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*
* WebARKitLog.cpp
* WebARKit
*
* This file is part of WebARKit.
*
* WebARKit 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.
*
* WebARKit 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 WebARKit. 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-2016 Daqri, LLC.
* Copyright 2003-2015 ARToolworks, Inc.
* Copyright 2023 WebARKit.
*
* Author(s): Hirokazu Kato, Philip Lamb, Walter Perdan
*
* This code was taken from Artoolkit5 https://github.com/artoolkitx/artoolkit5
* with small modifications to adapt to existing WebARKIt code
*
*/

#include <WebARKitLog.h>

#ifndef _WIN32
# include <pthread.h> // pthread_self(), pthread_equal()
# ifdef __APPLE__
# include <os/log.h>
# endif
#else
# include <Windows.h>
# define snprintf _snprintf
#endif

//
// Global required for logging functions.
//
int webarkitLogLevel = WEBARKIT_LOG_LEVEL_DEFAULT;
static WEBARKIT_LOG_LOGGER_CALLBACK webarkitLogLoggerCallback = NULL;
static int webarkitLogLoggerCallBackOnlyIfOnSameThread = 0;
#ifndef _WIN32
static pthread_t webarkitLogLoggerThread;
#else
static DWORD webarkitLogLoggerThreadID;
#endif
#define WEBARKIT_LOG_WRONG_THREAD_BUFFER_SIZE 4096
static char *webarkitLogWrongThreadBuffer = NULL;
static size_t webarkitLogWrongThreadBufferSize = 0;
static size_t webarkitLogWrongThreadBufferCount = 0;


void webarkitLogSetLogger(WEBARKIT_LOG_LOGGER_CALLBACK callback, int callBackOnlyIfOnSameThread)
{
webarkitLogLoggerCallback = callback;
webarkitLogLoggerCallBackOnlyIfOnSameThread = callBackOnlyIfOnSameThread;
if (callback && callBackOnlyIfOnSameThread) {
#ifndef _WIN32
webarkitLogLoggerThread = pthread_self();
#else
webarkitLogLoggerThreadID = GetCurrentThreadId();
#endif
if (!webarkitLogWrongThreadBuffer) {
if ((webarkitLogWrongThreadBuffer = static_cast<char*>(malloc(sizeof(char) * WEBARKIT_LOG_WRONG_THREAD_BUFFER_SIZE)))) {
webarkitLogWrongThreadBufferSize = WEBARKIT_LOG_WRONG_THREAD_BUFFER_SIZE;
}
}
} else {
if (webarkitLogWrongThreadBuffer) {
free(webarkitLogWrongThreadBuffer);
webarkitLogWrongThreadBuffer = NULL;
webarkitLogWrongThreadBufferSize = 0;
}
}
}

void webarkitLog(const char *tag, const int logLevel, const char *format, ...)
{
if (logLevel < webarkitLogLevel) return;
if (!format || !format[0]) return;

va_list ap;
va_start(ap, format);
webarkitLogv(tag, logLevel, format, ap);
va_end(ap);
}

void webarkitLogv(const char *tag, const int logLevel, const char *format, va_list ap)
{
va_list ap2;
char *buf = NULL;
size_t len;
const char *logLevelStrings[] = {
"debug",
"info",
"warning",
"error"
};
const size_t logLevelStringsCount = (sizeof(logLevelStrings)/sizeof(logLevelStrings[0]));
size_t logLevelStringLen;

if (logLevel < webarkitLogLevel) return;
if (!format || !format[0]) return;

// Count length required to unpack varargs.
va_copy(ap2, ap);
#ifdef _WIN32
len = _vscprintf(format, ap);
#else
len = vsnprintf(NULL, 0, format, ap2);
#endif
va_end(ap2);
if (len < 1) return;

// Add characters required for logLevelString.
if (logLevel >= 0 && logLevel < (int)logLevelStringsCount) {
logLevelStringLen = 3 + strlen(logLevelStrings[logLevel]); // +3 for brackets and a space, e.g. "[debug] ".
} else {
logLevelStringLen = 0;
}

buf = (char *)malloc((logLevelStringLen + len + 1) * sizeof(char)); // +1 for nul-term.

if (logLevelStringLen > 0) {
snprintf(buf, logLevelStringLen + 1, "[%s] ", logLevelStrings[logLevel]);
}

vsnprintf(buf + logLevelStringLen, len + 1, format, ap);
len += logLevelStringLen;

if (webarkitLogLoggerCallback) {

if (!webarkitLogLoggerCallBackOnlyIfOnSameThread) {
(*webarkitLogLoggerCallback)(buf);
} else {
#ifndef _WIN32
if (!pthread_equal(pthread_self(), webarkitLogLoggerThread))
#else
if (GetCurrentThreadId() != webarkitLogLoggerThreadID)
#endif
{
// On non-log thread, put it into buffer if we can.
if (webarkitLogWrongThreadBuffer && (webarkitLogWrongThreadBufferCount < webarkitLogWrongThreadBufferSize)) {
if (len <= (webarkitLogWrongThreadBufferSize - (webarkitLogWrongThreadBufferCount + 4))) { // +4 to reserve space for "...\0".
strncpy(&webarkitLogWrongThreadBuffer[webarkitLogWrongThreadBufferCount], buf, len + 1);
webarkitLogWrongThreadBufferCount += len;
} else {
strncpy(&webarkitLogWrongThreadBuffer[webarkitLogWrongThreadBufferCount], "...", 4);
webarkitLogWrongThreadBufferCount = webarkitLogWrongThreadBufferSize; // Mark buffer as full.
}
}
} else {
// On log thread, print buffer if anything was in it, then the current message.
if (webarkitLogWrongThreadBufferCount > 0) {
(*webarkitLogLoggerCallback)(webarkitLogWrongThreadBuffer);
webarkitLogWrongThreadBufferCount = 0;
}
(*webarkitLogLoggerCallback)(buf);
}
}

} else {
#if defined(__ANDROID__)
int logLevelA;
switch (logLevel) {
case WEBARKIT_LOG_LEVEL_REL_INFO: logLevelA = ANDROID_LOG_ERROR; break;
case WEBARKIT_LOG_LEVEL_ERROR: logLevelA = ANDROID_LOG_ERROR; break;
case WEBARKIT_LOG_LEVEL_WARN: logLevelA = ANDROID_LOG_WARN; break;
case WEBARKIT_LOG_LEVEL_INFO: logLevelA = ANDROID_LOG_INFO; break;
case WEBARKIT_LOG_LEVEL_DEBUG: default: logLevelA = ANDROID_LOG_DEBUG; break;
}
__android_log_write(logLevelA, (tag ? tag : "libAR"), buf);
//#elif defined(_WINRT)
// OutputDebugStringA(buf);
#elif defined(__APPLE__)
if (os_log_create == NULL) { // os_log only available macOS 10.12 / iOS 10.0 and later.
fprintf(stderr, "%s", buf);
} else {
os_log_type_t type;
switch (logLevel) {
case WEBARKIT_LOG_LEVEL_REL_INFO: type = OS_LOG_TYPE_DEFAULT; break;
case WEBARKIT_LOG_LEVEL_ERROR: type = OS_LOG_TYPE_ERROR; break;
case WEBARKIT_LOG_LEVEL_WARN: type = OS_LOG_TYPE_DEFAULT; break;
case WEBARKIT_LOG_LEVEL_INFO: type = OS_LOG_TYPE_INFO; break;
case WEBARKIT_LOG_LEVEL_DEBUG: default: type = OS_LOG_TYPE_DEBUG; break;
}
os_log_with_type(OS_LOG_DEFAULT, type, "%{public}s", buf);
}
#else
fprintf(stderr, "%s", buf);
#endif
}
free(buf);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h>

extern const double GOOD_MATCH_RATIO = 0.7f;
extern const int MAX_FEATURES = 8000;
extern const int N = 10;
extern const int MIN_NUM_MATCHES = 20;
Loading