Dlibは,数多くの機能を持つ C++ ライブラリ.機能には,機械学習,数値計算,グラフィカルモデル推論,画像処理,スレッド,通信,GUI,データ圧縮・一貫性,テスト,さまざまなユーティリティなどがある.Python API もある.
Dlib を用いた、次のプログラム(公開されているもの)を動かしてみます
利用条件などは利用者において確認してください
【サイト内の関連ページ】
先人に感謝
dlib の Web ページ: http://dlib.net/
Windows での Git のインストール: 別ページ »で説明
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
cmake のダウンロードページ: https://cmake.org/download/
cmake のインストールでは,システム環境変数 Path への追加を忘れないこと: C:\Program Files (x86)\GnuWin32\bin
sudo apt -y update sudo apt -y install cmake cmake-curses-gui
7-Zip 22.01 のインストール
Windows では, コマンドプロンプトを管理者として開き, 次のコマンドを実行することにより, 7-Zip 22.01 のインストールを行うことができる.
mkdir %HOMEPATH%\7zip cd %HOMEPATH%\7zip curl -O https://www.7-zip.org/a/7z2201-x64.exe .\7z2201-x64.exe call powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\7-Zip\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
【サイト内の関連ページ】
Windows での 7-Zip のインストール: 別ページ »で説明
【関連する外部ページ】
7-Zip の公式ページ: https://sevenzip.osdn.jp/
Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows での Visual Studio Community 2022 のインストール: 別ページ »で説明
Visual Studio Community 2022 に, Build Tools for Visual Studio 2022の機能が含まれている.
Windows での Build Tools for Visual Studio 2022 (ビルドツール for Visual Studio 2022) のインストール: 別ページ »で説明
【関連する外部ページ】
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行.
cd C:\ rmdir /s /q dlib git clone https://github.com/davisking/dlib
次のコマンドを実行.
cd C:\dlib cd python_examples curl -O http://dlib.net/files/mmod_human_face_detector.dat.bz2 curl -O http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2 curl -O http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2 curl -O http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2 "c:\Program Files\7-Zip\7z.exe" x mmod_human_face_detector.dat.bz2 "c:\Program Files\7-Zip\7z.exe" x dlib_face_recognition_resnet_model_v1.dat.bz2 "c:\Program Files\7-Zip\7z.exe" x shape_predictor_5_face_landmarks.dat.bz2 "c:\Program Files\7-Zip\7z.exe" x shape_predictor_68_face_landmarks.dat.bz2 del mmod_human_face_detector.dat.bz2 del dlib_face_recognition_resnet_model_v1.dat.bz2 del shape_predictor_5_face_landmarks.dat.bz2 del shape_predictor_68_face_landmarks.dat.bz2
コマンドプロンプトを管理者として実行: 別ページ »で説明
※ 「pip install ...」は,Python パッケージをインストールするための操作
python -m pip install -U opencv-python opencv-contrib-python
cd %HOMEPATH% rmdir /s /q imutils
cd %HOMEPATH% git clone https://github.com/jrosebr1/imutils cd imutils python setup.py build python setup.py install
python -c "import imutils; print( imutils.__version__ )"
mp4 形式動画ファイル: sample1.mp4
次のコマンドを実行.
cd C:\dlib cd python_examples curl -O https://www.kkaneko.jp/sample/face/sample1.mp4
謝辞:参考 Web ページ: https://github.com/TobiasRoeddiger/PupilTracker
利用条件などは必ず各自で確認してください
コマンドプロンプトを管理者として実行: 別ページ »で説明
cd %HOMEPATH% rmdir /s /q PupilTracker
cd %HOMEPATH% git clone https://github.com/TobiasRoeddiger/PupilTracker
次のコマンドを実行.
cd %HOMEPATH%\PupilTracker copy ..\dlib\python_examples\shape_predictor_68_face_landmarks.dat .
cd %HOMEPATH%\PupilTracker copy pupil_tracker.py a.py
エディタを使う
書き換え1つめ
書き換え前
書き換え後
cap = cv2.VideoCapture("c:/image/sample1.mp4")
書き換え2つめ
書き換え前
書き換え後
cv2.line(image,(int((bottom_left[0] + bottom_right[0]) / 2), lower_bound), (int((upper_left[0] + upper_right[0]) / 2), upper_bound),(0,0,255), 1)
Python プログラムの実行
python a.py -p shape_predictor_68_face_landmarks.dat
次のコマンドを実行.
copy a.py b.py
エディタを使う
書き換え前
書き換え後
cap = cv2.VideoCapture(0)
今度は、USB接続できるビデオカメラを準備し,パソコンに接続しておく.
python b.py -p shape_predictor_68_face_landmarks.dat