Skip to content
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

Docker Container #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
82 changes: 82 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#FROM python
#FROM ubuntu:20.04
FROM nvidia/vulkan:1.1.121
RUN mkdir /app
WORKDIR /app
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y python3-pip
RUN apt-get install ffmpeg libsm6 libxext6 -y
RUN apt-get install -y libeigen3-dev
RUN apt-get install -y git
RUN /usr/bin/python3 -m pip install --upgrade pip
RUN /usr/bin/python3 -m pip install opencv-python
RUN /usr/bin/python3 -m pip install pygame
RUN /usr/bin/python3 -m pip install PyOpenGL
RUN /usr/bin/python3 -m pip install scikit-build

# Install CMake
#RUN apt install -y libprotobuf-dev protobuf-compiler
RUN apt-get install -y cmake
RUN apt-get install -y g++
RUN apt-get install -y freeglut3
RUN apt-get install -y freeglut3-dev
RUN apt-get install -y libglew-dev
RUN apt-get install -y binutils-gold
RUN apt-get install -y libsuitesparse-dev
RUN /usr/bin/python3 -m pip install scipy
RUN /usr/bin/python3 -m pip install scikit-image

# Install Eigen
WORKDIR /app
RUN git clone https://gitlab.com/libeigen/eigen.git
WORKDIR /app/eigen
RUN git checkout 3.3.4
RUN mkdir build
WORKDIR /app/eigen/build
RUN /usr/bin/cmake ..
RUN /usr/bin/make -j12
RUN make install

# Install pangolin
WORKDIR /app
#RUN git clone https://github.com/uoip/pangolin.git
RUN git clone https://github.com/AdityaNG/pangolin.git
WORKDIR /app/pangolin
RUN mkdir build
WORKDIR /app/pangolin/build
RUN /usr/bin/cmake ..
RUN /usr/bin/make -j12
#RUN /usr/bin/make
WORKDIR /app/pangolin/
RUN ls pangolin*.so
RUN /usr/bin/python3 setup.py install

# Install g2opy
WORKDIR /app
RUN git clone https://github.com/uoip/g2opy.git
WORKDIR /app/g2opy
RUN mkdir build
WORKDIR /app/g2opy/build
RUN /usr/bin/cmake ..
RUN /usr/bin/make -j12
RUN /usr/bin/make install
WORKDIR /app/g2opy/
RUN /usr/bin/python3 setup.py install

RUN /usr/bin/python3 -m pip install pandas

# Install twitchslam
WORKDIR /app
#RUN git clone https://github.com/geohot/twitchslam
#RUN git clone https://github.com/AdityaNG/twitchslam
COPY . /app/twitchslam
WORKDIR /app/twitchslam
RUN git checkout docker

RUN touch /root/.Xauthority
RUN apt-get -y install xauth

EXPOSE 8887
WORKDIR /app/twitchslam
#CMD /usr/bin/python3 slam.py
CMD sh run.sh
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,33 @@ A toy implementation of monocular SLAM written while livestreaming.

<img width=600px src="https://raw.githubusercontent.com/geohot/twitchslam/master/example.png" />

# Docker
Pull the docker container
```bash
docker pull adityang5/twitchslam
```

Or you can build the container using the following
```bash
docker build -t twitchslam .
```

You can run the container customizing the provided `twitchslam_docker.sh`
```bash
./twitchslam_docker.sh
```

## Install nvidia-docker2

```bash
xhost +local:docker

sudo apt install nvidia-docker2

sudo systemctl daemon-reload
sudo systemctl restart docker
```

Stream
-----

Expand All @@ -25,6 +52,8 @@ export F=500 # Focal length (in px)
# good example
F=525 ./slam.py videos/test_freiburgxyz525.mp4

F=525 python3 slam.py videos/test_freiburgxyz525.mp4

# ground truth
F=525 ./slam.py videos/test_freiburgrpy525.mp4 videos/test_freiburgrpy525.npz

Expand Down
3 changes: 2 additions & 1 deletion frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def extractFeatures(img):
pts = cv2.goodFeaturesToTrack(np.mean(img, axis=2).astype(np.uint8), 3000, qualityLevel=0.01, minDistance=7)

# extraction
kps = [cv2.KeyPoint(x=f[0][0], y=f[0][1], _size=20) for f in pts]
#kps = [cv2.KeyPoint(x=f[0][0], y=f[0][1], _size=20) for f in pts]
kps = [cv2.KeyPoint(x=f[0][0], y=f[0][1], size=20) for f in pts]
kps, des = orb.compute(img, kps)

# return pts and des
Expand Down
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xauth add $DISPLAY_COOKIE
#FSKIP=1 F=525 python3 slam.py /videos/test_freiburgxyz525.mp4
python3 slam.py /videos/$VIDEO_PATH
16 changes: 11 additions & 5 deletions slam.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python3

import os
import sys

sys.path.append("lib/macosx")
sys.path.append("lib/linux")

import time
import cv2
from display import Display2D, Display3D
Expand Down Expand Up @@ -210,7 +207,16 @@ def process_frame(self, img, pose=None, verts=None):

i = 0
while cap.isOpened():
ret, frame = cap.read()
ret, frame_old = cap.read()

#FRAME_SKIP = int(os.getenv("FSKIP")) +1
FRAME_SKIP = 1 if not os.getenv("FSKIP") else int(os.getenv("FSKIP"))
i=0
while ret and i<FRAME_SKIP:
frame = frame_old
ret, frame_old = cap.read()
i+=1

frame = cv2.resize(frame, (W, H))

print("\n*** frame %d/%d ***" % (i, CNT))
Expand Down
12 changes: 12 additions & 0 deletions twitchslam_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

xhost +local:docker
a=$(xauth list | head -n 1)

docker run --runtime=nvidia --gpus all --net=host \
-e DISPLAY --rm -v /tmp/.X11-unix -e NVIDIA_DRIVER_CAPABILITIES=all \
--mount type=bind,source=/home/aditya/VSProjects/twitchslam/videos,target=/videos \
--env DISPLAY_COOKIE="$a" \
--env VIDEO_PATH="test_drone.mp4" \
-e SEEK=100 -e FSKIP=5 -e F=1000 \
-it adityang5/twitchslam