Mac: face_recognition

次のビデオを見ながら、数ヶ月の悩むのタネ、顔認識の課題は一気に吹き飛ばすの気がする。
https://www.youtube.com/watch?v=QSTnwsZj2yc
参考サイト:

face_recognitionのインストール

chen@Hong-Mac-mini Python % pip3 install face_recognition
Collecting face_recognition
  Downloading face_recognition-1.3.0-py2.py3-none-any.whl (15 kB)
Collecting dlib>=19.7
  Downloading dlib-19.20.0.tar.gz (3.2 MB)
     |████████████████████████████████| 3.2 MB 2.0 MB/s
Requirement already satisfied: numpy in /usr/local/lib/python3.8/site-packages (from face_recognition) (1.19.0)
Collecting Click>=6.0
  Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
     |████████████████████████████████| 82 kB 1.9 MB/s
Collecting Pillow
  Downloading Pillow-7.2.0-cp38-cp38-macosx_10_10_x86_64.whl (2.2 MB)
     |████████████████████████████████| 2.2 MB 2.3 MB/s
Collecting face-recognition-models>=0.3.0
  Downloading face_recognition_models-0.3.0.tar.gz (100.1 MB)
     |████████████████████████████████| 100.1 MB 2.5 MB/s
Building wheels for collected packages: dlib, face-recognition-models
  Building wheel for dlib (setup.py) … \
……
  Building wheel for dlib (setup.py) … done
  Created wheel for dlib: filename=dlib-19.20.0-cp38-cp38-macosx_10_15_x86_64.whl size=3299491 sha256=31ff56825fb1b8cf9324b6ec04f75119441a626a0484058e0d6aaca48f2be168
  Stored in directory: /Users/chen/Library/Caches/pip/wheels/a5/82/2c/2d2ccc604e2c2e35994b89a173d922331f1c6e1af9320a7602
  Building wheel for face-recognition-models (setup.py) … done
  Created wheel for face-recognition-models: filename=face_recognition_models-0.3.0-py2.py3-none-any.whl size=100566172 sha256=05dade1c471823874bf848e4eeb13166a20b569d238fbb97f1c918a58ebf7d19
  Stored in directory: /Users/chen/Library/Caches/pip/wheels/b4/4b/8f/751e99d45f089bdf366a7d3e5066db3c2b84a62e4377f534d7
Successfully built dlib face-recognition-models
Installing collected packages: dlib, Click, Pillow, face-recognition-models, face-recognition
Successfully installed Click-7.1.2 Pillow-7.2.0 dlib-19.20.0 face-recognition-1.3.0 face-recognition-models-0.3.0
chen@Hong-Mac-mini Python %

コマンドラインで試す

face_recognitionをインストールすると、2つのシンプルなコマンドラインがついてきます。

  • face_recognition – 画像もしくはフォルダの中の複数の画像から顔を認識します
  • face_detection – 画像もしくはフォルダの中の複数の画像から顔を検出します
Githubにサンプル写真はあるので、丸ごと取り込む
chen@Hong-Mac-mini Python % git clone https://github.com/ageitgey/face_recognition
Cloning into ‘face_recognition’…
remote: Enumerating objects: 874, done.
remote: Total 874 (delta 0), reused 0 (delta 0), pack-reused 874
Receiving objects: 100% (874/874), 101.46 MiB | 2.02 MiB/s, done.
Resolving deltas: 100% (506/506), done.
chen@Hong-Mac-mini Python %
画像フォルダとサンプル写真の用意
  1. ./pictures_of_people_i_know/   —- 知っている人の画像を入れたフォルダ
    1. obama.jpg
    2. biden.jpg
  2. ./unknown_pictures/  —- 特定したい画像のフォルダ
    1. two_people.jpg
識別してみる
chen@Hong-Mac-mini Python % face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/
./unknown_pictures/two_people.jpg,biden
./unknown_pictures/two_people.jpg,obama

Leave a Reply

Your email address will not be published. Required fields are marked *