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

Improving WebARKitLib with PnP algorithm #24

Merged
merged 48 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d0808fc
updated project with simd build
kalwalt Oct 25, 2023
c51b949
updated WebARKitLib
kalwalt Oct 26, 2023
4fff99b
update the project to last changes in WebARKitLib
kalwalt Nov 1, 2023
c677f2e
testing getPoseMatrix
kalwalt Nov 2, 2023
64e4c78
fix for issue with getPoseMatrix
kalwalt Nov 2, 2023
b15eef0
testing pose matrix
kalwalt Nov 3, 2023
39df258
the wrong camera matrix was causing the issue
kalwalt Nov 4, 2023
cc98d56
fix for camera matrix (WebARKitLib)
kalwalt Nov 4, 2023
93a6a6c
updating to GL functions
kalwalt Nov 6, 2023
b3e5a9e
testing camera proj matrix
kalwalt Nov 6, 2023
1ec6c9e
testing with threejs -> issue with Grayscale class
kalwalt Nov 8, 2023
f061835
pinball image is 3 channels add support for this type to initTracker
kalwalt Nov 10, 2023
bad00ce
processFrameData now may process also RGB data input
kalwalt Nov 10, 2023
af1ef83
new convert2Grayscale function to avoid repetitions
kalwalt Nov 11, 2023
905793c
oveloaded convert2Grayscale function and other fixes
kalwalt Nov 13, 2023
6fc22a2
testing matrix and cameraProjmatrix
kalwalt Nov 16, 2023
993fcbf
missed files for testing matrix and cameraProjmatrix
kalwalt Nov 16, 2023
cf03c2a
sphere is displayed but don't move
kalwalt Nov 18, 2023
af4bcc1
data is in GRAY format
kalwalt Nov 18, 2023
dcafdf2
removing not necessary files
kalwalt Nov 18, 2023
f2bc766
_isDetected = false should be outside clear_output()
kalwalt Nov 18, 2023
37e630d
initTracker as templatized function
kalwalt Nov 18, 2023
748cb1d
trying to solve threejs issue
kalwalt Dec 5, 2023
7d7ea4e
upgrade packages
kalwalt Jan 8, 2024
713d581
chages that not solve the start tracking issue
kalwalt Mar 3, 2024
6b99766
some progress on solving startTracking issue
kalwalt Mar 3, 2024
54f1a01
testing a new example with speedy-vision library
kalwalt Mar 7, 2024
3524dd9
this is much better
kalwalt Mar 7, 2024
034190a
removing cnavas_process and related code
kalwalt Mar 7, 2024
a052d27
improving the code with a callback function
kalwalt Mar 8, 2024
a1c1148
adpat code to grescale video example from speedy vision
kalwalt Mar 8, 2024
76ca61f
better code with bind
kalwalt Mar 8, 2024
5650ba0
it can detect but the example must be improved
kalwalt Mar 9, 2024
c58727c
removing not necessary args
kalwalt Mar 9, 2024
f7b9985
new extractFeatures method
kalwalt Mar 15, 2024
f2593b2
changes according to new enableBlur option in WebARKit
kalwalt Mar 20, 2024
ad911fe
testing speedy-vision gaussian blur and nightvision effect
kalwalt Mar 20, 2024
75968a8
testing modified sink
kalwalt Mar 26, 2024
445d502
testing new sink node but got some issues
kalwalt Mar 26, 2024
e34c456
testing a new export for SinkImageData
kalwalt Mar 28, 2024
331be88
testing new TextureReader
kalwalt Mar 31, 2024
d916ade
more modularity in the C++ code
kalwalt Mar 31, 2024
001b989
fix for getMatches function
kalwalt Mar 31, 2024
8a5c398
fix for getMatches function
kalwalt Mar 31, 2024
1cd5cb2
fix for numMatches
kalwalt Mar 31, 2024
ba1f01f
fix for numMatches format display
kalwalt Mar 31, 2024
142a108
PnP C++ code merged in dev branch
kalwalt Apr 1, 2024
aabc85d
Merge branch 'dev' into improved-gtests
kalwalt Apr 1, 2024
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"any": "cpp",
"string_view": "cpp",
"regex": "cpp"
}
},
"clang-format.executable": "/usr/bin/clang-format"
}
10 changes: 5 additions & 5 deletions build/webarkit_ES6_wasm.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions build/webarkit_ES6_wasm.simd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/WebARKit.js

Large diffs are not rendered by default.

55 changes: 28 additions & 27 deletions emscripten/WebARKitJS.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
#include "WebARKitJS.h"

void WebARKit::initTrackerGray(emscripten::val data_buffer, int width, int height) {
auto u8 =
emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
manager.initTracker(u8.data(), width, height);
auto u8 = emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
manager.initTracker(u8.data(), width, height);
}

void WebARKit::processFrame(emscripten::val data_buffer, webarkit::ColorSpace colorSpace) {
auto u8 =
emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
manager.processFrameData(u8.data(), this->videoWidth,
this->videoHeight, colorSpace);
auto u8 = emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
manager.processFrameData(u8.data(), this->videoWidth, this->videoHeight, colorSpace);
}

void WebARKit::setLogLevel(int logLevel) {
manager.setLogLevel(logLevel);
}
void WebARKit::setLogLevel(int logLevel) { manager.setLogLevel(logLevel); }

emscripten::val WebARKit::getHomography() {
std::vector<double> output;
output = manager.getOutputData();
emscripten::val homography = emscripten::val::array();
for (auto i = 0; i < 9; i++) {
homography.call<void>("push", output[i]);
}
return homography;
std::vector<double> output;
output = manager.getOutputData();
emscripten::val homography = emscripten::val::array();
for (auto i = 0; i < 9; i++) {
homography.call<void>("push", output[i]);
}
return homography;
}

emscripten::val WebARKit::getPoseMatrix() {
cv::Mat poseMatrix = manager.getPoseMatrix();
emscripten::val pose = emscripten::val::array();
for (auto i = 0; i < 12; i++) {
pose.call<void>("push", poseMatrix.at<double>(i));
kalwalt marked this conversation as resolved.
Show resolved Hide resolved
}
return pose;
}

emscripten::val WebARKit::getCorners() {
std::vector<double> output;
output = manager.getOutputData();
emscripten::val corners = emscripten::val::array();
for (auto i = 9; i < 17; i++) {
corners.call<void>("push", output[i]);
}
return corners;
std::vector<double> output;
output = manager.getOutputData();
emscripten::val corners = emscripten::val::array();
for (auto i = 9; i < 17; i++) {
corners.call<void>("push", output[i]);
}
return corners;
}

bool WebARKit::isValid() {
return manager.isValid();
}
bool WebARKit::isValid() { return manager.isValid(); }

#include "bindings.cpp"
1 change: 1 addition & 0 deletions emscripten/WebARKitJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WebARKit {
void processFrame(emscripten::val data_buffer, webarkit::ColorSpace colorSpace);
void setLogLevel(int logLevel);
emscripten::val getHomography();
emscripten::val getPoseMatrix();
emscripten::val getCorners();
bool isValid();

Expand Down
1 change: 1 addition & 0 deletions emscripten/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ EMSCRIPTEN_BINDINGS(constant_bindings) {
.function("processFrame", &WebARKit::processFrame)
.function("setLogLevel", &WebARKit::setLogLevel)
.function("getHomography", &WebARKit::getHomography)
.function("getPoseMatrix", &WebARKit::getPoseMatrix)
.function("getCorners", &WebARKit::getCorners)
.function("isValid", &WebARKit::isValid);
};
1 change: 1 addition & 0 deletions examples/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function initTracker(msg) {
type: "found",
corners: JSON.stringify(event.data.corners),
matrix: JSON.stringify(event.data.matrix),
pose: JSON.stringify(event.data.pose),
};
});
};
Expand Down
1 change: 1 addition & 0 deletions examples/worker_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ window.onload = async function () {
arElem.style.display = "none";
} else {
arElem.style.display = "block";
console.log("pose matrix: ", JSON.parse(msg.pose));
drawCorners(JSON.parse(msg.corners));
transformElem(JSON.parse(msg.matrix), arElem);
}
Expand Down
9 changes: 8 additions & 1 deletion src/WebARKitController.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ export default class WebARKitController {
process_raw(imageData) {
let corners = [];
let matrix = [];
let pose = [];
this.processFrame(imageData);

if(this.isValid()) {

corners = this.getCorners();
matrix = this.getHomography();
pose = this.getPoseMatrix();

this.dispatchEvent({
name: "getMarker",
Expand All @@ -98,7 +100,8 @@ export default class WebARKitController {
index: 0,
type: this.trackerType,
corners: corners,
matrix: matrix
matrix: matrix,
pose: pose
},
})
}
Expand All @@ -124,6 +127,10 @@ export default class WebARKitController {
return this.webarkit.getHomography();
}

getPoseMatrix() {
return this.webarkit.getPoseMatrix();
}

getCorners() {
return this.webarkit.getCorners();
}
Expand Down
7 changes: 4 additions & 3 deletions tools/makem.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ var webarkit_sources = [
'../WebARKitCamera.cpp',
'../WebARKitLog.cpp',
'../WebARKitManager.cpp',
'../WebARKitPattern.cpp',
'WebARKitOpticalTracking/WebARKitTracker.cpp',
'WebARKitOpticalTracking/WebARKitConfig.cpp'
].map(function (src) {
Expand Down Expand Up @@ -175,10 +176,10 @@ var DEBUG_FLAGS = ' ';

if (DEBUG) {
// Choose your Debug options
//DEBUG_FLAGS += ' -gsource-map -fsanitize=undefined ';
//DEBUG_FLAGS += ' -s ASSERTIONS=2 '
DEBUG_FLAGS += ' -gsource-map -fsanitize=undefined ';
DEBUG_FLAGS += ' -s ASSERTIONS=2 '
//DEBUG_FLAGS += ' --profiling '
//DEBUG_FLAGS += ' -s DEMANGLE_SUPPORT=1 ';
DEBUG_FLAGS += ' -s DEMANGLE_SUPPORT=1 ';
// WEBARKIT_DEBUG define flag is used to display additional debug information in the console
DEBUG_FLAGS += ' -DWEBARKIT_DEBUG '
}
Expand Down