Skip to content

[WIP] Feature multi marker #6

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

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(COMPRESSION_RELEASE_FLAG " -Oz ")
set(DEBUG_FLAGS " -g -sASSERTIONS=1 --profiling -s DEMANGLE_SUPPORT=1 ")
set(ES6_BUILD " -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -sEXPORT_NAME=ARtoolKitPlus -s MODULARIZE=1 ")
set(ES6_BUILD_SM " -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -sEXPORT_NAME=TrackerSingleMarker -s MODULARIZE=1 ")
set(ES6_BUILD_TM " -s EXPORT_ES6=1 -s USE_ES6_IMPORT_META=0 -sEXPORT_NAME=TrackerMultiMarker -s MODULARIZE=1 ")
set(MEMORY_OPTION " -s TOTAL_MEMORY=268435456 -s ALLOW_MEMORY_GROWTH=1 ")
set(FLAGS " -sFORCE_FILESYSTEM -s EXPORTED_RUNTIME_METHODS=['FS'] ")
set(INCLUDES " -I../emscripten/artoolkitplus ")
Expand Down Expand Up @@ -36,6 +37,12 @@ if(CMAKE_BUILD_TYPE STREQUAL Release)
target_link_libraries(trackerSM_ES6 ${ARToolKitPlus} )
endif()
set_target_properties(trackerSM_ES6 PROPERTIES LINK_FLAGS " ${COMPRESSION_RELEASE_FLAG} ${MEMORY_OPTION} ${INCLUDES} ${SRC} ${LINK_LIBS} --bind ${ES6_BUILD_SM} ${SINGLE_FILE} ${FLAGS} ")
add_executable(trackerMM_ES6 emscripten/trackerMM.cpp)
if(!LINK_LIBS)
add_dependencies(trackerMM_ES6 ARToolKitPlus)
target_link_libraries(trackerMM_ES6 ${ARToolKitPlus} )
endif()
set_target_properties(trackerMM_ES6 PROPERTIES LINK_FLAGS " ${COMPRESSION_RELEASE_FLAG} ${MEMORY_OPTION} ${INCLUDES} ${SRC} ${LINK_LIBS} --bind ${ES6_BUILD_TM} ${SINGLE_FILE} ${FLAGS} ")
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
add_executable(artoolkitplus_em_ES6_debug emscripten/artoolkitplus_em.cpp )
if(!LINK_LIBS)
Expand Down
2 changes: 1 addition & 1 deletion build/artoolkitplus_em_ES6_debug.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions build/trackerMM_ES6.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/trackerSM_ES6.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/trackerSM_ES6_debug.js

Large diffs are not rendered by default.

701 changes: 700 additions & 1 deletion dist/ARToolKitPlus.js

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions emscripten/trackerMM-bindings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <emscripten/bind.h>

using namespace emscripten;

EMSCRIPTEN_BINDINGS(TrackerMM) {
register_vector<int>("vector_int");

enum_<PIXEL_FORMAT>("PIXEL_FORMAT")
.value("PIXEL_FORMAT_ABGR", PIXEL_FORMAT_ABGR)
.value("PIXEL_FORMAT_BGRA", PIXEL_FORMAT_BGRA)
.value("PIXEL_FORMAT_BGR", PIXEL_FORMAT_BGR)
.value("PIXEL_FORMAT_RGBA", PIXEL_FORMAT_RGBA)
.value("PIXEL_FORMAT_RGB", PIXEL_FORMAT_RGB)
.value("PIXEL_FORMAT_RGB565", PIXEL_FORMAT_RGB565)
.value("PIXEL_FORMAT_LUM", PIXEL_FORMAT_LUM);

class_<TrackerMM>("TrackerMultiMarker")
.constructor<bool, int, int, int>()
.function("setup", &TrackerMM::setup)
.function("update", &TrackerMM::update)
.function("getMarkerId", &TrackerMM::getMarkerId)
.function("getMarkerPos", &TrackerMM::getMarkerPos)
.function("getMarkerVertexes", &TrackerMM::getMarkerVertexes)
.function("getModelViewMatrix", &TrackerMM::getMVMatrix)
.function("getPixelFormat", &TrackerMM::getPixelFormat)
.function("getProjectionMatrix", &TrackerMM::getProjectionMatrix)
.function("printCameraSettings", &TrackerMM::printCameraSettings)
.function("setBorderWidth", &TrackerMM::setBorderWidth)
.function("setMarkerMode", &TrackerMM::setMarkerMode)
.function("setPixelFormat", &TrackerMM::setPixelFormat)
.function("setThreshold", &TrackerMM::setThreshold)
.function("setUndistortionMode", &TrackerMM::setUndistortionMode);
};
138 changes: 138 additions & 0 deletions emscripten/trackerMM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "trackerMM.h"

void TrackerMM::setup(string camParamFile, string multiFile, int maxImagePatterns, int pattWidth,
int pattHeight, int pattSamples, int maxLoadPatterns) {
// ---------------------------------- AR TK+ STUFF - ripped from the single
// marker demo app

// create a tracker that does:
// - "pattWidth" x "pattHeight" sized marker images (6x6 required for binary
// markers)
// - samples at a maximum of 6x6
// - works with luminance (gray) images
// - can load a maximum of "maxLoadPatterns" non-binary pattern
// - can detect a maximum of "maxImagePatterns" patterns in one image
tracker = make_unique<ARToolKitPlus::TrackerMultiMarker>(
this->mWidth, this->mHeight, maxImagePatterns, pattWidth, pattHeight,
pattSamples, maxLoadPatterns);

// set a logger so we can output error messages
// tracker->setLogger(&logger);
// - works with luminance (gray) images
tracker->setPixelFormat(ARToolKitPlus::PIXEL_FORMAT_LUM);

tracker->setImageProcessingMode(ARToolKitPlus::IMAGE_FULL_RES);

// Initialize a Single Marker Tracker with
// Camera and near and far clipping values for the OpenGL projection matrix
/*if (!tracker->init(camParamFile.c_str(), multiFile.c_str(), 1.0f, 1000.0f)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had troble loading both files, now i will develop my init function:
in this commit only load the camera but we can load the multi file and calib file separately.


printf("ERROR: init() failed\n");
tracker = nullptr;

return;
}*/
if (!tracker->loadCameraFile(camParamFile.c_str(), 1.0f, 1000.0f)) {
printf("ERROR: loadCameraFile() failed\n");
tracker = nullptr;

return;
}
tracker->getCamera()->printSettings();
// define size of the marker
//tracker->setPatternWidth(this->mPatternWidth);
// multimarkers since it doesnt seem to have this option.

// the marker in the BCH test image has a thin border...
tracker->setBorderWidth(this->useBCH ? 0.125f : 0.250f);
// tracker->setBorderWidth(0.250f);

// set a threshold. alternatively we could also activate automatic
// thresholding
tracker->setThreshold(85);

// let's use lookup-table undistortion for high-speed
// note: LUT only works with images up to 1024x1024
tracker->setUndistortionMode(ARToolKitPlus::UNDIST_LUT);
// tracker->setUndistortionMode(ARToolKitPlus::UNDIST_STD);

// RPP is more robust than ARToolKit's standard pose estimator
tracker->setPoseEstimator(ARToolKitPlus::POSE_ESTIMATOR_RPP);

// switch to simple ID based markers
// use the tool in tools/IdPatGen to generate markers
tracker->setMarkerMode(useBCH ? ARToolKitPlus::MARKER_ID_BCH
: ARToolKitPlus::MARKER_ID_SIMPLE);
// tracker->activateVignettingCompensation(true);

// tracker->setUseDetectLite(false);
}

int TrackerMM::getMarkerId() { return marker_info->id; };

emscripten::val TrackerMM::getMarkerPos() {
emscripten::val obj = emscripten::val::object();
obj.set("x", marker_info->pos[0]);
obj.set("y", marker_info->pos[1]);
return obj;
}

emscripten::val TrackerMM::getMarkerVertexes() {
emscripten::val vertexes = emscripten::val::array();
for (auto x = 0; x < 4; x++) {
for (auto y = 0; y < 2; y++) {
vertexes.call<void>("push", marker_info->vertex[x][y]);
}
}
return vertexes;
}

int TrackerMM::update(emscripten::val data_buffer) {
vector<uint8_t> u8 =
emscripten::convertJSArrayToNumberVector<uint8_t>(data_buffer);
return tracker->calc(u8.data());
}

emscripten::val TrackerMM::getMVMatrix() {
emscripten::val arr = emscripten::val::array();
const ARFloat *ptr = tracker->getModelViewMatrix();
for (auto i = 0; i < 16; i++) {
arr.call<void>("push", ptr[i]);
}
return arr;
}

bool TrackerMM::setPixelFormat(PIXEL_FORMAT nFormat) {
return tracker->setPixelFormat(nFormat);
}

PIXEL_FORMAT TrackerMM::getPixelFormat() { return tracker->getPixelFormat(); }

emscripten::val TrackerMM::getProjectionMatrix() {
emscripten::val arr = emscripten::val::array();
const ARFloat *ptr = tracker->getProjectionMatrix();
for (auto i = 0; i < 16; i++) {
arr.call<void>("push", ptr[i]);
}
return arr;
}

void TrackerMM::printCameraSettings() {
tracker->getCamera()->printSettings();
};

void TrackerMM::setBorderWidth(ARFloat nFraction) {
tracker->setBorderWidth(nFraction);
}

void TrackerMM::setMarkerMode(MARKER_MODE nMarkerMode) {
tracker->setMarkerMode(nMarkerMode);
};

void TrackerMM::setThreshold(int nValue) { tracker->setBorderWidth(nValue); }

void TrackerMM::setUndistortionMode(UNDIST_MODE nMode) {
tracker->setUndistortionMode(nMode);
};

#include "TrackerMM-bindings.cpp"
58 changes: 58 additions & 0 deletions emscripten/trackerMM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <ARToolKitPlus/TrackerMultiMarker.h>
#include <ARToolKitPlus/ar.h>
#include <algorithm>
#include <emscripten/val.h>

using namespace ARToolKitPlus;
using namespace std;

class TrackerMM {
public:
TrackerMM(bool useBCH, int width, int height, int patternWidth) {
this->useBCH = useBCH;
this->mWidth = width;
this->mHeight = height;
this->mPatternWidth = patternWidth;
};
//~TrackerMM();

void setup(string camParamFile, string multiFile, int maxImagePatterns, int pattWidth,
int pattHeight, int pattSamples, int maxLoadPatterns);

int update(emscripten::val data_buffer);


emscripten::val getMVMatrix();

int getMarkerId();

emscripten::val getMarkerPos();

emscripten::val getMarkerVertexes();

bool setPixelFormat(PIXEL_FORMAT nFormat);

PIXEL_FORMAT getPixelFormat();

emscripten::val getProjectionMatrix();

void printCameraSettings();

void setBorderWidth(ARFloat nFraction);

void setMarkerMode(MARKER_MODE nMarkerMode);

void setThreshold(int nValue);

void setUndistortionMode(UNDIST_MODE nMode);

private:
bool useBCH;
int mWidth;
int mHeight;
int mPatternWidth;
vector<int> mMarkers;
ARMarkerInfo *marker_info;
int marker_num;
unique_ptr<ARToolKitPlus::TrackerMultiMarker> tracker;
};
Loading