Dlib C++ Library に付属のサンプルプログラムで顔検出を行う(Ubuntu 上)
Ubuntu を使うとして手順を説明する.
前準備
Ubuntu のシステム更新
Ubuntu で OS のシステム更新を行うときは, 次のコマンドを実行.
sudo apt -y update
sudo apt -yV upgrade
sudo /sbin/shutdown -r now
いくつかのパッケージのインストール
sudo apt install libx11-dev
DLib のインストール(Ubuntu 上)
DLib のインストール(Ubuntu 上): 別ページ »で説明
画像ファイルの準備
謝辞:このページでは,画像ファイルは Dlib 付属の画像ファイルを使用します.感謝します.
次で公開されている顔画像ファイル 2007_007763.jpg をダウンロードして使用する.
https://github.com/davisking/dlib/tree/master/examples/faces
検出された顔領域の矩形領域を標準出力に表示
dlib C++ Library を用いて、静止画から顔検出
#include<dlib/image_processing/frontal_face_detector.h>
#include<dlib/gui_widgets.h>
#include<dlib/image_io.h>
#include<iostream>
using namespace dlib;
using namespace std;
int main(int argc, char** argv)
{
frontal_face_detector detector = get_frontal_face_detector();
array2d<unsigned char> img;
load_image(img, argv[2]);
pyramid_up(img);
std::vector<rectangle> dets = detector(img);
std::vector<rectangle>::iterator it;
for( it = dets.begin(); it != dets.end(); it++ )
cout << *it << endl;
if ( atoi(argv[1]) != 0 ) {
image_window win;
win.clear_overlay();
win.set_image(img);
win.add_overlay(dets, rgb_pixel(255,0,0));
cin.get();
}
}
上のソースコードを,a.cのようなファイル名で保存し, 次の手順でビルドして実行
g++ -I/usr/local/include a.c -L/usr/local/lib -ldlib -lpthread -lX11
./a.out 0 2007_007763.jpg
./a.out 1 2007_007763.jpg

