LoginSignup
6
3

More than 3 years have passed since last update.

face_recognition使ってみた(ほぼ構築)

Last updated at Posted at 2020-06-25

顔認証記事見つけて試してみたら、インストール時点でエラーが出てスムーズに出来なかったのでメモしとく。

Python を利用して顔認証ができる。しかもライブラリは公開されている。
しかも簡単らしい。
 最初に見た記事: https://www.cresco.co.jp/blog/entry/9468/

※そもそもPython初心者なんだけど、適当に書いても動くので甘く見てる。
※環境はWindows10、Python3.8

ちょうど業務で課題となっているものに顔認証が使えないかなーと思っていたので
「pipでインストールするだけでしょ」ぐらいの軽い気持ちで始めて見た。

>pip3 install face_recognition

インストールでエラー出まくって全然先に進めなかった・・・
読めない英語を見ながらググって進めた

wheelが無いよって怒られた。
なにそれ?python配布用のzipらしい。

>pip install -U wheel

まだまだエラー
dlibがどーとか

そもそも、face_recognitionってのはdlibっていう顔認識ライブラリを使うための物らしい。
python用のラッパーかな?
 参考:https://qiita.com/nonbiri15/items/f95b5fb01ae38980c9ce

dlibのインストールが必要らしい。

>pip3 install dlib

やっぱりエラー出まくり

dlibってCで作られてるらしい
CMAKEってのが要るらしい。
cmake-3.18.0-rc2-win64-x64.msi
 ↑ をDLしてインストール

まだまだ~
VC++でビルドするらしい(そりゃそーか)
 参考:https://qiita.com/strv13570/items/a0542600532deee61391
Visualstudio2017は入れてたけどVC++なんて触りたくなかったので入れてなかった。
しょうがないのでVC++使うように変更してインストール

以上、pathなどは適宜設定(確認)

>pip3 install dlib
・
・
・
Successfully installed dlib-19.20.0

やっと、dlib通った。

pip3 install face_recognition
・
・
・
 Successfully installed Pillow-7.1.2 face-recognition-1.3.0 numpy-1.19.0

やっとインストールできたか、長い道のりだった・・・
  ググって思ったのが、なんで、みんなアナコンダとか入れてんだろうか??業務上か?

とりあえず、サイトを参考に2つのフォルダを作って写真入れて試す。
知ってる顔フォルダ と 知らない顔 フォルダ を作ってそれぞれ入れてdiff取る感じの使い方。
それぞれ以下で試した。
face.png

face2.png
※1枚本物入れて見た。
実行結果
diff_result.png
tosi3は騙されてるね。

以上、使用レビューのつもりが、インストールメモに成ってしまった・・・

他もいろいろ試してみたい予定
 参考:https://www.kkaneko.jp/dblab/dlib/facerec.html

追記:
     ↑ のサイト見てまんま試してみた

test_face.py
import face_recognition

src_img = face_recognition.load_image_file("./face/obama.png")
src_img_encoding = face_recognition.face_encodings(src_img)[0]
# print(src_img_encoding)

img1="./face2/tosi.png"
img2="./face2/tosi2.png"
img3="./face2/tosi3.png"

dest_img1 = face_recognition.load_image_file(img1)
dest_img_encoding1 = face_recognition.face_encodings(dest_img1)[0]

dest_img_encoding2 = face_recognition.face_encodings(face_recognition.load_image_file(img2))[0]
dest_img_encoding3 = face_recognition.face_encodings(face_recognition.load_image_file(img3))[0]

results = face_recognition.compare_faces([src_img_encoding], dest_img_encoding1)
print(img1 , results)
results = face_recognition.compare_faces([src_img_encoding], dest_img_encoding2)
print(img2 , results)
results = face_recognition.compare_faces([src_img_encoding], dest_img_encoding3)
print(img3 , results)
実行結果.
>test_face.py
./face2/tosi.png [False]
./face2/tosi2.png [False]
./face2/tosi3.png [True]

Process finished with exit code 0

顔の特徴を数値化して比較できる
めっちゃ楽じゃんか!!

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3