OpenPose 最新版のインストール,デモの実行(ソースコードを使用)(Windows 上)
【概要】
Windows で,OpenPose 最新版をソースコードからビルドして,インストールする.OpenPose のインストールには,複数の方法がある.
- OpenPose の最新版を検証,開発者に貢献したいなどの場合には, ソースコードからビルドして,インストールする.このページで説明する.
- OpenPose の安定版をインストールする手順は: 別ページ »で説明する.
OpenPoseは,人体,顔,手,足のキーポイントを検出するソフトウェアである. 多数のカメラを配置して,3次元のキーポイントを得る機能もある.
OpenPose の利用条件は,次のWebページで確認する.
https://flintbox.com/public/project/47343/
【目次】
【サイト内の関連情報】
前準備
Build Tools for Visual Studio 2026(ビルドツール)のインストール
Build Tools for Visual Studio 2026(ビルドツール)のインストールを行い、C/C++ コードのビルド環境を整える。
Build Tools for Visual Studio は,Visual Studio の IDE を含まない C/C++ コンパイラ,ライブラリ,ビルドツール等のコマンドライン向け開発ツールセットである。インストール済みの場合,この手順は不要である。 以下のコマンドは、Build Tools が未インストールの場合は winget で新規インストールし、インストール済みの場合は 【インストールコマンドの実行方法】 管理者権限でコマンドプロンプトを起動する(手順:Windows キーまたはスタートメニュー → 上記のコマンドでは、Build Tools 本体と Visual C++ 再頒布可能パッケージをインストールし、続いて以下のコンポーネントを追加している。 追加のコンポーネントが必要になった場合は Visual Studio Installer で個別にインストールできる。 インストール完了の確認 Visual Studio を必要とするとき Visual Studio の機能を必要とする場合は,追加インストールできる。
管理者権限のコマンドプロンプトで以下を実行する.管理者権限は,winget の --scope machine オプションでシステム全体にインストールするために必要となる.
管理者権限のコマンドプロンプトで以下を実行する.管理者権限のコマンドプロンプトを起動するには,Windows キーまたはスタートメニューから「
管理者権限のコマンドプロンプトで以下を実行する.管理者権限のコマンドプロンプトを起動するには,Windows キーまたはスタートメニューから「[Build Tools for Visual Studio 2026(ビルドツール)のインストール手順を見るには、ここをクリック]
Windows での Build Tools for Visual Studio 2026 のインストール
setup.exe modify でコンポーネントを追加する(バージョンは変更しない)。cmd と入力 → 右クリック → 「管理者として実行」)。そして、コマンド全体をコマンドプロンプトにコピー&ペーストする。REM ============================================================
REM Visual C++ 再頒布可能パッケージ (VCRedist 2015-)
REM ============================================================
winget install --scope machine --id Microsoft.VCRedist.2015+.x64 -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/quiet /norestart"
if not "%ERRORLEVEL%"=="0" ( color 0c & echo VCRedist のインストールに失敗しました & ping 127.0.0.1 -n 6 >nul & color )
REM ============================================================
REM Visual Studio Build Tools + Desktop development with C++
REM (VCTools、MSBuildTools、CMake連携、Clang、Windows 11 SDK)
REM ============================================================
REM 進行中のインストーラーを停止(ロック競合回避。対象プロセスが存在しない場合は
REM taskkillがエラーを返すが、これは想定内であるため出力のみ抑制する)
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
taskkill /F /IM msiexec.exe /T >nul 2>&1
REM Build Tools + Desktop development with C++(VCTools)+ 追加コンポーネント(一括)
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 --add Microsoft.VisualStudio.Component.VC.v143.x86.x64 --includeRecommended --quiet --norestart --nocache
if not "%ERRORLEVEL%"=="0" ( color 0c & echo Build Tools のコンポーネント追加に失敗しました & ping 127.0.0.1 -n 6 >nul & color )
) 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 --add Microsoft.VisualStudio.Component.VC.v143.x86.x64"
if not "%ERRORLEVEL%"=="0" ( color 0c & echo Build Tools のインストールに失敗しました & ping 127.0.0.1 -n 6 >nul & color )
)
REM
REM BuildTools のインストールパスを vswhere.exe で取得(メジャーバージョンに依存しない)
set "VSWHERE=C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
set "BT_PATH="
for /f "usebackq delims=" %P in (`"%VSWHERE%" -products Microsoft.VisualStudio.Product.BuildTools -property installationPath`) do set "BT_PATH=%P"
if not defined BT_PATH ( color 0c & echo Build Tools のインストールパスを取得できませんでした & ping 127.0.0.1 -n 6 >nul & color )
REM 破損時の修復(任意、動作がおかしくなった場合)
REM if defined BT_PATH "C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe" repair --installPath "%BT_PATH%" --quiet --norestart
REM 導入確認(インストールパスが表示されれば正常)
"%VSWHERE%" -products * -requires Microsoft.VisualStudio.Workload.VCTools -property installationPath
--includeRecommended により、MSVC コンパイラ、C++ AddressSanitizer、vcpkg、CMake ツール、Windows 11 SDK 等の推奨コンポーネントが含まれる)winget list Microsoft.VisualStudio.BuildToolsGit のインストール(Windows 上) [クリックして展開]
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"
CMakeのインストール(Windows 上) [クリックして展開]
cmd」と入力し,表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する.REM CMake をシステム領域にインストール
winget install --scope machine --id Kitware.CMake -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements --override "/qn /norestart ADD_CMAKE_TO_PATH=System"
7-Zip のインストール(Windows 上) [クリックして展開]
cmd」と入力し,表示された「コマンドプロンプト」を右クリックして「管理者として実行」を選択する.REM 7-Zip をシステム領域にインストール
winget install --scope machine --id 7zip.7zip -e --silent --disable-interactivity --force --accept-source-agreements --accept-package-agreements
REM 7-Zip のパス設定
powershell -NoProfile -Command "$p='C:\Program Files\7-Zip'; $c=[Environment]::GetEnvironmentVariable('Path','Machine'); if((Test-Path $p) -and $c -notlike \"*$p*\"){[Environment]::SetEnvironmentVariable('Path',\"$p;$c\",'Machine')}"
NVIDIA CUDA Toolkit 12.8のインストール
- 前提条件(NVIDIA CUDA Toolkit インストール前): NVIDIA GPU,NVIDIA ドライバ,および Build Tools for Visual Studio もしくは Visual Studio が必要である.
以下の手順を管理者権限のコマンドプロンプトで実行する
(手順:Windowsキーまたはスタートメニュー → cmd と入力 → 右クリック → 「管理者として実行」).
REM NVIDIA CUDA Toolkit 12.8 をシステム領域にインストール
winget install --scope machine --id Nvidia.CUDA --version 12.8 -e --silent --disable-interactivity --force --uninstall-previous --accept-source-agreements --accept-package-agreements --override "-s -n"
REM 環境変数TEMP, TMPの設定(一時ファイルの保存先を短いパスに変更)
mkdir C:\TEMP
set "TEMP_PATH=C:\TEMP"
setx TEMP "%TEMP_PATH%" /M >nul
setx TMP "%TEMP_PATH%" /M >nul
OpenPose のインストール
次のWebページの記述に従う.
https://github.com/CMU-Perceptual-Computing-Lab/openpose/tree/master/doc/installation
- 以下の手順を管理者権限のコマンドプロンプトで実行する
(手順:Windowsキーまたはスタートメニュー →
cmdと入力 → 右クリック → 「管理者として実行」). - ディレクトリを削除する
cd c:\ rmdir /s /q openpose
- OpenPose のソースコードをダウンロード
cd c:\ git clone --recursive https://github.com/CMU-Perceptual-Computing-Lab/openpose
- cmake の実行
cmake でのオプションについて
cmake のオプションの 「Visual Studio 17 2022」のところは, 使用する Visual Studio のバージョンにあわせること. Visual Studio 2026 のときは,「Visual Studio 18 2026」. Visual Studio 2022 のときは,「Visual Studio 17 2022」. Visual Studio 2019 のときは,「Visual Studio 16 2019」
cmake の実行手順例は次の通り
cd c:\ cd openpose rmdir /s /q build mkdir build cd build del CMakeCache.txt rmdir /s /q CMakeFiles cmake .. -A x64 -T host=x64 ^ -DCUDA_NVCC_FLAGS="-allow-unsupported-compiler" ^ -DDOWNLOAD_BODY_25_MODEL=ON ^ -DDOWNLOAD_BODY_COCO_MODEL=ON ^ -DDOWNLOAD_BODY_MPI_MODEL=ON
- cmake の実行結果の確認
* 下図のとおりになるとは限らない.設定がうまくいっていない場合は,1つ上の「cmake の実行」のところを,設定を変えてやり直す.
- ソースコードからビルドし,インストールする
cmake --build . --config release
- 結果の確認
エラーメッセージが出ていないことを確認する.
* 黄色の警告メッセージは無視してよい
- ファイルの配置の調整
cd c:\ cd openpose mkdir bin copy build\x64\release\*.* bin
- Windows の システム環境変数 Pathに,c:\openpose\build\bin を追加することにより,パスを通す.
Windows で,管理者権限でコマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー >
cmdと入力 > 右クリック > 「管理者として実行」).次のコマンドを実行
powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\openpose\build\bin\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
- Windows の システム環境変数 OPENPOSE_ROOTに,c:\openpose を設定.
Windows で,管理者権限でコマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー >
cmdと入力 > 右クリック > 「管理者として実行」).次のコマンドを実行
powershell -command "[System.Environment]::SetEnvironmentVariable(\"OPENPOSE_ROOT\", \"c:\openpose\", \"Machine\")" - デモプログラムを試す.そのために,
新しく,コマンドプロンプトを開く.
付属の動画ファイルを使用
cd c:\ cd openpose bin\OpenPoseDemo.exe --video examples\media\video.avi
- 付属の画像ファイルを使用
cd c:\ cd openpose bin\OpenPoseDemo.exe --image_dir examples\media
- パソコンにカメラがついている場合
cd c:\ cd openpose bin\OpenPoseDemo.exe
- オプションの確認
cd c:\ cd openpose bin\OpenPoseDemo.exe --help
(以下省略) - --face, --hand オプションを試してみる
【関連する外部ページ】: https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/quick_start.md
cd c:\ cd openpose bin\OpenPoseDemo.exe --image_dir examples\media --face --hand
- --write_json オプションを試してみる
* 末尾の「.」(半角ピリオド)はディレクトリの指定
cd c:\ cd openpose bin\OpenPoseDemo.exe --image_dir examples\media --write_json .
.json ファイルができていることがわかる
dir *.json