PySfMUtils
A Python package for interacting with Structure-from-Motion (SfM) projects.
Requirements
- Python 3.6+
- numpy 1.15+
Installation
The package is registered on PyPI. Released versions can be installed using pip:
pip install PySfMUtils
Development versions can be installed directly from the GitLab repository:
python -m pip install -e git+https://gitlab.com/educelab/sfm-utils.git
Usage
This package was originally designed to ease the process of importing pose priors into OpenMVG. It contains a format agnostic interface for defining an SfM Scene and its component parts:
import sfm_utils as sfm
# Create the scene
scene = sfm.Scene()
scene.root_dir = '/path/to/images/'
# Construct a view
view = sfm.View()
view.path = "view.jpg"
view.width = 800
view.height = 600
view.camera_make = 'PySfMUtils'
view.camera_model = 'Test Camera'
scene.add_view(view)
# Add the view's intrinsics
intrinsic = sfm.IntrinsicRadialK3()
intrinsic.width = view.width
intrinsic.height = view.height
intrinsic.focal_length = 50
intrinsic.sensor_width = 36
intrinsic.dist_params = [-0.1, -1.1, -1.1]
view.intrinsic = scene.add_intrinsic(intrinsic)
# Add the view's pose
pose = sfm.Pose()
pose.center = [10, 10, 10]
view.pose = scene.add_pose(pose)
# Write an OpenMVG project file
sfm.export_scene(path='sfm_data.json', scene=scene)
The exported sfm_data.json file can be passed directly to OpenMVG programs:
openMVG_main_ComputeFeatures -i sfm_data.json -o matches/
Export to AliceVision/Meshroom
To export a scene to an AliceVision/Meshroom compatible json file, use
sfm_utils.export_scene:
import sfm_utils as sfm
scene = sfm.Scene()
...
sfm.export_scene(path='SfMData.json', scene=scene, fmt=sfm.Format.ALICE_VISION)
The AliceVision json file matches an example file generated by Meshroom, but has not been tested for actually performing reconstructions. Contributions to this functionality are welcome.
Pose coordinate system
This package assumes a right-handed1 coordinate system,
in contrast to the left-handed2 system used by OpenMVG.
When exporting to OpenMVG, this package will premultiply the Pose.rotation
matrix with the following conversion matrix:
-1, 0, 0
0, 1, 0
0, 0, -1
To control this behavior, supply your own change of basis matrix using the
cob_matrix parameter of export_scene:
custom_cob = np.array([[-1, 0, 0], [0, -1, 0], [0, 0, 1]])
sfm_utils.export_scene(path='sfm_data.json', scene=scene, cob_matrix=custom_cob)
1: PySfMUtils coordinate system: -Z-forward, +Y-up, and +X-right
2: OpenMVG coordinate system: +Z-forward, +Y-up, and -X-right
Limitations
This package is a work-in-progress and currently implements only the most basic features needed to import pre-calibrated camera pose information into OpenMVG. We will gladly accept pull requests for new features. Known limitations in the current implementation are as follows:
- Only Views, Poses, and Intrinsics are supported. Feature points, control points, tracks, etc. are not provided.
- Only the Pinhole, RadialK3, and BrownT2 camera intrinsics are implemented.
- AliceVision support is untested.
- There is no support for loading pre-existing SfM files.
License
The software in this repository is licensed under the GNU General Public License v3.0. This project is free software: you can redistribute it and/or modify it under the terms of the GPLv3 or (at your option) any later version.
Release files for PySfMUtils 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| PySfMUtils-1.2.0.tar.gz | 8.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| PySfMUtils-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.3 kB
Release files / PySfMUtils-1.2.0.tar.gz
| Download URL | PySfMUtils-1.2.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b677f95ae0cd3749235fca536ee22636c21f2ce217b6b9a5ba2966df55d391b6
|
|
BLAKE2b-256 checksum How to use checksums |
91e038bc028dad717ca02666d09bb3704377251f270908c65fb093cde0acfa70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.12
|
Release files / PySfMUtils-1.2.0-py3-none-any.whl
| Download URL | PySfMUtils-1.2.0-py3-none-any.whl |
|---|---|
| Size | 24.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f8201bc2f127877cced57b2c8f4067ed31d4ddcf28ac6eed3b3d0bbb326c8f0
|
|
BLAKE2b-256 checksum How to use checksums |
8a14014c629b5413d85b645934b040a130d5c308178de3309ac7ec0f7982614a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.6.12
|