Skip to content

Commit

Permalink
Merge pull request #1 from meyerls/meyerls
Browse files Browse the repository at this point in the history
Meyerls
  • Loading branch information
meyerls authored Nov 28, 2022
2 parents 118dced + 7446382 commit e663baf
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 70 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
name: Python package

on: [push]
name: Test COLMAP Wrapper

on: [ push ]
jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
python-version: [ "3.8", "3.9" ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- run: git checkout ${{ github.ref_name }}
- name: 'Install dependencies'
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
pip install .
- name: 'Install ExifTools'
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test aruco estimator
wget https://exiftool.org/Image-ExifTool-12.51.tar.gz
gzip -dc Image-ExifTool-12.51.tar.gz | tar -xf -
cd Image-ExifTool-12.51
perl Makefile.PL
make test
sudo make install
- name: 'Test COLMAP wrapper'
run: |
echo 1
#python scale_estimator.py --test_data
exiftool -ver
python colmap_wrapper/test.py
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
.idea/
data/
test.py
#test.py
colmap_wrapper.egg-info
dist

!colmap_wrapper/data
colmap_wrapper/data/bunny_reco
*/**/*.zip
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -139,4 +141,4 @@ dmypy.json
.settings/

# Test Files
test*.py
#test*.py
33 changes: 25 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ pip install colmap-wrapper

### Single Reconstruction

To visualize a single reconstruction from COLMAP, the following code reads all colmap elements and visualizes them.
To visualize a single reconstruction from COLMAP, the following code reads all colmap elements and visualizes them. For
this case an example reconstruction project is provided as shown at the top of the readme.

```python
from colmap_wrapper.colmap import COLMAP
from colmap_wrapper.visualization import ColmapVisualization
from colmap_wrapper.data.download import Dataset

project = COLMAP(project_path="[PATH2COLMAP_PROJECT]", load_images=True, image_resize=0.3)
downloader = Dataset()
downloader.download_bunny_dataset()

project = COLMAP(project_path=downloader.file_path, load_images=True, image_resize=0.3)

colmap_project = project.projects

# Acess camera, images and sparse + dense point cloud
camera = project.cameras
images = project.images
sparse = project.get_sparse()
dense = project.get_dense()
camera = colmap_project.cameras
images = colmap_project.images
sparse = colmap_project.get_sparse()
dense = colmap_project.get_dense()

# Visualize COLMAP Reconstruction
project_vs = ColmapVisualization(project)
project_vs = ColmapVisualization(colmap_project)
project_vs.visualization(frustum_scale=0.7, image_type='image')
```

Expand All @@ -69,7 +76,17 @@ for COLMAP_MODEL in project.projects:
## References

* [PyExifTool](https://github.com/sylikc/pyexiftool): A library to communicate with the [ExifTool](https://exiftool.org)
command- application. If you have trouble installing it please refer to the PyExifTool-Homepage.
command- application. If you have trouble installing it please refer to the PyExifTool-Homepage.
```bash
# For Ubuntu users:
wget https://exiftool.org/Image-ExifTool-12.51.tar.gz
gzip -dc Image-ExifTool-12.51.tar.gz | tar -xf -
cd Image-ExifTool-12.51
perl Makefile.PL
make test
sudo make install
```

* To Visualize the Reconstruction on an OSM-Map the implementation
from [GPS-visualization-Python](https://github.com/tisljaricleo/GPS-visualization-Python) is used. A guide to
visualize gps data can be found
Expand Down
1 change: 1 addition & 0 deletions colmap_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

from colmap_wrapper.colmap import *
from colmap_wrapper.visualization import *
from colmap_wrapper.data import *

This file was deleted.

This file was deleted.

This file was deleted.

7 changes: 6 additions & 1 deletion colmap_wrapper/colmap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2022 Lukas Meyer
Licensed under the MIT License.
See LICENSE file for more information.
"""

from colmap_wrapper.colmap.utils import *
from colmap_wrapper.colmap.bin import *
from colmap_wrapper.colmap.camera import *
from colmap_wrapper.colmap.colmap import *
from colmap_wrapper.colmap.colmap_project import *
from colmap_wrapper.colmap.colmap_project import *
8 changes: 6 additions & 2 deletions colmap_wrapper/colmap/bin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2022 Lukas Meyer
Licensed under the MIT License.
See LICENSE file for more information.
'''
Code for COLMAP readout borrowed from https://github.com/uzh-rpg/colmap_utils/tree/97603b0d352df4e0da87e3ce822a9704ac437933
'''
"""

# Built-in/Generic Imports
import struct
Expand Down
20 changes: 11 additions & 9 deletions colmap_wrapper/colmap/colmap.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Copyright (c) 2022 Lukas Meyer
Licensed under the MIT License.
See LICENSE file for more information.
Code for COLMAP readout borrowed from https://github.com/uzh-rpg/colmap_utils/tree/97603b0d352df4e0da87e3ce822a9704ac437933
"""


# Built-in/Generic Imports
from pathlib import Path

# Libs
import numpy as np

# Own modules
from colmap_wrapper.colmap import (read_array, generate_colmap_sparse_pc)
from colmap_wrapper.colmap.colmap_project import COLMAPProject


Expand Down Expand Up @@ -73,11 +74,15 @@ def projects(self, projects):
if __name__ == '__main__':
from colmap_wrapper.visualization import ColmapVisualization

MODE = 'multi'
MODE = 'single'

if MODE == "single":
project = COLMAP(project_path='/home/luigi/Dropbox/07_data/misc/bunny_data/reco_DocSem2',
dense_pc='fused.ply',
from colmap_wrapper.data.download import Dataset

downloader = Dataset()
downloader.download_bunny_dataset()

project = COLMAP(project_path=downloader.file_path,
load_images=True,
load_depth=True,
image_resize=0.4)
Expand Down Expand Up @@ -105,6 +110,3 @@ def projects(self, projects):
dense = COLMAP_MODEL.get_dense()
project_vs = ColmapVisualization(colmap=COLMAP_MODEL)
project_vs.visualization(frustum_scale=0.8, image_type='image')

# project.visualization(frustum_scale=0.8, image_type='image', model_idx=MODEL_IDX)
#project.visualization_all(frustum_scale=0.8, image_type='image')
39 changes: 17 additions & 22 deletions colmap_wrapper/colmap/colmap_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

# Built-in/Generic Imports

import warnings
from pathlib import Path

# Libs
Expand All @@ -20,16 +20,6 @@
read_points3d_binary, read_images_binary, generate_colmap_sparse_pc)


# try:
# from colmap_wrapper.utils import *
# from colmap_wrapper.visualization import *
# from colmap_wrapper.bin import *
# except ImportError:
# from .utils import *
# from .visualization import *
# from .bin import *


class PhotogrammetrySoftware(object):
def __init__(self, project_path):
self._project_path = project_path
Expand Down Expand Up @@ -187,13 +177,17 @@ def __read_project_init_file(self):
return {}

def __read_exif_data(self):
for image_idx in self.images.keys():
self.images[image_idx].original_filename: Path = Path(self.project_ini['Basic']['image_path']) / \
self.images[
image_idx].name
with exiftool.ExifToolHelper() as et:
metadata = et.get_metadata(self.images[image_idx].original_filename.__str__())
self.images[image_idx].exifdata = metadata[0]
try:
for image_idx in self.images.keys():
self.images[image_idx].original_filename: Path = Path(self.project_ini['Basic']['image_path']) / \
self.images[
image_idx].name
with exiftool.ExifToolHelper() as et:
metadata = et.get_metadata(self.images[image_idx].original_filename.__str__())
self.images[image_idx].exifdata = metadata[0]
except exiftool.exceptions.ExifToolExecuteError as error:
# traceback.print_exc()
warnings.warn("Exif Data could not be read.")

def __add_infos(self):
"""
Expand Down Expand Up @@ -335,12 +329,13 @@ def __read_dense_model(self):


if __name__ == '__main__':
# project = COLMAP(project_path='data/door', load_images=True, load_depth=True, image_resize=0.4)
# project = COLMAP(project_path='/home/luigi/Dropbox/07_data/CherrySLAM/test_sequences/01_easy/reco/',
from colmap_wrapper.data.download import Dataset
from colmap_wrapper.visualization import ColmapVisualization

project = COLMAPProject(project_path='/home/luigi/Dropbox/07_data/misc/bunny_data/reco_DocSem2',
dense_pc='fused.ply',
downloader = Dataset()
downloader.download_bunny_dataset()

project = COLMAPProject(project_path=downloader.file_path,
load_images=True,
load_depth=True,
image_resize=0.4)
Expand Down
4 changes: 4 additions & 0 deletions colmap_wrapper/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from colmap_wrapper.data.download import *
104 changes: 104 additions & 0 deletions colmap_wrapper/data/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (c) 2022 Lukas Meyer
Licensed under the MIT License.
See LICENSE file for more information.
"""

# Built-in/Generic Imports
# ...

# Libs
import os
from zipfile import ZipFile
from tqdm import tqdm
import urllib.request

# Own modules
# ...

EXISTS = True
NON_EXIST = False


class DownloadProgressBar(tqdm):
def update_to(self, b=1, bsize=1, tsize=None):
if tsize is not None:
self.total = tsize
self.update(b * bsize - self.n)


def download(url: str, output_dir: str, overwrite: bool = False):
filename = os.path.join(output_dir, url.split('/')[-1])

if os.path.exists(filename) and not overwrite:
print('{} already exists in {}'.format(url.split('/')[-1], output_dir))
else:
with DownloadProgressBar(unit='B',
unit_scale=True,
miniters=1,
desc=url.split('/')[-1]) as t:
urllib.request.urlretrieve(url, filename=filename, reporthook=t.update_to)

return filename


def extract(filename: str, output_dir: str):
# opening the zip_file file in READ mode
with ZipFile(filename, 'r') as zip_file:
# printing all the contents of the zip_file file
# zip_file.printdir()

# extracting all the files
print('Extracting all the files now...')
zip_file.extractall(path=output_dir)
print('Done!')


class Dataset:
def __init__(self):
self.dataset_name = None
self.dataset_path = None
self.filename = None
self.url = None
self.data_path = None
self.scale = None # in cm

def __check_existence(self, output_directory, dataset_name):
if output_directory == os.path.abspath(__file__):
self.data_path = os.path.abspath(os.path.join(output_directory, '..', '..', 'data'))
else:
self.data_path = os.path.join(output_directory, 'data')

os.makedirs(self.data_path, exist_ok=True)

if os.path.exists(os.path.join(self.data_path, dataset_name)):
return EXISTS
else:
return NON_EXIST

def download_bunny_dataset(self, output_path: str = os.path.abspath(__file__), overwrite: bool = False):

self.url = 'https://faubox.rrze.uni-erlangen.de/dl/fiN75KeHkAB78x3MTexFMu/bunny_reco.zip'

self.dataset_name ='bunny'

existence = self.__check_existence(output_directory=output_path, dataset_name=self.dataset_name)

if existence == NON_EXIST:
self.filename = download(url=self.url, output_dir=self.data_path, overwrite=overwrite)
extract(filename=self.filename, output_dir=self.data_path)
else:
print('Dataset {} already exists at location {}'.format(self.dataset_name, self.data_path))

self.file_path = os.path.abspath(
os.path.join(self.data_path, self.url.split('/')[-1].split('.zip')[0]))
return self.file_path


if __name__ == '__main__':
downloader = Dataset()
downloader.download_bunny_dataset()

print('Saved at {}'.format(downloader.dataset_path))
Loading

0 comments on commit e663baf

Please sign in to comment.