Browse Source

初始化提交

master
hesuicong 5 months ago
parent
commit
df61f3992d
  1. 16
      docker/Dockerfile
  2. 2
      docker/QUICK_START.sh
  3. 37
      docker/README.md
  4. 49
      docker/buildFromScratch.cmd
  5. 47
      docker/buildFromScratch.sh
  6. 95
      docker/buildInDocker.sh

16
docker/Dockerfile

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
ARG BASE_IMAGE=ubuntu:22.04
FROM $BASE_IMAGE
ARG MASTER=0
ARG USER_ID
ARG GROUP_ID
ARG CUDA=0
COPY buildInDocker.sh /tmp/buildInDocker.sh
RUN /tmp/buildInDocker.sh --cuda $CUDA --user_id $USER_ID --group_id $GROUP_ID --master $MASTER && rm /tmp/buildInDocker.sh
USER user
# Add binaries to path
ENV PATH /usr/local/bin/OpenMVS:$PATH

2
docker/QUICK_START.sh

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
docker pull openmvs/openmvs-ubuntu:latest
docker run -w /working -v $1:/working -it openmvs/openmvs-ubuntu:latest

37
docker/README.md

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
# Building & running openMVS using Docker
## Quick start:
1. Make sure docker is installed on your local machine.
2. Run the 'easy start' script, using the *full local path* to the folder with your SFM input files (perhaps output from openMVG or COLMAP):
```
./QUICK_START.sh /path/where/your/SFM/results/are
```
3. This will put you in a directory (inside the Docker container) mounted to the local path you specified so that you can run openMVS binaries on your own SFM inputs. Enjoy!
## Build from scratch:
You can also build the docker image from scratch based on the **Dockerfile** (perhaps with your own changes / modifications) using:
```sh
./buildFromScratch.sh --workspace /path/where/your/SFM/results/are
# With CUDA support:
./buildFromScratch.sh --cuda --workspace /path/where/your/SFM/results/are
# From master branch:
./buildFromScratch.sh --master --workspace /path/where/your/SFM/results/are
```
## NOTES
+ This workflow is pinned to build from [openMVS 1.0](https://github.com/cdcseacave/openMVS/releases/tag/v1.0). To build from a different release, or build from the latest commit on master, open up the Dockerfile and comment/uncomment as directed.
+ Display is also supported inside docker. If there are any issues with `xauth` make sure to run `xhost +` on your host machine.
+ Running openMVS binaries can use a lot of memory (depending on the size of your data set/ imagery). Docker has a relatively small default memory setting (2Gb on Mac). You will probably want to increase this before you run any larger workflows. From Docker desktop on Mac for example, just open the Docker GUI, go to the *Advanced* tab and increase via the slider:
![alt text][dockerParam]
[dockerParam]: https://i.stack.imgur.com/6iWiW.png "Recommend increasing memory to >4Gb"

49
docker/buildFromScratch.cmd

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
@echo off
set WORKSPACE=%CD%
set CUDA_BUILD_ARGS=
set CUDA_RUNTIME_ARGS=
set CUDA_CONTAINER_SUFFIX=
set MASTER_ARGS=
set DISPLAY_ARGS=
:parse_args
if "%~1" == "" goto build_image
if "%~1" == "--cuda" (
set "CUDA_BUILD_ARGS=--build-arg CUDA=1 --build-arg BASE_IMAGE=nvidia/cuda:11.8.0-devel-ubuntu22.04"
set "CUDA_RUNTIME_ARGS=--gpus all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics"
set "CUDA_CONTAINER_SUFFIX=-cuda"
shift
goto parse_args
)
if "%~1" == "--master" (
set "MASTER_ARGS=--build-arg MASTER=1"
shift
goto parse_args
)
if "%~1" == "--workspace" (
set "WORKSPACE=%~2"
shift
shift
goto parse_args
)
if "%~1" == "--gui" (
set "XSOCK=\\.\pipe\X11-unix"
set "XAUTH=%TEMP%\docker.xauth"
set "DISPLAY_ARGS=-e ^"DISPLAY=%COMPUTERNAME%:0.0^" -v ^"%XAUTH%:%XAUTH%:rw^" -e ^"XAUTHORITY=%XAUTH%^""
shift
goto parse_args
)
echo Unknown argument: %~1
exit /b 1
:build_image
echo Running with workspace: %WORKSPACE%
docker build -t="openmvs-ubuntu%CUDA_CONTAINER_SUFFIX%" --build-arg "USER_ID=1001" --build-arg "GROUP_ID=1001" %CUDA_BUILD_ARGS% %MASTER_ARGS% .
if errorlevel 1 exit /b 1
docker run %CUDA_RUNTIME_ARGS% --entrypoint bash --ipc=host --shm-size=4gb -w /work -v "%WORKSPACE%:/work" %DISPLAY_ARGS% -it openmvs-ubuntu%CUDA_CONTAINER_SUFFIX%
exit /b 0

47
docker/buildFromScratch.sh

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
#!/bin/bash
# Example use:
# ./buildFromScratch.sh --cuda --master --workspace /home/username/datapath/
WORKSPACE=$(pwd)
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--cuda)
CUDA_BUILD_ARGS="--build-arg CUDA=1 --build-arg BASE_IMAGE=nvidia/cuda:11.8.0-devel-ubuntu22.04"
CUDA_RUNTIME_ARGS="--gpus all -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics"
CUDA_CONTAINER_SUFFIX="-cuda"
shift
;;
--master)
MASTER_ARGS="--build-arg MASTER=1"
shift
;;
--workspace)
WORKSPACE=$2
shift
shift
;;
*)
echo "Unknown argument: $key"
exit 1
;;
esac
done
# no need to do `xhost +` anymore
XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist "$DISPLAY" | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -
DISPLAY_ARGS="--volume=$XSOCK:$XSOCK:rw --volume=$XAUTH:$XAUTH:rw --env=XAUTHORITY=$XAUTH --env=DISPLAY=unix$DISPLAY"
echo Running with workspace: "$WORKSPACE"
docker build -t="openmvs-ubuntu$CUDA_CONTAINER_SUFFIX" --build-arg "USER_ID=$(id -u)" --build-arg "GROUP_ID=$(id -g)" $CUDA_BUILD_ARGS $MASTER_ARGS .
docker run $CUDA_RUNTIME_ARGS --entrypoint bash --ipc=host --shm-size=4gb -w /work -v "$WORKSPACE:/work" $DISPLAY_ARGS -it openmvs-ubuntu$CUDA_CONTAINER_SUFFIX

95
docker/buildInDocker.sh

@ -0,0 +1,95 @@ @@ -0,0 +1,95 @@
#!/bin/bash
set -e
# Parse arguments to see if --cuda was passed and equals 1 or --master was passed and equals 1
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--cuda)
CUDA="$2"
shift
shift
;;
--master)
MASTER="$2"
shift
shift
;;
--user_id)
USER_ID="$2"
shift
shift
;;
--group_id)
GROUP_ID="$2"
shift
shift
;;
*)
echo "Unknown argument: $key"
exit 1
;;
esac
done
if [[ "$CUDA" == "1" ]]; then
echo "Building with CUDA support"
EIGEN_BUILD_ARG="-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/"
OPENMVS_BUILD_ARG="-DOpenMVS_USE_CUDA=ON -DCMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs/ -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ -DCUDA_INCLUDE_DIRS=/usr/local/cuda/include/ -DCUDA_CUDART_LIBRARY=/usr/local/cuda/lib64 -DCUDA_NVCC_EXECUTABLE=/usr/local/cuda/bin/"
else
echo "Building without CUDA support"
EIGEN_BUILD_ARG=""
OPENMVS_BUILD_ARG="-DOpenMVS_USE_CUDA=OFF"
fi
if [[ "$MASTER" == "1" ]]; then
echo "Pulling from master branch"
else
echo "Pulling from develop branch"
fi
apt-get update -yq
apt-get -yq install build-essential git cmake libpng-dev libjpeg-dev libtiff-dev libglu1-mesa-dev libglew-dev libglfw3-dev
# Eigen
git clone https://gitlab.com/libeigen/eigen --branch 3.4
mkdir eigen_build
cd eigen_build &&\
cmake . ../eigen $EIGEN_BUILD_ARG &&\
make && make install &&\
cd .. && rm -rf eigen_build eigen
# Boost
apt-get -y install libboost-iostreams-dev libboost-program-options-dev libboost-system-dev libboost-serialization-dev
# OpenCV
DEBIAN_FRONTEND=noninteractive apt-get install -yq libopencv-dev
# CGAL
apt-get -yq install libcgal-dev libcgal-qt5-dev
# VCGLib
git clone https://github.com/cdcseacave/VCG.git vcglib
# Build from stable openMVS release or the latest commit from the develop branch
if [[ "$MASTER" == "1" ]]; then
git clone https://github.com/cdcseacave/openMVS.git --branch master
else
git clone https://github.com/cdcseacave/openMVS.git --branch develop
fi
mkdir openMVS_build
cd openMVS_build &&\
cmake . ../openMVS -DCMAKE_BUILD_TYPE=Release -DVCG_ROOT=/vcglib $OPENMVS_BUILD_ARG
# Install OpenMVS library
make -j4 &&\
make install &&\
cd .. && rm -rf openMVS_build vcglib
# Set permissions such that the output files can be accessed by the current user (optional)
echo "Setting permissions for user $USER_ID:$GROUP_ID"
addgroup --gid $GROUP_ID user &&\
adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user
Loading…
Cancel
Save