Skip to content

Commit

Permalink
build libs with working example
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Nov 26, 2022
1 parent 143a0a8 commit 2163d6d
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 57 deletions.
104 changes: 104 additions & 0 deletions build.Unix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
function usage {
echo "Usage: $(basename $0) [--debug | --clean-em] ( libar | linux | emscripten | emscripten-all )"
exit 1
}

if [ $# -eq 0 ]; then
usage
fi

# -e = exit on errors
set -e

# Parse parameters
while test $# -gt 0
do
case "$1" in
libar) BUILD_LIBAR=1
;;
linux) BUILD_LINUX=1
;;
emscripten) BUILD_EM=1
;;
emscripten-all) BUILD_EM_ALL=1
;;
--clean-em) CLEAN_EM=1
;;
--*) echo "bad option $1"
usage
;;
*) echo "bad argument $1"
usage
;;
esac
shift
done

# Set OS-dependent variables.
OS=`uname -s`
ARCH=`uname -m`
TAR='/usr/bin/tar'
if [ "$OS" = "Linux" ]
then
CPUS=`/usr/bin/nproc`
TAR='/bin/tar'
# Identify Linux OS. Sets useful variables: ID, ID_LIKE, VERSION, NAME, PRETTY_NAME.
source /etc/os-release
# Windows Subsystem for Linux identifies itself as 'Linux'. Additional test required.
if grep -qE "(Microsoft|WSL)" /proc/version &> /dev/null ; then
OS='Windows'
fi
else
CPUS=1
fi

if [ $BUILD_LIBAR ] ; then
npm run build
fi

if [ $BUILD_LINUX ] ; then
g++ -std=gnu++17 -Isrc test.cpp -o test
g++ -std=gnu++17 -Isrc test.cpp -g -o test_d
fi

if [ $BUILD_EM ]; then
echo "Entering in build folder"
cd build
echo "Building jsfeatcpp.js with emscripten (emcmake)..."
emcmake cmake .. -DCMAKE_BUILD_TYPE="Release"
echo "Running command make..."
make
echo "Building jsfeatcpp_debug.js with emscripten (emcmake)..."
emcmake cmake .. -DCMAKE_BUILD_TYPE="Debug"
echo "Running command make..."
make
echo "Build completed."
fi

if [ $BUILD_EM_ALL ]; then
echo "Building libar libs"
npm run build
echo "Done!"
echo "preparing to build jsfeat libs..."
echo "Entering in build folder"
cd build
echo "Building jsfeatcpp.js with emscripten (emcmake)..."
emcmake cmake .. -DCMAKE_BUILD_TYPE="Release"
echo "Running command make..."
make
echo "Building jsfeatcpp_debug.js with emscripten (emcmake)..."
emcmake cmake .. -DCMAKE_BUILD_TYPE="Debug"
echo "Running command make..."
make
echo "Build completed."
fi

if [ $CLEAN_EM ]; then
echo "Entering in build folder"
cd build
echo "Cleaning build folder."
rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake Makefile
rm -rf ./jsfeatcpp.js ./jsfeatcpp_debug.js
echo "Removed files."
fi
2 changes: 1 addition & 1 deletion build/jsfeatES6cpp.js

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions build/jsfeatES6cpp_debug.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions build/jsfeatcpp_debug.js

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions emscripten/webarkitJsfeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,33 @@ emscripten::val load_jpeg_data(std::string filename) {
return out;
};

int yape06_detect(emscripten::val inputSrc, int w, int h) {
emscripten::val yape06_detect(emscripten::val inputSrc, int w, int h) {
auto src = emscripten::convertJSArrayToNumberVector<u_char>(inputSrc);
Imgproc imgproc;
Yape06 yape;
KeyPoints keypoints(w * h);

std::unique_ptr<KeyPoints> keypoints = std::make_unique<KeyPoints>(w * h);
std::unique_ptr<Matrix_t> lev0_img = std::make_unique<Matrix_t>(w, h, ComboTypes::U8C1_t);

imgproc.grayscale_internal<u_char, Matrix_t>(src.data(), w, h, lev0_img.get(), ColorSpace::COLOR_RGBA2GRAY);
imgproc.grayscale_internal<u_char, Matrix_t>(src.data(), w, h, lev0_img.get(), Colors::COLOR_RGBA2GRAY);
imgproc.gaussian_blur_internal(lev0_img.get(), lev0_img.get(), 5, 2);
auto kpc = yape.detect_internal(lev0_img.get(), keypoints&, 17);
auto obj = yape.detect_internal(lev0_img.get(), keypoints.get(), 17);

emscripten::val outObj = emscripten::val::object();
emscripten::val pointsArr = emscripten::val::array();
KPoint_t pt;
for (auto i = 0; i < obj.pts.kpoints.size(); i++) {
pt.x = obj.pts.kpoints[i].x;
pt.y = obj.pts.kpoints[i].y;
pt.level = obj.pts.kpoints[i].level;
pt.score = obj.pts.kpoints[i].score;
pt.angle = obj.pts.kpoints[i].angle;
pointsArr.call<void>("push", pt);
}
outObj.set("count", obj.count);
outObj.set("points", pointsArr);

return kpc.count;
return outObj;
};

}
Expand Down
14 changes: 2 additions & 12 deletions examples/yape06_detector_video_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@

window.addEventListener('jsfeatCpp-loaded', function (e) {
var jsfeatCpp = Module;
console.log(jsfeatCpp);
var imgproc = new jsfeatCpp.imgproc();
var yape06 = new jsfeatCpp.yape06();
yape06.laplacian_threshold = 30;
yape06.min_eigen_value_threshold = 25;
var size = 640 * 480;
corners = new jsfeatCpp.KeyPoints(size);
const U8_t = Module.Types.U8_t.value;
const C1_t = Module.Types.C1_t.value;
const COLOR_RGBA2GRAY = Module.Colors.COLOR_RGBA2GRAY.value;
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
var hint = {
audio: false,
Expand Down Expand Up @@ -111,11 +101,11 @@
ctx.drawImage(video, 0, 0, width, height);
var image_data = ctx.getImageData(0, 0, width, height);
var obj = jsfeatCpp.yape06_detect(image_data.data, width, height);
console.log("count is: ", obj);
// console.log("count is: ", obj);
var data_u32 = new Uint32Array(image_data.data.buffer);
// we convert to mono gray image, check both methods
//render_mono_image(img_u8.data, data_u32, width, height, 640)
//render_corners(obj.points, obj.count, data_u32, 640);
render_corners(obj.points, obj.count, data_u32, 640);
//moveBytes(img_u8.data, image_data.data, width, height);
ctx.putImageData(image_data, 0, 0);
requestAnimationFrame(process);
Expand Down

0 comments on commit 2163d6d

Please sign in to comment.