A Python-based 3D reconstruction workflow that turns a video or a folder of images into a textured 3D mesh using OpenCV, COLMAP, and OpenMVS.
The main entry point is init_3d_reconstruction.py.
It performs the pipeline below:
- Read input from either a video file or a folder of still images.
- Extract or normalize images into
test/images. - Run COLMAP feature extraction.
- Remove images with too few detected features.
- Run COLMAP matching and sparse mapping.
- Convert the COLMAP model into OpenMVS format.
- Run OpenMVS dense reconstruction, meshing, refinement, and texturing.
- Export a textured mesh such as
scene_dense_mesh_refine_texture.obj.
init_3d_reconstruction.py: Main 3D reconstruction pipeline.prepare_3d.py: Older helper script for frame extraction and sparse COLMAP setup.extract_video_frames.py: Standalone utility that extracts frames from videos undervideo/intoextracted_frames/.requirements.txt: Python package dependencies used by the scripts.
The current scripts assume this layout under the repository root:
FrameForge3D/
|-- init_3d_reconstruction.py
|-- prepare_3d.py
|-- extract_video_frames.py
|-- requirements.txt
|-- test.mp4 # optional video input for the main pipeline
|-- image/ # optional image input folder for the main pipeline
|-- test/ # generated working directory
|-- colmap/ # local COLMAP installation
| `-- COLMAP.bat
`-- vcpkg/
`-- installed/x64-windows/tools/openmvs/
|-- InterfaceCOLMAP.exe
|-- DensifyPointCloud.exe
|-- ReconstructMesh.exe
|-- RefineMesh.exe
`-- TextureMesh.exe
- Windows is the primary target in the current script.
- Linux code paths exist, but they assume system packages and executable locations that you must verify manually.
Install one of the following:
- Python 3.10
- Python 3.11
- Python 3.12
Python 3.12 is recommended because this workspace already contains .cpython-312.pyc cache files.
You must have all of the following available before the main pipeline will run:
- COLMAP
- OpenMVS
- OpenCV Python bindings
- A C++ toolchain suitable for building OpenMVS dependencies when using
vcpkg
For Windows, the practical setup is:
- Visual Studio 2022 Build Tools or full Visual Studio with C++ workload
- CMake
- Git
- vcpkg
- COLMAP for Windows
These are not required for the main reconstruction pipeline, but are used by the secondary scripts:
ffmpeg.exeforprepare_3d.py- No additional Python packages beyond
requirements.txtfor the current secondary scripts.
Follow the steps in this order.
git clone https://github.com/SongChaeYoung98/FrameForge3D.git
cd FrameForge3DWindows PowerShell:
python -m venv .venv
.\.venv\Scripts\Activate.ps1Linux/macOS shell:
python -m venv .venv
source .venv/bin/activatepip install -r requirements.txtInstall COLMAP and place it so that this file exists:
colmap/COLMAP.bat
If your installation lives elsewhere, update the Windows path block near the top of init_3d_reconstruction.py.
Example:
git clone https://github.com/microsoft/vcpkg.gitPlace the cloned folder at:
FrameForge3D/vcpkg
Then bootstrap it.
Windows:
.\vcpkg\bootstrap-vcpkg.batLinux/macOS:
./vcpkg/bootstrap-vcpkg.shThe script expects the OpenMVS executables under:
vcpkg/installed/x64-windows/tools/openmvs/
A typical Windows installation command is:
.\vcpkg\vcpkg install openmvs:x64-windowsAfter installation, verify these files exist:
InterfaceCOLMAP.exeDensifyPointCloud.exeReconstructMesh.exeRefineMesh.exeTextureMesh.exe
Choose one input mode.
- Put a source video in the repository root, for example
test.mp4. - The script default is
DEFAULT_INPUT_MODE = "video".
- Put source images under
image/. - Change
DEFAULT_INPUT_MODEto"images", or callrun_pipeline(input_mode="images")manually.
This matters because some paths are hardcoded.
Open init_3d_reconstruction.py and confirm these values match your machine:
default_video_pathdefault_image_pathwork_dircolmap_batopenmvs_bin_dir
Also note:
extract_video_frames.pylooks for videos undervideo/and writes frames underextracted_frames/.prepare_3d.pyexpectsffmpeg.exenext to the script.
python init_3d_reconstruction.pyfrom pathlib import Path
from init_3d_reconstruction import run_pipeline
run_pipeline(
input_mode="video",
input_path=Path("test.mp4"),
n_frames=100,
rotate_180=True,
)For image input:
from pathlib import Path
from init_3d_reconstruction import run_pipeline
run_pipeline(
input_mode="images",
input_path=Path("image"),
rotate_180=False,
)create_dirs() creates the working folders such as:
test/imagestest/sparse
If input_mode == "video":
extract_frames()samples frames uniformly from the source video.rename_frames_with_timestamps()renames them to filenames such asframe_0001_000.000s.jpg.
If input_mode == "images":
prepare_captured_images()copies images into the working directory and optionally rotates them.
colmap_feature_extraction() creates the COLMAP database and runs feature extraction with a PINHOLE camera model.
remove_low_feature_images() opens the COLMAP SQLite database and removes images whose keypoint count is below the configured threshold.
The script then runs:
colmap_exhaustive_matching()colmap_mapper()
This produces a sparse COLMAP model under test/sparse/0.
colmap_model_converter()converts COLMAP binary output to text.colmap_to_openmvs()usesInterfaceCOLMAPto createscene.mvs.
openmvs_dense_reconstruction() runs the OpenMVS tools in sequence:
DensifyPointCloudReconstructMeshRefineMeshTextureMesh
After a successful run, look inside test/ for files such as:
scene.mvsscene_dense.mvsscene_dense_mesh.mvsscene_dense_mesh_refine.mvsscene_dense_mesh_refine_texture.objscene_dense_mesh_refine_texture.png
- The current implementation uses hardcoded paths and local folder assumptions.
DEFAULT_ROTATE_180 = True, so source frames are rotated unless you change that option.organize_files()exists but is not currently called because it is commented out inrun_pipeline().- The repository does not currently track the heavy native dependencies such as
colmap/,vcpkg/, or media files. prepare_3d.pyappears to be an older prototype and is not the recommended entry point.
Check:
colmap/COLMAP.batexists.- The path in
colmap_batis correct. - Any required COLMAP DLLs are present beside the executable.
Check that OpenMVS was installed to:
vcpkg/installed/x64-windows/tools/openmvs/
If not, update openmvs_bin_dir in init_3d_reconstruction.py.
Check:
- The video path exists.
- OpenCV can decode the file format.
- The path in
default_video_pathis correct.
Possible causes:
- Too few source images.
- Low-texture or blurry frames.
- Wrong image orientation.
- COLMAP features were filtered too aggressively.
- Sparse mapping failed before OpenMVS started.
The most valuable cleanup would be replacing the hardcoded path block with command-line arguments or environment-based configuration, so the repository works without local file edits.