Skip to content

Commit

Permalink
simplifying C++ code
Browse files Browse the repository at this point in the history
- removing not necessary classes
- fix issue #11
  • Loading branch information
kalwalt committed May 2, 2023
1 parent 60523fa commit e92312d
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1,363 deletions.
42 changes: 21 additions & 21 deletions build/webarkit_ES6_wasm.js

Large diffs are not rendered by default.

355 changes: 1 addition & 354 deletions dist/GrayScale.js

Large diffs are not rendered by default.

940 changes: 2 additions & 938 deletions dist/WebARKit.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/WebARKit.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
43 changes: 5 additions & 38 deletions emscripten/WebARKitJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,19 @@
void WebARKit::initTrackerGray(emscripten::val data_buffer, int width, int height) {
auto u8 =
emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
if (this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER) {
m_akaze_tracker->initialize_gray_raw(u8.data(), width, height);
} else if (this->m_trackerType == webarkit::TRACKER_TYPE::ORB_TRACKER) {
m_orb_tracker->initialize_gray_raw(u8.data(), width, height);
} else {
throw std::invalid_argument("Invalid tracker type");
}
m_tracker->initTracker(u8.data(), width, height);
}

void WebARKit::processFrame(emscripten::val data_buffer, webarkit::ColorSpace colorSpace) {
auto u8 =
emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
if (this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER) {
m_akaze_tracker->processFrameData(u8.data(), this->videoWidth,
m_tracker->processFrameData(u8.data(), this->videoWidth,
this->videoHeight, colorSpace);
} else if (this->m_trackerType == webarkit::TRACKER_TYPE::ORB_TRACKER) {
m_orb_tracker->processFrameData(u8.data(), this->videoWidth,
this->videoHeight, colorSpace);
} else {
throw std::invalid_argument("Invalid tracker type");
}
}

emscripten::val WebARKit::getHomography() {
std::vector<double> output;
if (this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER) {
output = m_akaze_tracker->getOutputData();
} else if (this->m_trackerType == webarkit::TRACKER_TYPE::ORB_TRACKER) {
output = m_orb_tracker->getOutputData();
} else {
throw std::invalid_argument("Invalid tracker type");
}
output = m_tracker->getOutputData();
emscripten::val homography = emscripten::val::array();
for (auto i = 0; i < 9; i++) {
homography.call<void>("push", output[i]);
Expand All @@ -45,13 +26,7 @@ emscripten::val WebARKit::getHomography() {

emscripten::val WebARKit::getCorners() {
std::vector<double> output;
if (this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER) {
output = m_akaze_tracker->getOutputData();
} else if (this->m_trackerType == webarkit::TRACKER_TYPE::ORB_TRACKER) {
output = m_orb_tracker->getOutputData();
} else {
throw std::invalid_argument("Invalid tracker type");
}
output = m_tracker->getOutputData();
emscripten::val corners = emscripten::val::array();
for (auto i = 9; i < 17; i++) {
corners.call<void>("push", output[i]);
Expand All @@ -60,15 +35,7 @@ emscripten::val WebARKit::getCorners() {
}

bool WebARKit::isValid() {
auto valid = false;
if (this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER) {
valid = m_akaze_tracker->isValid();
} else if (this->m_trackerType == webarkit::TRACKER_TYPE::ORB_TRACKER) {
valid = m_orb_tracker->isValid();
} else {
throw std::invalid_argument("Invalid tracker type");
}
return valid;
return m_tracker->isValid();
}

#include "bindings.cpp"
17 changes: 8 additions & 9 deletions emscripten/WebARKitJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#include <AR2/config.h>
#include <AR2/imageFormat.h>
#include <AR2/util.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitAkazeTracker.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitOrbTracker.h>
/*#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitAkazeTracker.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitOrbTracker.h>*/
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitTracker.h>
#include <WebARKitTrackers/WebARKitOpticalTracking/WebARKitEnums.h>
#include <emscripten.h>
#include <emscripten/val.h>
Expand All @@ -26,17 +27,16 @@ class WebARKit {
this->videoWidth = videoWidth;
this->videoHeight = videoHeight;
this->m_trackerType = trackerType;
if(this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER) {
m_akaze_tracker = std::make_unique<webarkit::WebARKitAkazeTracker>(webarkit::WebARKitAkazeTracker());
} else if(this->m_trackerType == webarkit::TRACKER_TYPE::ORB_TRACKER) {
m_orb_tracker = std::make_unique<webarkit::WebARKitOrbTracker>(webarkit::WebARKitOrbTracker());
m_tracker = std::make_unique<webarkit::WebARKitTracker>(webarkit::WebARKitTracker());
if(this->m_trackerType == webarkit::TRACKER_TYPE::AKAZE_TRACKER || webarkit::TRACKER_TYPE::ORB_TRACKER) {
m_tracker->initialize(trackerType);
} else {
throw std::invalid_argument("Invalid tracker type");
}
}

void initTrackerGray(emscripten::val data_buffer, int width, int height);
void processFrame(emscripten::val data_buffer, webarkit::ColorSpace colorSpace);
void processFrame(emscripten::val data_buffer, webarkit::ColorSpace colorSpace);
emscripten::val getHomography();
emscripten::val getCorners();
bool isValid();
Expand All @@ -45,6 +45,5 @@ class WebARKit {
int videoWidth;
int videoHeight;
int m_trackerType;
std::unique_ptr<webarkit::WebARKitAkazeTracker> m_akaze_tracker;
std::unique_ptr<webarkit::WebARKitOrbTracker> m_orb_tracker;
std::unique_ptr<webarkit::WebARKitTracker> m_tracker;
};
2 changes: 0 additions & 2 deletions tools/makem.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ var ar2_sources = [

var webarkit_sources = [
'WebARKitOpticalTracking/WebARKitTracker.cpp',
'WebARKitOpticalTracking/WebARKitAkazeTracker.cpp',
'WebARKitOpticalTracking/WebARKitOrbTracker.cpp',
'WebARKitOpticalTracking/WebARKitConfig.cpp'
].map(function(src) {
return path.resolve(__dirname, WEBARKITLIB_ROOT + '/WebARKit/WebARKitTrackers/', src);
Expand Down

0 comments on commit e92312d

Please sign in to comment.