COLMAP 3.8 のインストールと3次元再構成の実行(COLMAP 3.8 を使用)(Windows 上)

COLMAP 3.8は,画像からの3次元再構成が可能なソフトウェアである.インストールはコマンドプロンプトを管理者で実行し,コマンドを実行して行うことができる.3次元再構成の実行は,画像データの準備後,コマンドプロンプトでの所定のコマンドを実行することで可能である.GUIも使用できる.

目次

  1. 前準備
  2. COLMAP 3.8 のインストールと3次元再構成の実行

COLMAP

COLMAP は 3次元再構成の機能を持ったソフトウェア.

文献

Johannes L. Schonberger, Jan-Michael Frahm, Structure-From-Motion Revisited, CVPR 2016, 2016

https://openaccess.thecvf.com/content_cvpr_2016/papers/Schonberger_Structure-From-Motion_Revisited_CVPR_2016_paper.pdf

サイト内の関連ページ

関連する外部ページ

前準備

Build Tools for Visual Studio 2026(ビルドツール)のインストール

Build Tools for Visual Studio 2026(ビルドツール)のインストールを行い、C/C++ コードのビルド環境を整える。

[Build Tools for Visual Studio 2026(ビルドツール)のインストール手順を見るには、ここをクリック]

Windows での Build Tools for Visual Studio 2026 のインストール

Build Tools for Visual Studio は,Visual Studio の IDE を含まない C/C++ コンパイラ,ライブラリ,ビルドツール等のコマンドライン向け開発ツールセットである。インストール済みの場合,この手順は不要である。

以下のコマンドは、Build Tools が未インストールの場合は winget で新規インストールし、インストール済みの場合は setup.exe modify でコンポーネントを追加する(バージョンは変更しない)。

インストールコマンドの実行方法

管理者権限コマンドプロンプトを起動する(手順:Windows キーまたはスタートメニュー → cmd と入力 → 右クリック → 「管理者として実行」)。そして、コマンド全体をコマンドプロンプトにコピー&ペーストする。

REM VC++ ランタイム
winget install --scope machine --id Microsoft.VCRedist.2015+.x64 -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/quiet /norestart"

REM ============================================================
REM Visual Studio Build Tools + Desktop development with C++
REM (VCTools、MSBuildTools、CMake連携、Clang、Windows 11 SDK)
REM ============================================================
REM 進行中のインストーラーを停止(ロック競合回避)
taskkill /F /IM vs_setup.exe /T >nul 2>&1
taskkill /F /IM vs_installer.exe /T >nul 2>&1
taskkill /F /IM vs_installerservice.exe /T >nul 2>&1

REM 未インストール時: winget で新規インストール
REM インストール済み時: setup.exe modify でコンポーネント追加(バージョンは変更しない)
winget list --id Microsoft.VisualStudio.BuildTools 2>nul | findstr /i "BuildTools" >nul 2>&1
if %ERRORLEVEL% EQU 0 (
    for /f "usebackq delims=" %P in (`"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -property installationPath`) do start /wait "" "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" modify --installPath "%P" --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.Component.Windows11SDK.26100 --includeRecommended --quiet --norestart --nocache
) else (
    winget install --scope machine --id Microsoft.VisualStudio.BuildTools -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "--quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --add Microsoft.VisualStudio.Workload.MSBuildTools --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.Component.Windows11SDK.26100"
)

REM 破損時の修復(任意、動作がおかしくなった場合)
REM "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" repair --installPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" --quiet --norestart

REM 導入確認(インストールパスが表示されれば正常)
"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -products * -requires Microsoft.VisualStudio.Workload.VCTools -property installationPath

上記のコマンドでは、Build Tools 本体と Visual C++ 再頒布可能パッケージをインストールし、続いて以下のコンポーネントを追加している。

上記以外の追加のコンポーネントが必要になった場合は Visual Studio Installer で個別にインストールできる。

インストール完了の確認

winget list Microsoft.VisualStudio.BuildTools

Visual Studio を必要とするとき

Visual Studio の機能を必要とする場合は,追加インストールできる。

Git のインストール(Windows 上) [クリックして展開]

管理者権限コマンドプロンプトで以下を実行する.管理者権限は,winget の --scope machine オプションでシステム全体にインストールするために必要となる.

REM Git をシステム領域にインストール
winget install --scope machine --id Git.Git -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS=""icons,ext\reg\shellhere,assoc,assoc_sh"" /o:PathOption=Cmd /o:CRLFOption=CRLFCommitAsIs /o:BashTerminalOption=MinTTY /o:DefaultBranchOption=main /o:EditorOption=VIM /o:SSHOption=OpenSSH /o:UseCredentialManager=Enabled /o:PerformanceTweaksFSCache=Enabled /o:EnableSymlinks=Disabled /o:EnableFSMonitor=Disabled"

Build Tools for Visual Studio 2022,NVIDIA ドライバ,NVIDIA CUDA ツールキット 11.8,NVIDIA cuDNN 8.9.7 のインストール(Windows 上)

サイト内の関連ページNVIDIA グラフィックスボードを搭載しているパソコンの場合には, NVIDIA ドライバNVIDIA CUDA ツールキットNVIDIA cuDNN のインストールを行う.

関連する外部ページ

COLMAP 3.8 のインストールと3次元再構成の実行

COLMAP 3.8 のインストール

  1. 以下の操作を管理者権限コマンドプロンプトで実行する (手順:Windowsキーまたはスタートメニュー → cmd と入力 → 右クリック → 「管理者として実行」)。

  2. ダウンロードとインストール

    次のコマンドを実行

    cd C:\
    mkdir COLMAP-3.8-windows-cuda
    cd COLMAP-3.8-windows-cuda
    curl -L -O https://github.com/colmap/colmap/releases/download/3.8/COLMAP-3.8-windows-cuda.zip
    powershell -command "Expand-Archive -DestinationPath .. -Path COLMAP-3.8-windows-cuda.zip"
    
  3. ファイルの確認

    dir コマンドを実行.bin,COLMAP.bat,lib ができていることを確認.

  4. https://demuc.de/colmapから,Vocabulary Trees をダウンロード

    次のコマンドを実行

    cd C:\
    cd COLMAP-3.8-windows-cuda
    curl -L -O https://demuc.de/colmap/vocab_tree_flickr100K_words32K.bin
    
  5. 必要であれば,次のページから,付属のデータセットをダウンロードできる.

    https://colmap.github.io/datasets.html

  6. Windowsシステム環境変数 Pathc:\COLMAP-3.8-windows-cuda\binc:\COLMAP-3.8-windows-cuda\lib追加することにより,パスを通す

    Windows で,管理者権限コマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー > cmd と入力 > 右クリック > 「管理者として実行」)。

    次のコマンドを実行

    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\COLMAP-3.8-windows-cuda\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\COLMAP-3.8-windows-cuda\lib\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
    

3次元再構成の実行

動作確認のため COLMAP を実行してみる

  1. Windows で,コマンドプロンプトを実行.
  2. 画像データの準備

    ここでは, https://www.kkaneko.jp/sample/potato/potato_image.zip をダウンロードし,その中の画像ファイルを images ディレクトリに置いている.

    cd C:\
    cd COLMAP-3.8-windows-cuda
    curl -O https://www.kkaneko.jp/sample/potato/potato_image.zip
    powershell -command "Expand-Archive -DestinationPath . -Path potato_image.zip"
    mkdir images
    cd images
    move ..\potato_image\*.JPG .
    
  3. COLMAP による3次元再構成
    cd C:\
    cd COLMAP-3.8-windows-cuda
    colmap automatic_reconstructor --workspace_path . --image_path ./images
    
  4. 終了の確認

    エラーメッセージが出ていないこと.

    主なファイルの配置は次のようになる

       ├─database.db
       ├─dense
          ├─0
             ├─fused.ply
             ├─images
             ├─sparse
             ├─stereo
    
  5. Blender で .ply ファイルを開き確認する

GUI での利用

次のコマンドで起動

colmap gui

メニューの「Reconstruction」. Image foloder は3次元再構成した画像のあるディレクトリを指定. Vocabulary tree は先ほどダウンロードしたVocabulary treeを指定. Workspace folder, Mask folder は,すでに存在するディレクトリを指定する(処理で使用される)

こまなく段階を分けて処理したい場合

colmap image_undistorter --image_path images --input_path sparse/0 --output_path dense --output_type COLMAP
colmap patch_match_stereo --workspace_path dense --workspace_format COLMAP --PatchMatchStereo.geom_consistency true
colmap stereo_fusion --workspace_path dense --workspace_format COLMAP --input_type geometric --output_path dense/fused.ply
colmap poisson_mesher --input_path dense/fused.ply --output_path dense/meshed-poisson.ply
colmap delaunay_mesher --input_path dense --output_path dense/meshed-delaunay.ply