0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ubuntu20 に CPU 版の dlib をインストール

Last updated at Posted at 2021-04-22

Ubuntu20 に CPU 版の dlib をインストールします。

sudo apt install -y python3-dev python3-pip python3-setuptools python3-venv
#sudo pip3 uninstall ptyprocess sniffio terminado tornado jupyterlab jupyter jupyter-console jupytext nteract_on_jupyter spyder
#sudo apt install -y jupyter jupyter-qtconsole spyder3
sudo apt install -y python3-ptyprocess python3-sniffio python3-terminado python3-tornado 
#sudo pip3 install -U jupyterlab nteract_on_jupyter
sudo apt install -y git cmake cmake-curses-gui cmake-gui wget p7zip-full
sudo apt install -y build-essential gcc g++ make libtool texinfo dpkg-dev pkg-config
cd /usr/local
sudo rm -rf dlib
sudo git clone https://github.com/davisking/dlib
cd /usr/local/dlib
sudo rm -rf build
sudo mkdir build
cd build
sudo cmake -DUSE_AVX_INSTRUCTIONS=YES -DDLIB_USE_CUDA=NO ..
sudo cmake --build .
sudo make install 
which python3
cd /usr/local/dlib
sudo python3 setup.py build
sudo python3 setup.py install 

# python3 sample
cd /usr/local/dlib/python_examples
sudo wget http://dlib.net/files/mmod_human_face_detector.dat.bz2
sudo wget http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2
sudo wget http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2
sudo wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
sudo bzip2 -d mmod_human_face_detector.dat.bz2
sudo bzip2 -d dlib_face_recognition_resnet_model_v1.dat.bz2
sudo bzip2 -d shape_predictor_5_face_landmarks.dat.bz2
sudo bzip2 -d shape_predictor_68_face_landmarks.dat.bz2
python3 opencv_webcam_face_detection.py

# test
cd /usr/local/dlib/test
sudo mkdir build
cd build
sudo cmake ..
sudo cmake --build . --config Release
sudo ./dtest --runall

# c sample
cd /usr/local/dlib/examples
sudo rm -rf build
sudo mkdir build
cd build
sudo cmake -DUSE_AVX_INSTRUCTIONS=YES -DDLIB_USE_CUDA=NO ..
sudo cmake --build .
sudo wget http://dlib.net/files/mmod_human_face_detector.dat.bz2
sudo wget http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2
sudo wget http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2
sudo wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
sudo bzip2 -d mmod_human_face_detector.dat.bz2
sudo bzip2 -d dlib_face_recognition_resnet_model_v1.dat.bz2
sudo bzip2 -d shape_predictor_5_face_landmarks.dat.bz2
sudo bzip2 -d shape_predictor_68_face_landmarks.dat.bz2
./webcam_face_pose_ex

C言語でのサンプルファイルの作成(おそらく Python で作成したほうがいいかも)

cd
gedit mysample.c

サンプルファイルの中身

mysample.c
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_io.h>
#include <dlib/gui_widgets.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[1]);
  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; 

  image_window win;
  win.clear_overlay();
  win.set_image(img);
  win.add_overlay(dets, rgb_pixel(255,0,0));
  cin.get();
}

コンパイルと実行(ちょっとエラー undefined reference to `pthread_create' が出ますが雰囲気として)

sudo apt install -y libblas-dev liblapack-dev
g++ -ldlib -llapack -lblas mysample.c -o mysample.exe
./mysample.out 2007_007763.jpg 

####参考リンク

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?