SlamJS
SlamJS is a free, opensource, easy-to-use and understand JavaScript library for camera pose estimation for VR, AR, XR use on mobile browsers. Warning: It is meant for experimentation and not yet in a production-ready state.
Install / Use
/learn @mukulbasu/SlamJSREADME
What is SlamJS
SlamJS is a free, opensource, easy-to-use and understand JavaScript library for camera pose estimation for VR, AR, XR use on mobile browsers. It is not yet in a production-ready state. However, the hope is that it provides a starting point for anyone wanting to experiment, play around with SLAM and its concepts.
Demo Video
https://github.com/mukulbasu/slamJS/assets/1706979/688b67ba-524e-4b4d-9edb-1957472d033f
Installation:
- Make sure gcc, cmake, yarn are installed.
- To build for Web, you have to set up emscripten. Follow the instructions from https://emscripten.org/docs/getting_started/downloads.html
Build and Running:
The application can be built and run locally against a test dataset or it can be run on the web browser. A sample dataset is provided in data/dataTest. The user can also choose to generate their own dataset for tests using the tools provided.
Building and running on Local machine:
This has been tested primarily on Ubuntu 22.04 LTS and Mac M2.
NOTE: Before building on Mac, open CMakeLists.txt and change set(LINUX TRUE) to set(LINUX FALSE). Also change set(APPLE_M FALSE) to set(APPLE_M TRUE).
Building for local machine:
- Go to top level directory
yarn installmkdir build; cd buildcmake ..make -j10Any time you update the libraries in the third_party folders, remember torm -rf *everything in build folder and then redo from step 3 (cmake and so on).
Also the libraries to be copied to third_party/lib are all opencv and can be generated from https://github.com/mukulbasu/opencv. Follow the cpp build process mentioned in the README and copy over the libraries from the build/lib/* and build/3rdparty/lib/* into the third_party/lib/opencv/<arch> folder.
Running on local machine:
The executable binary is created in build directory as slamJS. A sample configuration file config/slamConfigMobile.js is provided. A test dataset data/dataTest is also present.
- Go to top level directory
build/slamJS slamConfigMobile > debug/tmp- After this command completes running, move to Debugging.
Debugging:
The main debug website is built on React. The actual debug data on the website is served by a separate Node server (debug/server.js) that reads and serves data from debug/logs/debug.txt and debug/tmp. These files are generated once the command above is run.
- Go to top level directory
cd debugnpm install; source startServer.sh- Open another terminal and in that type
cd debug/react; npm install; npm start. - Open http://localhost:3000. Follow instructions on screen.
Building and running on Web:
This has been tested only on Android so far.
Building for Web:
- Activate emscripten environment.
- in the top level directory run: source build_wasm.sh
Running on Web:
Set up ADB wireless connection between your Android device and the local machine https://developer.android.com/tools/adb.
- Go to top level directory
- cd debug
- source startServer.sh
- Set up your android device for ADB connection.
- On your local machine, open Google Chrome and point it to
chrome://inspect/#devices. Make sure the port forwarding settings are set up to forward 8080 to localhost:8080. - On your Android Chrome browser open
http://localhost:8080/slamDemo.html - Click
Start ARto start the AR operation. Stop ARis not tested yet. Reload the page instead to retest.
Building third party libraries
Pre-built binaries for third_party libraries are provided for linux and Mac ARM architecture. For other architectures, you might have build the binaries yourself as follows:
There are 2 main libraries in the folder : 1) Libraries from OpenCV 2) Libraries from Suitesparse
- OpenCV: The libraries to be copied to third_party/lib are all opencv and can be generated from https://github.com/mukulbasu/opencv, branch: slamjs. Follow the cpp build process mentioned in the README and copy over the libraries from the build/lib/* and build/3rdparty/lib/* into the third_party/lib/opencv/<arch> folder.
- Suitesparse: Clone https://github.com/DrTimothyAldenDavis/SuiteSparse. a. You might need to install openBLAS on linux using - sudo apt-get install libopenblas-dev b. In the top level directory, run the command: CMAKE_OPTIONS="-DBLA_VENDOR=OpenBLAS" make -j20 c. Go to build folder inside each of the respective directories like - CHOLMOD, AMD etc and copy the library from there to third_party/lib/suitesparse/<arch>/
- G2O: The source code for the same is included in the third_party/src directory. Follow the instructions in README.md in third_party/src/go/ to build it for the required platform.
Running locally with your test data
Test data can be generated this way:
- Go to top level directory
mkdir datacd debugsource startServer.sh- On your mobile browser open - http://localhost:8080/test.html
