【サイト内の関連ページ】
【用語説明】
Dlibは,数多くの機能を持つ C++ ライブラリ.機能には,機械学習,数値計算,グラフィカルモデル推論,画像処理,スレッド,通信,GUI,データ圧縮・一貫性,テスト,さまざまなユーティリティなどがある.Python API もある.
Gitは,バージョン管理システム.ソースコードの管理や複数人での共同に役立つ.
【サイト内の関連ページ】
Windows での Git のインストール: 別ページ »で説明している.
【関連する外部ページ】
Git の公式ページ: https://git-scm.com/
7-Zipは,ファイル圧縮・展開(解凍)ツール
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドは,7-Zip圧縮・展開(解凍)ツールをインストールするものである.
winget install --scope machine 7zip.7zip powershell -command "$oldpath = [System.Environment]::GetEnvironmentVariable(\"Path\", \"Machine\"); $oldpath += \";c:\Program Files\7-Zip\"; [System.Environment]::SetEnvironmentVariable(\"Path\", $oldpath, \"Machine\")"
【関連する外部ページ】
【サイト内の関連ページ】
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
【インストールの判断】
Build Tools for Visual Studio は,開発ツールセットである. Visual Studio は統合開発環境であり,いくつかの種類があり,Build Tools for Visual Studioの機能を含むか連携して使用するものである.インストールは以下の基準で判断してください:
Visual Studio 2022 をインストールする際に,「C++ によるデスクトップ開発」を選択することで, Build Tools for Visual Studio 2022 の機能も一緒にインストールされる.
不明な点がある場合は,Visual Studio 全体をインストール を行う方が良い.
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行.
python -m pip uninstall -y dlib cd C:\ rmdir /s /q dlib git clone https://github.com/davisking/dlib cd C:\dlib python setup.py build --no DLIB_GIF_SUPPORT python setup.py install --no DLIB_GIF_SUPPORT
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python -c "import dlib; print( dlib.__version__ )"
次のコマンドを実行.
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
cd C:\dlib cd python_examples python cnn_face_detector.py mmod_human_face_detector.dat ..\examples\faces\2007_007763.jpg
コマンドプロンプトを管理者として実行: 別ページ »で説明
次のコマンドを実行する.
python -m pip install -U numpy scikit-image scikit-learn
cd %HOMEPATH% rmdir /s /q face_recognition git clone https://github.com/ageitgey/face_recognition cd face_recognition copy C:\dlib\python_examples\shape_predictor_68_face_landmarks.dat . python setup.py build python setup.py install
ここで行うこと
顔写真の枚数は多いほうが精度が高い
knn アルゴリズム。
ここでは,c:\w にコピーしている.
ディレクトリ名は何でも良いが、英語または数字のみを使い、分かりやすい名前がよい.
次の例では2つ作っているが、3つ以上作ってもよい。
画像ファイルの拡張子は .png もしくは .jpg もしくは .jpeg であること。
このプログラムでは,モデルとして hog を使う. ディープラーニングの CNN を使うように変更する場合には, face_locaions のところを,「face_locations(..., model="cnn")」のように書き換える.
画像サイズを変える(解像度を変える)など、少しの工夫で検出漏れがなくなったり、顔認識の精度が向上する可能性がある。
python face_recognition_knn.py を次のように書き換え.
「pil_image.save('result' + os.path.basename(img_path))」を追加
python face_recognition_knn.py を実行すると、次のように、結果がファイルに保存される.