Repository with source code of SLAM indoor project
- OpenCV 4.8.0
- CMake 3.26.2
- Ceres-solver 2.2.0
- Optional: CUDA 12.3.2
- Install dependencies and tools:
sudo apt update
sudo apt install cmake libtbb2 g++ wget unzip ffmpeg libgtk2.0-dev libavformat-dev libavcodec-dev libavutil-dev libswscale-dev libtbb-dev libjpeg-dev libpng-dev libtiff-dev
sudo apt install libvtk7-dev
sudo apt install build-essential
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
#тут некоторые библиотеки могли не установится но пофиг
sudo apt install libeigen3-dev libgflags-dev libgoogle-glog-dev libatlas-base-dev libsuitesparse-
#тут вроде всё должно сработать
- Install Ceres-Solver
- Optional: Install CUDA
- Download sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.8.0.zip
unzip opencv.zip # files will be extracted to ./opencv-4.8.0
wget -O opencv-contrib.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.8.0.zip
unzip opencv-contrib.zip # files will be extracted to ./opencv_contrib-4.8.0
mkdir opencv-build
cd opencv-build
- Build & install
- See CUDA build options here
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.8.0/modules/ \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_opencv_sfm=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_TESTS=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON \
-D WITH_QT=ON \
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D WITH_FFMPEG=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_VTK=ON \
../opencv-4.8.0/
# Make sure FFMPEG and its modules marked "YES"
make -j8 # Number of jobs can be specified
sudo make install
sudo apt-get install libeigen3-dev libgflags-dev libgoogle-glog-dev
wget http://ceres-solver.org/ceres-solver-2.2.0.tar.gz
tar zxf ceres-solver-2.2.0.tar.gz
mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-2.2.0
make -j3
make test
sudo make install
Run to test:
./bin/simple_bundle_adjuster ../ceres-solver-2.2.0/data/problem-16-22106-pre.txt
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-3
Specify version for -D CUDA_ARCH_BIN=<version>
ragrding to your hardware using this site
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.8.0/modules/ \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_opencv_sfm=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_TESTS=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=ON \
-D WITH_QT=ON \
-D WITH_GTK=ON \
-D WITH_OPENGL=ON \
-D WITH_FFMPEG=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_VTK=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_CUDA=ON \
-D BUILD_opencv_cudacodec=OFF \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=OFF \
-D CUDA_ARCH_BIN=<version> \
-D WITH_GSTREAMER=ON \
../opencv-4.8.0/
# Make sure FFMPEG, its and CUDA (not cuDNN) modules marked "YES"
Install nlohmann-json
:
sudo apt install nlohmann-json3-dev
JSON config example (path to it should be specified as command line argument):
{
"onlyViz": true,
"calibrate": false,
"visualCalibration": true,
"calibrationPath": "./config/samsung-hv-2.xml",
"usePhotosCycle": false,
// "photosPathPattern": "/mnt/c/Users/bakug/YandexDisk/NSU/private/2-1/PAK/static/photos/samsung-room-new/_ (*).JPG",
"photosPathPattern": "/mnt/c/Users/bakug/YandexDisk/NSU/private/2-1/PAK/static/photos/samsung-4to3-tumbochka/*.JPG",
// "videoSourcePath" has an effect when "usePhotosCycle" is false
"videoSourcePath": "/mnt/c/Users/bakug/YandexDisk/NSU/private/2-1/PAK/static/samsung-new-tumbochka-fhd.MP4",
// If "onlyViz" is true program searches files with data in this folder
"outputDataDir": "./data/video_report/table-photos-CPU",
"threadsCount": 1,
"useUndistortion": false,
"requiredExtractedPointsCount": 10000,
"featureExtractingThreshold": 1,
"framesBatchSize": 210,
"skipFramesFromBatchHead": 0,
"useFirstFitInBatch": true,
"requiredMatchedPointsCount": 500,
// This block has an effect when "useFeatureTracker" is false
"useFM-SIFT-FLANN": true, // NORM_L2 in CUDA
"useFM-SIFT-BF": false, // NORM_L1 in CUDA
"useFM-ORB": false, // NORM_HAMMING in CUDA
"knnMatcherDistance": 0.7,
// Now this parameters are used only for the first pair of frames
"RPUseRANSAC": true,
"RPRANSACProb": 0.999,
"RPRANSACThreshold": 5.0,
"RPDistanceThreshold": 200.0,
"useBundleAdjustment": false,
// Next parameter also specifes max frames datas cnt which will be uploaded to global data at the one moment
"BAMaxFramesCnt": 8,
"BAThreadsCnt": 12,
// Priority of loss functions' flags is from top to bottom
"BAUseTrivialLossFunction": false,
"BAUseHuberLossFunction": true,
"BAHuberLossFunctionParameter": 4.0,
"BAUseCauchyLossFunction": false,
"BACauchyLossFunctionParameter": 4.0,
"BAUseArctanLossFunction": false,
"BAArctanLossFunctionParameter": 2.0,
"BAUseTukeyLossFunction": false,
"BATukeyLossFunctionParameter": 4.0
}
So now you can specify program working using configs and run using ./rebuild_and_run.sh <path/to/config.json
(write chmod a+x rebuild_and_run.sh
to make this file executable)
- For launching with CUDA use
rebuild_and_run_cuda.sh
Simple building:
cmake . -B build
make -C build -j8
CUDA building:
cmake . -B build -D USE_CUDA=YES
make -C build -j8
So now you can execute ./build/slam-indoor-code <path/to/config.json>