dlib--ubuntu16.04如何安装dlib

版权声明:本文为博主原创文章,如要转载,请注明地址,谢谢^...^ https://blog.csdn.net/qq_38880380/article/details/78774540

Step 1: Install OS libraries

/
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libatlas-base-dev libboost-python-dev
/

 

Step 2: Compile C++ binary

/
cd dlib-19.6/
cd dlib
mkdir build
cd build
cmake ..
cmake --build . --config Release
sudo make install
sudo ldconfig
cd ..
/

上述是本人编译的步骤。

 

链接:

1、How to install dlib for python3 in Ubuntu 14.04

2、How to install dlib

3、Install Dlib on Ubuntu(good)

 

附:链接3的文章

In this post, we will provide step by step instructions on how to install Dlib on Ubuntu.

Step 1: Install OS libraries

/
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libx11-dev libatlas-base-dev
sudo apt-get install libgtk-3-dev libboost-python-dev
/

 

Step 2: Install Python libraries

/
sudo apt-get install python-dev python-pip python3-dev python3-pip
sudo -H pip2 install -U pip numpy
sudo -H pip3 install -U pip numpy
/

We will use Virtual Environment to install Python libraries. It is generally a good practice in order to separate your project environment and global environment.

 

/
# Install virtual environment
sudo pip2 install virtualenv virtualenvwrapper
sudo pip3 install virtualenv virtualenvwrapper
echo"# Virtual Environment Wrapper" >> ~/.bashrc
echo"source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
source~/.bashrc
  
############ For Python 2 ############
# create virtual environment
mkvirtualenv facecourse-py2 -p python2
workon facecourse-py2
  
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
  
# quit virtual environment
deactivate
######################################
  
############ For Python 3 ############
# create virtual environment
mkvirtualenv facecourse-py3 -p python3
workon facecourse-py3
  
# now install python libraries within this virtual environment
pipinstallnumpy scipy matplotlib scikit-image scikit-learn ipython
  
# quit virtual environment
deactivate
######################################
/

Step 3: Compile DLib

Step 3.1: Compile C++ binary

Davis King, creator of Dlib, recommends using CMake for using Dlib in your code.
But if you want to use Dlib as a library follow these steps:

/
wget http://dlib.net/files/dlib-19.6.tar.bz2
tarxvf dlib-19.6.tar.bz2
cd dlib-19.6/
mkdir build
cd build
cmake ..
cmake --build . --config Release
sudo make install
sudo ldconfig
cd..
/

Now you can use pkg-config to provide path to Dlib’s include directory and link Dlib library file.

/
pkg-config --libs --cflags dlib-1
/

Step 3.2: Compile Python module

Activate Python virtual environment.

/
############ For Python 2 ############
workon facecourse-py2
 
############ For Python 3 ############
workon facecourse-py3
/

Now let’s compile and install Dlib’s Python module.

/
# move to dlib's root directory
cd dlib-19.6
python setup.py install
# clean up(this step is required if you want to build dlib for both Python2 and Python3)
rm -rf dist
rm -rf tool/python/build
rm python_examples/dlib.so
/

We have cleaned up few files and directories because Dlib creates Python modules for Python2 and Python3 with the same name. Suppose you ran the setup.py in Python2 virtual environment, it will generate dlib.so in python_examples directory. Now if you deactivate Python2 virtual env, activate Python3 virtual env and run setup.py file, it will replace dlib.so (which was compiled with Python2) in python_examples directory with newer one (which is compiled with Python3). When you will try to run any python_example from within this directory, it will import this dlib.so instead of one located in site-packages or dist-packages directory and throw an error. Although this error won’t occur is a local copy of dlib.so is not present in current directory but it is better to remove local copies to avoid any confusion.

For consistency, we have installed Python and C++ binaries of Dlib using the same source code.

If you are going to use only Python module of Dlib you can also install Python bindings for Dlib using pip.

/
pip install dlib
/

Now you can exit from Python virtual environment.

/
deactivate
/

Now, whenever you are going to run Python scripts which use Dlib you have to activate the virtual environment using workon command.

Subscribe & Download Code

If you liked this article and would like to download code (C++ and Python) and example images used in all posts of this blog, please subscribe to our newsletter. You will also receive a free Computer Vision Resource Guide. In our newsletter, we share OpenCV tutorials and examples written in C++/Python, and Computer Vision and Machine Learning algorithms and news.

Subscribe Now

FILED UNDER: COMPILEINSTALLTUTORIAL TAGGED WITH: C++DLIBDLIB 19.4DLIB 19.5DLIB 19.6PYTHONUBUNTU

  • Stephen Meschke

    Great tutorial! Thanks: https://youtu.be/jKkoFTgjn2k

  • Behnam Zeinali

    Hello Satya Mallick. Your tutorials are really great and they have helped me to improve my skills in CV and ML. I followed the instructions of this post and installed the dlib library in my ubuntu OS. I had installed the opencv for python and c++ and the dlib for python before.
    know I have the library in this path:

    behnam@ubuntu:/usr/local/include$ ls
    dlib opencv opencv2 python3.6m

    pkg-config –libs –cflags dlib-1
    -I/usr/local/include -I/usr/include/libpng12 -L/usr/local/lib -ldlib -lpng12

    I want to use the library for the landmark detection in Qt project. I need both opencv and dlib. But after running the code Qt complains about Error 2 and the qmake could not find the correct path. I could not solve the problem.
    I run this code by adding the existing source and adding the dlib include path and in the release mode the speed is acceptable. The opencv installed library is fine but I can not use the dlib installed library. Here is my .pro file. Any help would be really really appreciated.

    QT += core
    QT -= gui

    TARGET = dlibTest
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    INCLUDEPATH += /usr/local/include/opencv -I/usr/local/include -L/usr/local/lib

    LIBS += `pkg-config opencv –libs` `pkg-config –cflags dlib-1`

    QMAKE_CXXFLAGS += -std=c++11

    • Vaibhaw Singh Chandel

      I would have a better idea if you can post error message too.
      btw shouldn’t LIBS be
      LIBS += `pkg-config --libs opencv` `pkg-config --libs dlib-1`

      • Behnam Zeinali

        Hello and thanks for replying.
        You right. I changed it and this is my .pro file:

        QT += core
        QT -= gui

        TARGET = dlibTest
        CONFIG += console
        CONFIG -= app_bundle

        TEMPLATE = app

        SOURCES += main.cpp

        INCLUDEPATH += /usr/local/include/opencv -I/usr/local/include
        INCLUDEPATH += /usr/local/include

        LIBS += `pkg-config opencv –libs`
        LIBS += -I/usr/local/include
        LIBS += -I/usr/include/libpng12
        LIBS += -L/usr/local/lib -ldlib -lpng12

        QMAKE_CXXFLAGS += -std=c++11

        But now I have three errors <img class="emoji" alt="

展开阅读全文

没有更多推荐了,返回首页