Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
09579bd
removing dynamic throw's see #11
kalwalt Nov 28, 2022
a201127
adding try catch to avoid dynamic throw #11
kalwalt Nov 28, 2022
b0e5352
removing dymanic throw from image.h & .cpp see #11
kalwalt Nov 29, 2022
661e2cf
Eigen 3.4.0 version
kalwalt Jun 30, 2022
bdf5e85
added fatal log errors
kalwalt Nov 30, 2022
fab0f07
updated Readme
kalwalt Nov 30, 2022
938d5b0
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
4e34ef5
Merge pull request #17 from webarkit/feature-webarkit-trackers-stable
kalwalt May 14, 2023
73d5823
separate detector from descriptor
kalwalt May 16, 2023
b8ed035
adding support for other feature detector
kalwalt May 19, 2023
fd844be
improved optical flow
kalwalt May 19, 2023
e05bbbf
createFeatureMask and _isDetected
kalwalt May 19, 2023
295c80e
feature masks to Tracker and frame view
kalwalt May 22, 2023
a4fb707
start to develop some tests with googletest
kalwalt May 23, 2023
05c84c0
improved cmake settings
kalwalt May 23, 2023
3e13b98
Improving WebARKitManager
kalwalt May 25, 2023
17128b5
WebARKitManager now can pass also output data
kalwalt Jun 3, 2023
2ddf77a
setLogLevel method and
kalwalt Jun 19, 2023
fe4dbf6
new property minNumMatches to assign specific matches threshold
kalwalt Jun 20, 2023
d0bbef9
testing cmake configuration
kalwalt Jul 21, 2023
a6a7cd0
trying to compile opencv with fetchContent
kalwalt Jul 25, 2023
442712d
succesful compilation of opencv with FetchContent
kalwalt Jul 27, 2023
8fb3abb
build opencv_contrib also with FetchContent
kalwalt Jul 28, 2023
72f7524
almost done for a first test
kalwalt Jul 29, 2023
d550036
now test starts but there is a bug to fix
kalwalt Jul 30, 2023
bf852cc
solve destructor issue ad first working gtest!
kalwalt Aug 1, 2023
6a83f67
fix for target_include_directories
kalwalt Aug 1, 2023
26dc733
add one more test and change name of tests
kalwalt Aug 1, 2023
f160066
version 0.4.3
kalwalt Sep 14, 2023
8b424a0
creating test with github action
kalwalt Sep 14, 2023
e66bebe
fix path and typo in the action script
kalwalt Sep 14, 2023
36f1502
the script do not enter in the folder
kalwalt Sep 14, 2023
09a4ea0
the commands should stay in the same run
kalwalt Sep 14, 2023
442e9ce
avoiding multilines command
kalwalt Sep 14, 2023
3f3b4fd
missed make command to compile the project
kalwalt Sep 14, 2023
e43b862
testing with a different OPENCV_EXTRA_MODULES_PATH
kalwalt Sep 14, 2023
13d8049
fix for extra modules path
kalwalt Sep 14, 2023
83ef2bd
this should compile WebARKitLib
kalwalt Sep 15, 2023
f9b0261
correct xfeatures2d include for tests
kalwalt Sep 15, 2023
4a2c715
correct path for xfeatures2d include for tests
kalwalt Sep 15, 2023
3c32591
correct path for xfeatures2d include for tests
kalwalt Sep 15, 2023
2a855a1
maybe this is correct
kalwalt Sep 15, 2023
6e883c0
fix a typo
kalwalt Sep 15, 2023
5b235a9
minor changes but not solve anything
kalwalt Sep 17, 2023
3740075
fetching content from opencv-em build the project!
kalwalt Sep 24, 2023
c54087a
fix for linux command in tests.yml
kalwalt Sep 24, 2023
8f65ada
setting CMP0135 NEW policy
kalwalt Sep 24, 2023
8341ec1
improving the README
kalwalt Sep 24, 2023
bf7aeb7
fix for VersionString bug
kalwalt Sep 24, 2023
3e6d273
Merge remote-tracking branch 'upstream/dev' into dev
kalwalt Sep 24, 2023
0f57d04
making CMakeLists file compliant for emscripten
kalwalt Oct 23, 2023
656823e
build the WebARKitLib with Emscripten
kalwalt Oct 23, 2023
377f967
fix for wrong compilation
kalwalt Oct 23, 2023
97a63b7
docker should be run outside build
kalwalt Oct 23, 2023
efc4574
display the files in the directory for debugging
kalwalt Oct 23, 2023
a565d9f
we are outside webarkit-testing
kalwalt Oct 23, 2023
a8979bd
fix for path
kalwalt Oct 23, 2023
f839e22
tests for enums
kalwalt Oct 24, 2023
c2e79e9
more tests for enums
kalwalt Oct 24, 2023
fc70005
testing config values
kalwalt Oct 24, 2023
e221dda
test for config values
kalwalt Oct 24, 2023
c71745c
fake test for initTracker
kalwalt Oct 24, 2023
645a6e4
new opencv version to fetch from opencv-em
kalwalt Oct 24, 2023
5ea8ee2
fix for cmake policy
kalwalt Oct 24, 2023
750a4c7
fix for test
kalwalt Oct 25, 2023
18fcf1f
tests for other trackers initialization
kalwalt Oct 25, 2023
ee86ba4
new WebARKitCamera class to test
kalwalt Oct 25, 2023
2d4794d
basic code for WebARKitCamera class
kalwalt Oct 26, 2023
fc6cbd2
new member methods for WebARKitCamera
kalwalt Oct 27, 2023
39b1e8f
load camera data and coefficients in the Tracker
kalwalt Oct 27, 2023
690fcad
use WebARKit custom logging
kalwalt Oct 28, 2023
be9c775
rewrited setupCamera code with new setFocalLength
kalwalt Oct 28, 2023
ba9486b
creating WebARKitPattern struct see #21
kalwalt Nov 1, 2023
fdb3269
using push_back to avoid an Seg fault
kalwalt Nov 1, 2023
1efbd84
getPoseMatrix function and improved computePose
kalwalt Nov 2, 2023
b12d9f7
trying to find the root of the pose matrix issue
kalwalt Nov 3, 2023
538bbc2
cleaning the code
kalwalt Nov 4, 2023
e9a29bf
The issue arise the wrong camera matrix data
kalwalt Nov 4, 2023
df2db7f
this seems to be correct!
kalwalt Nov 4, 2023
531b2e9
improved classes and features
kalwalt Nov 4, 2023
1719da5
new WebARKitGL collection of GL functions
kalwalt Nov 5, 2023
90c9115
fix for wrong cv headers
kalwalt Nov 5, 2023
cbcc8b9
values and params should be double
kalwalt Nov 6, 2023
f86e9d0
make GL mfunctions part of ebarkit namespace
kalwalt Nov 6, 2023
ecb161b
revert to old syntax pattern
kalwalt Nov 6, 2023
b6b113c
new cameraProjectionMatrix with gtest
kalwalt Nov 6, 2023
1f90c06
getCameraProjectioMatrix with gtest
kalwalt Nov 6, 2023
8c5e572
fix for: Test issue: impossible to load a jpeg image with imread (Ope…
kalwalt Nov 9, 2023
1648f8a
add to initTracker colorSpace option to let use other colors channels
kalwalt Nov 10, 2023
c6c950c
pinball image is 3 channels add support for this type to initTracker
kalwalt Nov 10, 2023
190015b
processFrameData now may process also RGB data input
kalwalt Nov 10, 2023
b7a143e
new convert2Grayscale function to avoid repetitions
kalwalt Nov 11, 2023
2556de3
oveloaded convert2Grayscale function and other fixes
kalwalt Nov 13, 2023
a12f515
testing matrix and cameraProjmatrix
kalwalt Nov 16, 2023
545b02b
sphere is displayed but don't move
kalwalt Nov 18, 2023
1508a63
_isDetected = false should be outside clear_output()
kalwalt Nov 18, 2023
b061656
initTracker as templatized function
kalwalt Nov 18, 2023
9a58f02
Fix swapImage and other related code
kalwalt Dec 5, 2023
7a9e52c
small improves
kalwalt Mar 3, 2024
ab660e3
fix for MIN_NUM_MATCHES failed test
kalwalt Mar 4, 2024
48f7d01
move marker dected message inside processFrame
kalwalt Mar 8, 2024
f16a52a
new extractFeatures method
kalwalt Mar 15, 2024
fab85d7
new boolean option enablleBlur
kalwalt Mar 20, 2024
9536f62
more modularity in the C++ code
kalwalt Mar 31, 2024
f4ea9ff
fix for getMatches function
kalwalt Mar 31, 2024
d2a15a9
fix for numMatches
kalwalt Mar 31, 2024
6e7e597
fix for numMatches format display
kalwalt Mar 31, 2024
d465fd5
backward calcOpticalFlowPyrLK
kalwalt Apr 20, 2024
864ed7a
further improves to Optical Flow routine
kalwalt Apr 20, 2024
9043bed
new getHomograpyInliers function and WebARKitHomographyInfo class
kalwalt May 28, 2024
0bdcd97
runOpticalFlow and updateTrackableHomography under test
kalwalt May 28, 2024
ade19d5
new processFrame2 function under testing
kalwalt May 30, 2024
fc09522
testing matchFeatures from artoolkitx
kalwalt May 31, 2024
edb9d2a
fix for build tests issue
kalwalt Jun 2, 2024
4160b61
MatchTemplateToImage function
kalwalt Jun 2, 2024
5df3f89
template matching and TrackViz
kalwalt Jun 4, 2024
edcf708
fix for template matching
kalwalt Jun 4, 2024
7923e10
lowering num. of features
kalwalt Jun 4, 2024
d386836
fix for tests
kalwalt Jun 4, 2024
0fed59e
chore: Update Node.js version in test workflow
kalwalt Jun 4, 2024
47e1984
_trackViz improves in the code
kalwalt Jun 5, 2024
1e98161
removing old code
kalwalt Jun 5, 2024
568146e
using pyrDown utility
kalwalt Jun 5, 2024
f9d4260
Testing new update function
kalwalt Jul 9, 2024
2db7e6a
Added new enum for blurring -> updated c++ and javascript code
kalwalt Sep 12, 2024
6611957
new example with jsfeatNext
kalwalt Sep 14, 2024
57f077c
testing opencv 4.10.0
kalwalt Jan 24, 2025
1f5dcf6
updating webARKit tests to opencv 4.10.0
kalwalt Jan 24, 2025
f53d3fd
Add step to update Ubuntu and install libjpeg-dev in CI workflow
kalwalt Jan 24, 2025
2e6ce31
fix for sudo command
kalwalt Jan 24, 2025
eee44b8
test with emsdk 3.1.38
kalwalt Jan 24, 2025
f1e77dd
improves to viewMatrix_GL and related code
kalwalt Feb 6, 2025
891f50f
improved getTransformationMatrix function to be tested
kalwalt Feb 7, 2025
3429eb3
Fix CV->GL pose conversion in updateTrackable()
kalwalt May 29, 2026
32a6343
Fix crash when a marker is detected on the first frame (#37)
kalwalt May 30, 2026
1021616
fix(tracker): stop double-scaling matched keypoints when detection is…
kalwalt Jun 9, 2026
f448ef3
fix(gl,pose): standard GL projection X sign + D*R*D marker-frame hand…
kalwalt Jun 9, 2026
c1ae096
refactor(tracker): remove vestigial pyramid-downsample/scale machinery
kalwalt Jun 9, 2026
39183f0
fix(tracker): declare tracking lost when the marker leaves the frame
kalwalt Jun 13, 2026
15dc93f
feat(tracker): optional centered marker origin (setOriginCentered)
kalwalt Jun 16, 2026
4308af6
feat(#44): detect features on downsampled frame (part A)
kalwalt Jun 18, 2026
28ff065
feat(#44): skip feature detection while tracking (part B)
kalwalt Jun 19, 2026
f3f33cc
fix(#55): populate pose3d + rename getPoseMatrix/getPoseMatrix2
kalwalt Jun 19, 2026
791dc04
refactor(#50): remove dangling WebARKitManager::update() declaration
kalwalt Jun 20, 2026
9bf7703
refactor(#50): remove commented-out im_gray() helper
kalwalt Jun 20, 2026
f6bca84
refactor(#50): drop commented-out _trackables/getPoseMatrix3 scaffolding
kalwalt Jun 20, 2026
e6f87fa
refactor(#50): remove superseded computePose/invertPose/computeGLview…
kalwalt Jun 20, 2026
24b8877
docs(#51): rewrite README + bump version to 0.8.0
kalwalt Jun 20, 2026
4553096
test(#51): update version assertions to 0.8.0
kalwalt Jun 20, 2026
284fa45
docs(#51): clarify CMake already builds the static lib
kalwalt Jun 21, 2026
221ff36
docs(#51): note static-lib targets (WASM + Linux) and opencv-em depen…
kalwalt Jun 21, 2026
c9b7280
docs(#51): require Conventional Commits + point to CONTRIBUTING.md
kalwalt Jun 21, 2026
dc9a058
docs(#51): add CONTRIBUTING.md
kalwalt Jun 21, 2026
758057c
docs(#51): clarify PR-pair flow scope (WebARKit/ <-> webarkit-testing)
kalwalt Jun 21, 2026
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
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: WebARKitLib test

on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Update Ubuntu and install libjpeg-dev
run: |
sudo apt-get update && sudo apt install libjpeg-dev
- name: Build and test WebARKitLib
run: |
cd tests && mkdir build && cd build && cmake -DEMSCRIPTEN_COMP=0 .. && make && ./webarkit_test
- name: Build WebARKitLib with Emscripten (Docker)
run: |
cd ..
ls
docker run -dit --name emscripten-webarkit-testing -v $(pwd):/src emscripten/emsdk:3.1.38 bash
docker exec emscripten-webarkit-testing emcmake cmake -B WebARKitLib/WebARKit/build -S WebARKitLib/WebARKit -DEMSCRIPTEN_COMP=1 ..
docker exec emscripten-webarkit-testing emmake make -C WebARKitLib/WebARKit/build

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include/AR/config.h
include/AR/config.h
tests/build
build
73 changes: 73 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributing to WebARKitLib

Thanks for helping improve WebARKit! This is the C/C++ source of the tracker; most
changes are consumed by the [webarkit-testing](https://github.com/webarkit/webarkit-testing)
superproject as a submodule.

## Workflow

- **Branch from `dev`** and open your PR **against `dev`** (not `main`).
- Reference the related issue in the PR description.
- **Sign your commits** (`git commit -S …`).

## Commit messages — Conventional Commits

All commit messages **must** follow
[Conventional Commits](https://www.conventionalcommits.org/):

```
<type>(<optional scope>): <short description>
```

Common types: `feat`, `fix`, `docs`, `refactor`, `test`, `chore`, `perf`. Examples:

```
feat(tracker): detect features on a downsampled frame
fix(#55): populate pose3d so getPoseMatrixCV() isn't zero
docs: document the pose pipeline
refactor(#50): remove dead computePose/invertPose
```

## What you may change

- Active WebAR work lives under **`WebARKit/`** (the OCVT planar tracker).
- **Do not** modify the vendored **old ARToolKit5** sources under `lib/SRC/**` or
`include/AR/**` — those are upstream utilities used by
[jsartoolkitNFT](https://github.com/webarkit/jsartoolkitNFT) /
[ARnft](https://github.com/webarkit/ARnft) and are kept untouched.

## Cross-repo changes (the PR pair)

> **Applies to `WebARKit/` (this folder) ↔ the `webarkit-testing` repo.** This flow is
> for changes to the **`WebARKit/`** OCVT tracker, which the **webarkit-testing**
> superproject compiles to WASM. Changes to the vendored `lib/SRC/**` / `include/AR/**`
> (old ARToolKit5) do **not** use this flow — they reach the web through
> [jsartoolkitNFT](https://github.com/webarkit/jsartoolkitNFT), a different consumer.

A change to `WebARKit/` that affects the WASM build is consumed by webarkit-testing via
the submodule. Coordinate both repos:

1. Branch from `dev` in **both** WebARKitLib and webarkit-testing.
2. Make the C++ change here; in webarkit-testing bump the submodule pointer and
rebuild (`npm run build-docker` → `build-es6`).
3. Open a **PR pair** (WebARKitLib → `dev`, webarkit-testing → `dev`); cross-link them.
4. After the WebARKitLib PR merges, re-point the submodule to the merged `dev` tip.

## Building & tests

- The library is normally built **from webarkit-testing** (WASM) — see its README.
`WebARKit/CMakeLists.txt` can also build it as a static lib for **WASM** or **native
Linux** (selected via `EMSCRIPTEN_COMP`), pulling OpenCV from
[webarkit/opencv-em](https://github.com/webarkit/opencv-em).
- **Unit tests** (GoogleTest) live in `tests/` and run in CI on every PR:

```bash
cmake -S tests -B tests/build && cmake --build tests/build && ctest --test-dir tests/build
```

If you change a config constant or the version, update the matching assertions in
`tests/webarkit_test.cc`.

## License

By contributing, you agree that your contributions are licensed under **LGPL-3.0**.
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,98 @@
![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.
Updated to [Eigen](https://eigen.tuxfamily.org) 3.4.0 and Emscripten emsdk 3.1.26.
The C/C++ source of **WebARKit** — a browser-side Augmented Reality tracker. The
active code (`WebARKit/`) is an emscripten-friendly port of the **OCVT** planar
image-tracking design from [ArtoolkitX](https://github.com/artoolkitx/artoolkitx),
built on OpenCV. It is normally compiled to WebAssembly and consumed from the
[webarkit-testing](https://github.com/webarkit/webarkit-testing) superproject.

> **Two lineages live here, keep them straight:**
> - **`WebARKit/`** — the WebAR OCVT planar tracker (the design reference is *ArtoolkitX*). This is the code under active development.
> - **`lib/SRC/**`, `include/AR/**`** — vendored **old ARToolKit5** utility sources/headers, kept only because [jsartoolkitNFT](https://github.com/webarkit/jsartoolkitNFT) needs them (and [ARnft](https://github.com/webarkit/ARnft) in turn consumes jsartoolkitNFT as an npm module). Treated as untouched upstream. (Updated to Eigen 3.4.0 / emsdk 3.1.26.)

## Code layout (`WebARKit/`)

| Component | Role |
|---|---|
| `WebARKitManager` | top-level façade — owns the tracker, drives init/process, exposes the output (homography, pose, GL-view, projection) |
| `WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker` | the OCVT tracker core: feature detect/match → homography → optical-flow + template-match tracking |
| `…/TrackingPointSelector` + `…/TrackedPoint` | bin-based selection of template tracking points (ArtoolkitX-derived) |
| `…/WebARKitHomographyInfo` + `WebARKitUtils.h` | RANSAC homography estimation/validation (`getHomographyInliers`) |
| `…/WebARKitConfig` | tuning constants (feature counts, match ratios, pyramid/template sizes, version) |
| `…/TrackerVisualization` | optional debug-overlay scaffolding (inert until wired) |
| `WebARKitCamera` | camera intrinsics from a diagonal-FOV estimate |
| `WebARKitGL` | CV→GL matrix conversion (`arglCameraViewRHf`) + GL projection |
| `WebARKitPattern` | the reference marker (`WebARKitPattern`) and per-frame pose state (`WebARKitPatternTrackingInfo`) |
| `WebARKitLog` | logging |

## Pose pipeline (one glance)

```
solvePnP (cameraPoseFromPoints) // OpenCV-convention camera pose
-> getTrackablePose / updateTrackable // CV->GL handedness fix, D*R*D (see #42)
-> arglCameraViewRHf // right-handed GL modelview
-> matrixGL_RH // what the examples attach content to
```

Pose getters: **`getPoseMatrixCV()`** (raw 4×4 OpenCV pose) and **`getPoseMatrixGL()`**
(the GL/right-handed pose); projection via `getCameraProjectionMatrix()`. The full
derivation is in
[`docs/design-projection-and-pose-artoolkitx-alignment.md`](https://github.com/webarkit/webarkit-testing/blob/dev/docs/design-projection-and-pose-artoolkitx-alignment.md)
(webarkit-testing).

## Building

This repo isn't built as a single unit — each consumer compiles the **subset it
needs**:

- **`WebARKit/` (the OCVT tracker)** is built by the
[webarkit-testing](https://github.com/webarkit/webarkit-testing) superproject, which
compiles it to WebAssembly with emscripten (emsdk **3.1.26**) inside Docker and wires
it to JS through `emscripten/WebARKitJS.{cpp,h}` + `bindings.cpp` (which live in
webarkit-testing). webarkit-testing currently drives that compile with the Node script
`tools/makem.js` (`npm run build-docker` → `build-es6`); migrating to the CMake config
(`WebARKit/CMakeLists.txt`) is planned.
- **The vendored `lib/SRC/**` + `include/AR/**` (old ARToolKit5)** is built by
[jsartoolkitNFT](https://github.com/webarkit/jsartoolkitNFT) as part of its build —
not by webarkit-testing. ([ARnft](https://github.com/webarkit/ARnft) consumes
jsartoolkitNFT as an npm module and doesn't build the emscripten code itself.)

`WebARKit/CMakeLists.txt` can **already build WebARKitLib as a static library**
today — for both **WASM** (emscripten) and **native Linux**, selected via the
`EMSCRIPTEN_COMP` flag. It depends on a prebuilt **OpenCV** from
[webarkit/opencv-em](https://github.com/webarkit/opencv-em) (the emscripten
`opencv-js-…-emcc` build for WASM, or the native `opencv-…` build for Linux),
fetched automatically via CMake `FetchContent`. The "planned" part above is
webarkit-testing switching its WASM build over to this CMake config (away from
`tools/makem.js`). The same config also drives the unit tests (see below).

## Tests

C++ unit tests (GoogleTest) live in [`tests/`](tests/) (`webarkit_test.cc`,
`CMakeLists.txt`, `pinball.jpg`) and run in CI via
[`.github/workflows/test.yml`](https://github.com/webarkit/WebARKitLib/actions/workflows/test.yml).
Build them standalone with CMake:

```bash
cmake -S tests -B tests/build && cmake --build tests/build && ctest --test-dir tests/build
```

## Contributing

Please read [`./CONTRIBUTING.md`](./CONTRIBUTING.md) for the full guidelines. In short:

- Branch from `dev`; PR back to `dev`; sign your commits and reference the issue.
- **Commit messages must follow [Conventional Commits](https://www.conventionalcommits.org/)**
(e.g. `feat:`, `fix:`, `docs:`, `refactor:`, `test:`, `chore:`).
- Library changes are usually paired with a build/bump in webarkit-testing — see that
repo's "cross-repo PR pair" flow.
- Don't modify the vendored `lib/SRC/**` / `include/AR/**` (old ARToolKit5) as part of
WebAR work.

## License

LGPL-3.0 (see `LICENSE.txt`).
83 changes: 83 additions & 0 deletions WebARKit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
cmake_minimum_required(VERSION 3.16)

project(WebARKitLib)

set(CMAKE_CXX_STANDARD 14)

if(VERSION GREATER 3.24)
cmake_policy(SET CMP0135 NEW)
endif()

include(FetchContent)

if(${EMSCRIPTEN_COMP} EQUAL 1)
message("Fetching opencv for emscripten compilation from webarkit/opencv-em ...")
FetchContent_Declare(
build_opencv
URL https://github.com/webarkit/opencv-em/releases/download/0.1.6/opencv-js-4.10.0-emcc-3.1.38.zip
)
else()
message("Fetching opencv from webarkit/opencv-em ...")
FetchContent_Declare(
build_opencv
URL https://github.com/webarkit/opencv-em/releases/download/0.1.6/opencv-4.10.0.zip
)
endif()

FetchContent_MakeAvailable(build_opencv)

get_filename_component(PARENT_DIR ./ ABSOLUTE)

set(WEBARKIT_HEADERS
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/TrackedPoint.h
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/TrackingPointSelector.h
${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/WebARKitHomographyInfo.h
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/include/WebARKitTrackers/WebARKitOpticalTracking/WebARKitUtils.h
${PARENT_DIR}/include/WebARKitCamera.h
${PARENT_DIR}/include/WebARKitLog.h
${PARENT_DIR}/include/WebARKitGL.h
${PARENT_DIR}/include/WebARKitManager.h
${PARENT_DIR}/include/WebARKitPattern.h
)

set(SOURCE
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/TrackedPoint.cpp
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/TrackingPointSelector.cpp
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.cpp
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/WebARKitHomographyInfo.cpp
${PARENT_DIR}/WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.cpp
${PARENT_DIR}/WebARKitCamera.cpp
${PARENT_DIR}/WebARKitLog.cpp
${PARENT_DIR}/WebARKitGL.cpp
${PARENT_DIR}/WebARKitManager.cpp
${PARENT_DIR}/WebARKitPattern.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"
)

target_link_libraries(WebARKitLib
jpeg
"${build_opencv_SOURCE_DIR}/3rdparty/lib/liblibopenjp2.a"
)
52 changes: 52 additions & 0 deletions WebARKit/WebARKitCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <WebARKitCamera.h>
#include <WebARKitLog.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitConfig.h>

namespace webarkit {
WebARKitCamera::WebARKitCamera() : xsize(-1), ysize(-1), diagonal_fov_degrees(70.0) { cmat.fill(0.0); }

WebARKitCamera::~WebARKitCamera() {}

bool WebARKitCamera::setupCamera(int width, int height) {
if (width <= 0 || height <= 0) {
return false;
}
xsize = width;
ysize = height;

setFocalLength(xsize, ysize);

cmat.at(0) = focal_length;
cmat.at(2) = 0.5 * xsize;
cmat.at(4) = focal_length;
cmat.at(5) = 0.5 * ysize;
cmat.at(8) = 1.0;
kc.fill(0.0);
return true;
};

void WebARKitCamera::printSettings() {
WEBARKIT_LOGi("WebARKit: Camera Size %d , %d\n", xsize, ysize);
WEBARKIT_LOGi("WebARKit: camera matrix = [%.2f %.2f %.2f]\n", cmat[0], cmat[1], cmat[2]);
WEBARKIT_LOGi(" [%.2f %.2f %.2f]\n", cmat[3], cmat[4], cmat[5]);
WEBARKIT_LOGi(" [%.2f %.2f %.2f]\n", cmat[6], cmat[7], cmat[8]);
WEBARKIT_LOGi("WebARKit: kc = [%.4f %.4f %.4f %.4f %.4f %.4f]\n", kc[0], kc[1], kc[2], kc[3], kc[4], kc[5]);
};

std::array<double, 9> WebARKitCamera::getCameraData() const {
return cmat;
}

std::array<double, 6> WebARKitCamera::getDistortionCoefficients() const {
return kc;
}

void WebARKitCamera::setFocalLength(int width, int height) {
double diagonal_image_size;
double diagonal_fov_radians;
// simple routine to calculate focal length from diagonal field of view, and convert to camera matrix.
diagonal_image_size = std::pow(std::pow(width, 2.0) + std::pow(height, 2.0), 0.5);
diagonal_fov_radians = diagonal_fov_degrees * m_pi / 180.0;
focal_length = 0.5 * diagonal_image_size / std::tan(0.5 * diagonal_fov_radians);
}
} // namespace webarkit
Loading
Loading