My開発メモ

face_recognitionのインストールとエラー(Python, Ubuntu)

ハーバード大学のコンピュータサイエンス入門講座のPython編のなかに
Pythonの画像認識(顔認識)プログラムの紹介がある。
それを実際にやってみた。

face_recognitionのインストールでエラー

$ python3 -m pip install face_recognition

以下のエラーが出る。

...(略)...

Collecting dlib>=19.7
  Downloading dlib-19.24.0.tar.gz (3.2 MB)
...
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: dlib, face-recognition-models
  Building wheel for dlib (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      running bdist_wheel
      running build
      running build_py
      package init file 'tools/python/dlib/__init__.py' not found (or not a regular file)
      running build_ext
      
      ERROR: CMake must be installed to build dlib
      
      [end of output]

...(略)...

dlibのダウンロードが終わって、dlibのビルドを始めているときに、CMake がないからビルドできない
と言っているようである。

CMakeのインストール

次のサイトによると、以下の3つのパッケージをインストールする必要があるみたい。

$ sudo apt install -y cmake  cmake-curses-gui  cmake-gui

(参考)
Dlib のインストール(Ubuntu 上)金子邦彦研究室
https://www.kkaneko.jp/ai/ubuntu/ubuntu_dlib.html

ターミナルでcmakeを使うのなら cmake だけでいいが、多くのコンパイルオプションがあるので、
GUIツールが用意してある。ついでなので、それもインストールしておいたほうがいいというのが
この参考サイトの考えだろう。それに従うことにする。

$ sudo apt-update
$ sudo apt-upgrade
$ sudo apt install cmake cmake-curses-gui cmake-gui

すぐインストールできたので、再度 face_recognition をインストールする。

$ python3 -m pip install face_recognition

なんか、すごく負荷がかかっているんだけど…。

Installing collected packages: dlib, face_recognition
Successfully installed dlib-19.24.0 face_recognition-1.3.0

なんとかインストールできたようである。

ハーバード大学のcs50のサンプルコードで試してみる

(素材) https://cdn.cs50.net/2021/fall/lectures/6/src6/6/faces/

$ python3 recognize.py

Tobyの顔写真(toby.jpg)を読み込み、 Tobyの顔を集合写真(office.jpg)の中から見つけることに
成功している。

カテゴリー: memo, Python, Python3

タグ: cmake, face-recognition

カウント: 294