Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	WebARKit/WebARKitManager.cpp
  • Loading branch information
kalwalt committed Sep 24, 2023
2 parents bf7aeb7 + 8341ec1 commit 3e6d273
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 69 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: WebARKitLib test

on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16.x'
- name: Build and test WebARKitLib
run: |
cd tests && mkdir build && cd build && cmake .. && make && ./webarkit_test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include/AR/config.h
tests/build
tests/build
build
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

![github releases](https://flat.badgen.net/github/release/webarkit/WebARKitLib)
![github stars](https://flat.badgen.net/github/stars/webarkit/WebARKitLib)
![github forks](https://flat.badgen.net/github/forks/webarkit/WebARKitLib)[![Test](https://github.com/webarkit/WebARKitLib/actions/workflows/test.yml/badge.svg)](https://github.com/webarkit/WebARKitLib/actions/workflows/test.yml)
# WebARKitLib

The C/C++ source code of WebARKit, from Artoolkit5 and extended.
Expand Down
55 changes: 55 additions & 0 deletions WebARKit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
cmake_minimum_required(VERSION 3.20)

project(WebARKitLib)

set(CMAKE_CXX_STANDARD 14)

cmake_policy(SET CMP0135 NEW)

include(FetchContent)

FetchContent_Declare(
build_opencv
URL https://github.com/webarkit/opencv-em/releases/download/0.1.0/opencv-4.7.0.zip
)

FetchContent_MakeAvailable(build_opencv)

get_filename_component(PARENT_DIR ./ ABSOLUTE)

set(WEBARKIT_HEADERS
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking//WebARKitEnums.h
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitUtils.h
${PARENT_DIR}/include/WebARKitLog.h
${PARENT_DIR}/include/WebARKitManager.h
)

set(SOURCE
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.cpp
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp
${PARENT_DIR}/WebARKitLog.cpp
${PARENT_DIR}/WebARKitManager.cpp
)

add_library(
WebARKitLib STATIC
${WEBARKIT_HEADERS}
${SOURCE}
)

target_include_directories(WebARKitLib PRIVATE "${PARENT_DIR}/include")
target_include_directories(WebARKitLib PRIVATE "${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include")

target_include_directories(WebARKitLib PRIVATE
"${build_opencv_SOURCE_DIR}"
"${build_opencv_SOURCE_DIR}/libs/opencv/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/calib3d/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/core/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/features2d/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/flann/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/imgproc/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/video/include"
"${build_opencv_SOURCE_DIR}/libs/opencv_contrib/modules/xfeatures2d/include"
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <opencv2/core/types_c.h>
#include <opencv2/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/video/tracking.hpp>

extern const double DEFAULT_NN_MATCH_RATIO;
extern const double TEBLID_NN_MATCH_RATIO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "WebARKitEnums.h"
#include <WebARKitLog.h>
#include <opencv2/Xfeatures2d.hpp>
#include <opencv2/xfeatures2d.hpp>

namespace webarkit {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ static cv::Mat grayscale(uchar data[], size_t cols, size_t rows, ColorSpace colo
return cv::Mat(cols, rows, CV_8UC1, gray.data());
}

std::string inline webarkitGetVersion() {
return WEBARKIT_HEADER_VERSION_STRING;
}

unsigned int inline webarkitGetVersion(char** versionStringRef) {
std::string version = WEBARKIT_HEADER_VERSION_STRING;

if (versionStringRef) {
*versionStringRef = (char*)version.data();
*versionStringRef = const_cast<char*>(version.data());
}

// Represent full version number (major, minor, tiny, build) in
Expand Down
6 changes: 3 additions & 3 deletions WebARKit/include/WebARKitManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WebARKitManager {
} WebARKitState;

WebARKitState state; ///< Current state of operation, progress through initialisation
char* versionString;
std::string versionString;
std::shared_ptr<WebARKitTracker> m_tracker;
webarkit::TRACKER_TYPE m_trackerType;

Expand All @@ -71,9 +71,9 @@ class WebARKitManager {

/**
* Returns a string containing the WebARKit version, such as "1.0.0".
* @return The WebARKit version
* @return The WebARKit version as a std::string
*/
const char* getWebARKitVersion();
std::string getWebARKitVersion();

/**
* Start trackable management so trackables can be added and removed.
Expand Down
90 changes: 39 additions & 51 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ project(Webarkit_tests)
# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)

cmake_policy(SET CMP0135 NEW)

# Fetch googletest v1.13.0 commit b796f7d44681514f58a683a3a71ff17c94edb0c1
include(FetchContent)
FetchContent_Declare(
Expand All @@ -12,73 +14,59 @@ FetchContent_Declare(
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

FetchContent_Declare(
build_opencv
URL https://github.com/webarkit/opencv-em/releases/download/0.1.0/opencv-4.7.0.zip
)

FetchContent_MakeAvailable(googletest build_opencv)

enable_testing()

add_subdirectory(../WebARKit ../WebARKit/build)

add_executable(
hello_test
hello_test.cc
webarkit_test
webarkit_test.cc
)

message(STATUS "CMAKE_CURRENT_LIST_DIR: ${CMAKE_CURRENT_LIST_DIR}")
message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")

get_filename_component(PARENT_DIR ../ ABSOLUTE)
get_filename_component(OPENCV_DIR ../../../opencv/ ABSOLUTE)
get_filename_component(OPENCV_JS_DIR ../../../opencv_js/ ABSOLUTE)
get_filename_component(OPENCV_CONTRIB_DIR ../../../opencv_contrib/ ABSOLUTE)

target_include_directories(hello_test PRIVATE "${PARENT_DIR}/WebARKit/include")
target_include_directories(hello_test PRIVATE "${PARENT_DIR}/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include")
target_include_directories(hello_test PRIVATE "${OPENCV_CONTRIB_DIR}/modules/xfeatures2d/include")
target_include_directories(hello_test PRIVATE "${OPENCV_JS_DIR}")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/calib3d/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/core/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/features2d/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/flann/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/imgproc/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/imgcodecs/include")
target_include_directories(hello_test PRIVATE "${OPENCV_DIR}/modules/video/include")
target_include_directories(webarkit_test PRIVATE "${PARENT_DIR}/WebARKit/include")
target_include_directories(webarkit_test PRIVATE "${PARENT_DIR}/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include")

set(WEBARKIT_HEADERS
${PARENT_DIR}/WebARKit/include/WebARKitManager.h)
target_include_directories(webarkit_test PRIVATE
"${build_opencv_SOURCE_DIR}"
"${build_opencv_SOURCE_DIR}/libs/opencv/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/calib3d/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/core/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/features2d/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/flann/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/imgproc/include"
"${build_opencv_SOURCE_DIR}/libs/opencv/modules/video/include"
"${build_opencv_SOURCE_DIR}/libs/opencv_contrib/modules/xfeatures2d/include"
)

set(SOURCE
set(webarkit_test
${PARENT_DIR}/WebARKit/WebARKitManager.cpp
)

add_library(
WEBARKIT STATIC
${WEBARKIT_HEADERS}
${SOURCE}
)

target_include_directories(WEBARKIT PRIVATE "${PARENT_DIR}/WebARKit/include")
target_include_directories(WEBARKIT PRIVATE "${PARENT_DIR}/WebARKit/WebARKitTrackers/WebARKitOpticalTracking/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_CONTRIB_DIR}/modules/xfeatures2d/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_JS_DIR}")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/calib3d/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/core/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/features2d/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/flann/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/imgproc/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/imgcodecs/include")
target_include_directories(WEBARKIT PRIVATE "${OPENCV_DIR}/modules/video/include")


target_link_libraries(WEBARKIT
INTERFACE
)
# The order of the libs make the difference!

target_link_libraries(
hello_test
${WEBARKIT}
libWEBARKIT
webarkit_test
WebARKitLib
"${build_opencv_SOURCE_DIR}/lib/libopencv_calib3d.a"
"${build_opencv_SOURCE_DIR}/lib/libopencv_features2d.a"
"${build_opencv_SOURCE_DIR}/lib/libopencv_flann.a"
"${build_opencv_SOURCE_DIR}/lib/libopencv_video.a"
"${build_opencv_SOURCE_DIR}/lib/libopencv_xfeatures2d.a"
"${build_opencv_SOURCE_DIR}/lib/libopencv_imgproc.a"
"${build_opencv_SOURCE_DIR}/lib/libopencv_core.a"
"${build_opencv_SOURCE_DIR}/3rdparty/lib/libzlib.a"
GTest::gtest_main
)

include(GoogleTest)
gtest_discover_tests(hello_test)
gtest_discover_tests(webarkit_test)
11 changes: 0 additions & 11 deletions tests/hello_test.cc

This file was deleted.

20 changes: 20 additions & 0 deletions tests/webarkit_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <gtest/gtest.h>
#include <WebARKitManager.h>

// Check WebARKitManager initialisation.
TEST(WebARKitTest, InitialiseBaseTest) {
// Create a WebARKitManager object
webarkit::WebARKitManager manager;
// Check if the WebARKitManager initialisation is successful
EXPECT_TRUE(manager.initialiseBase(webarkit::TRACKER_TYPE::AKAZE_TRACKER));
}

// Check WebARKit version
TEST(WebARKitTest, CheckWebARKitVersion) {
// Create a WebARKitManager object
webarkit::WebARKitManager manager;
// Init the manager with the Akaze tracker
manager.initialiseBase(webarkit::TRACKER_TYPE::AKAZE_TRACKER);
// Check if the WebARKit version is correct
EXPECT_STREQ(manager.getWebARKitVersion().c_str(), "1.0.0");
}

0 comments on commit 3e6d273

Please sign in to comment.