I follow the steps according to http://npatta01.github.io/2015/08/10/dlib/ but when I try to run (I use sudo),
python python_examples/face_detector.py exampl
As I see in your code:
detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
First line works and the second does not. This means that dlib is installed, but it is compiled with no GUI support
In dlib's source code we see that if macro DLIB_NO_GUI_SUPPORT is defined - there will be no "image_window" function in dlib module. This macro is defined automatically if CMake scripts can't find X11 libraries
You need to ensure that dlib is compiled with GUI support. To make it, first - install libx11-dev into your system if you are working on Linux, or XQuartz for Mac
When building dlib with running python setup.py install --yes DLIB_JPEG_SUPPORT
- check its messages. If there are errors or warnings - fix them
I am answering this question because I ran into the same issue by doing
conda install -c conda-forge dlib
and
pip install dlib
I tried searched and got several helpful links and below one link was saved my day. So listing down the details here too..
https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf
It will be better to compile the latest code from Github than installing it from conda / pip. This is to ensure that dlib is compiled with GUI support.
Install dependencies
sudo apt-get update
Install Boost
sudo apt-get install libboost-all-dev
Install other dependencies ( May be most of them will already have installed in your system)
apt-get install -y --fix-missing build-essential cmake gfortran git wget curl graphicsmagick libgraphicsmagick1-dev libatlas-dev libavcodec-dev libavformat-dev libboost-all-dev libgtk2.0-dev libjpeg-dev liblapack-dev libswscale-dev pkg-config python3-dev python3-numpy software-properties-common zip
apt-get clean
Build the latestst code of dlib from Github. Assumptions: - Ubuntu 16.04 or higher - don't have an nVidia GPU and don't have Cuda and cuDNN installed and don't want GPU acceleration
Clone the code from github:
git clone https://github.com/davisking/dlib.git
Build the main dlib library:
cd dlib
mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
Build and install the Python extensions:
cd ..
python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
make sure are pointing to the right python( if you have anaconda installed on top of Ubuntu's vanilla python then you should install the package pointing anaconda).
if you are still facing a gcc error like below
lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
then make sure you are installing the below python package
conda install libgcc
At this point, you should be able to run python and type import dlib successfully.