A few weeks ago I did a blog post on how to install the dlib library on Ubuntu and macOS.
Since Raspbian, the operating system that (most) Raspberry Pi users run is Debian-based (as is Ubuntu), the same install instructions can be used for Raspbian as Ubuntu…
…however, there’s a catch.
The Raspberry Pi 3 ships with only 1GB of RAM. This 1GB of RAM is responsible for all system operations, displaying the GUI/desktop, and handling our compile.
In fact, if you tried to compile dlib on the Raspberry Pi, your compile likely bombed out with an error.
In order to get dlib with Python bindings to successfully install on your Raspberry Pi, you need to update your system to reclaim as much memory as possible as well as update your swap file size.
Luckily, this isn’t as challenging as it sounds, and if you follow the steps detailed in this guide, you’ll have dlib installed on your Raspbian system in the next 45 minutes.
To learn how to install dlib on your Raspberry Pi, just keep reading.
Install dlib on the Raspberry Pi
The first part of this tutorial discusses the common memory error you’ll encounter when trying to compile dlib with Python bindings on your Raspberry Pi.
We then move into my six step guide to installing dlib on the Raspberry Pi.
Finally, we’ll wrap up with an example demonstrating how to detect facial landmarks using dlib, Python, and the Raspberry Pi.
Running into memory errors? System crashing?
If you used the Ubuntu instructions from my previous dlib install tutorial to install dlib on your Raspberry Pi, your compile likely bombed out with an error message similar to this one:
The reason for this error can be found in the highlighted box:
c++: internal compiler error: Killed (program cc1plus)
This error message boils down to the dlib compile program using too much memory and the Raspbian operating system killing the process, preventing the Raspberry Pi from seizing.
However, the preventative measures weren’t enough — 3 out of the 5 times I tried to compile dlib on my Raspberry Pi without updating my swap file size, boot options, and memory split (detailed below), my Pi simply locked up and I had to hard reset it.
In order to get dlib with Python bindings installed on Raspbian, we need to reclaim as much available memory as possible. We’ll dive into how to do this in the next section.
Step #1: Update swap file size, boot options, and memory split
Preparing your Raspberry Pi for the dlib compile is divided into three steps, each of them with the same goal — to increase the amount of memory available for the compile:
- Increase your swap file size.
- Switch your boot options.
- Update your GPU/RAM split.
Note: For nearly all screenshots in this tutorial, I was SSH’d into my Raspberry Pi from my host macOS system (that is why the screenshots are from the macOS terminal rather than the Raspbian terminal).
Increase swap file size
Swap files, or swap space, is space on a hard disk/memory card used as virtual memory as an extension to a system’s real memory (RAM).
Enabling swap files allows your operating system to “pretend” like it has more on-board memory than it actually does. Using the swap file architecture, pages in RAM are “swapped out” to disk until they are needed again in which case they are “swapped in”.
Nearly all major operating systems support swapping to some degree.
In Raspbian, the dphys-swapfile solution is used with a default of 100MB dedicated to swap on our card.
In order to update the size of our swap, we need to edit the dphys-swapfile configuration file, which is located in /etc/dphys-swapfile
. You can edit the configuration using your favorite text editor:
$ sudo nano /etc/dphys-swapfile
Scroll down to the configuration which reads:
CONF_SWAPSIZE=100
And then update it to use 1024MB rather than 100MB:
Notice here how CONF_SWAPSIZE=1024
— this will be more than enough swap for us to compile dlib on our Raspberry Pi.
Note: Increasing swap size is a great way to burn out your Raspberry Pi card. Flash-based storage have limited number of writes you can perform until the card is essentially unable to hold the 1’s and 0’s anymore. We’ll only be enabling large swap for a short period of time, so it’s not a big deal. Regardless, be sure to backup your .img
file after installing dlib just in case your card dies unexpectedly early. You can read more about large swap sizes corrupting memory cards on this page.
After you have updated the /etc/dphys-swapfile
file, run the following two commands to restart the swap service:
$ sudo /etc/init.d/dphys-swapfile stop $ sudo /etc/init.d/dphys-swapfile start
The start
command will likely take a few minutes to finish executing since the swap size is being increased and re-allocated.
You can then run:
$ free -m
To confirm that your swap size has been increased.
Here you can see that my swap is 1024MB, up from the previous 100MB:
Change your boot options
By default, your Raspberry Pi will boot into the the PIXEL desktop (assuming you’re using the latest version of Raspbian). This is fine; except that the PIXEL desktop requires memory — RAM that we desperately need for the dlib compile.
Instead of booting into the PIXEL GUI, we should instead boot directly to the terminal. This will save us a substantial amount of memory.
To accomplish this, execute:
$ sudo raspi-config
And then select Boot Options => Desktop / CLI => Console Autologin
:
This will ensure that your Raspberry Pi boots directly to a terminal, skipping the PIXEL desktop.
However, before you exit raspi-config
, be sure to update your memory split, as detailed below.
Update your memory split
By default, the Raspberry Pi allocates 64MB of memory to the onboard GPU. We should reduce this number to 16MB to reclaim memory for the compile.
This is simple enough using raspi-config
. Go back to the main screen and select Advanced Options => Memory Split
, where you’ll see the 64MB prompt:
Update this value to be 16MB and then exit.
Restart your Raspberry Pi
Upon exiting, raspi-config
will ask if you would like to reboot your system.
Go ahead and reboot, then we can move on with the rest of the install tutorial.
Step #2: Install dlib prerequisites
The dlib library requires four prerequisites:
- Boost
- Boost.Python
- CMake
- X11
These can all be installed via the following commands:
$ sudo apt-get update $ sudo apt-get install build-essential cmake $ sudo apt-get install libgtk-3-dev $ sudo apt-get install libboost-all-dev
The pip
command should already be installed on your Raspberry Pi (you can verify this by executing the pip
command and ensuring that it does indeed exist) — otherwise, you can install pip
via:
$ wget https://bootstrap.pypa.io/get-pip.py $ sudo python get-pip.py
Once you’ve verified that pip
is installed, we can move on.
Step #3: Access your Python virtual environment (if you are using them)
All of my OpenCV install tutorials on the PyImageSearch blog make use of Python virtual environments.
Using Python’s virtualenv and virtualenvwrapper libraries, we can create separate Python environments for each project we are working on — this is considered a best practice when developing software in the Python programming language.
I’ve discussed Python virtual environments many times before on the PyImageSearch blog, so I’ll spare any discussion of them here. If you would like to read more about Python virtual environments please refer to any of my installing OpenCV tutorials along with this excellent Python virtual environment primer.
If you would like to install dlib into a pre-existing Python, virtual environment, use the workon
command:
$ workon <your virtualenv name>
For example, most tutorials here on PyImageSearch create a virtual environment named cv
. We can access the cv
virtual environment via:
$ workon cv
Otherwise, I suggesting creating an entirely separate virtual environment using the mkvirtualenv
command.
The command below will create a Python virtual environment named py2_dlib
with the Python 2.7 interpreter:
$ mkvirtualenv py2_dlib
While this command will create a Python 3 virtual environment named py3_dlib
:
$ mkvirtualenv py3_dlib -p python3
Please keep in mind that this step is optional, but highly recommended.
For readers who have followed any of my previous OpenCV install tutorials on PyImageSearch, please make sure you access your Python virtual environment before proceeding to Step #4.
Step #4: Use pip to install dlib with Python bindings
We’ll start with the basic NumPy + SciPy stack, followed by scikit-image, a library commonly used in conjunction with dlib:
$ pip install numpy $ pip install scipy $ pip install scikit-image
We can then install dlib via pip
as well:
$ pip install dlib
On my Raspberry Pi 3, this compile took approximately 40 minutes, but as you can see, the library was compiled successfully with no errors:
Step #5: Test out your dlib install
To test out your dlib install, open up a Python shell (making sure to access your Python virtual environment if you used one), and then try to import dlib
:
$ python Python 3.4.2 (default, Oct 19 2014, 13:31:11) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import dlib >>>
If you would like to access your OpenCV bindings along with your dlib bindings from the same virtual environment, make sure your cv2.so
bindings are properly sym-linked into the site-packages
directory of your Python virtual environment.
Step #6: Reset your swap file size, boot options, and memory split
Important — before you walk away from your machine, be sure to reset your swap file size to 100MB (using the process detailed in the “Step #1: Increase swap file size” section above).
You can then reset your GPU/RAM split to 64MB as well as update the boot options to boot into the desktop interface versus the command line.
After making these changes, reboot your Raspberry Pi to ensure they take affect.
BONUS: Facial landmark detection with dlib and the Raspberry Pi
As a final example of using dlib on the Raspberry Pi, here is a short example I coded up where we are going to detect facial landmarks in an input image:
# import the necessary packages from imutils import face_utils import dlib import cv2 # initialize dlib's face detector (HOG-based) and then create # the facial landmark predictor p = "shape_predictor_68_face_landmarks.dat" detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(p) # load the input image and convert it to grayscale image = cv2.imread("example.jpg") gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # detect faces in the grayscale image rects = detector(gray, 0) # loop over the face detections for (i, rect) in enumerate(rects): # determine the facial landmarks for the face region, then # convert the facial landmark (x, y)-coordinates to a NumPy # array shape = predictor(gray, rect) shape = face_utils.shape_to_np(shape) # loop over the (x, y)-coordinates for the facial landmarks # and draw them on the image for (x, y) in shape: cv2.circle(image, (x, y), 2, (0, 255, 0), -1) # show the output image with the face detections + facial landmarks cv2.imshow("Output", image) cv2.waitKey(0)
For a detailed review of the code above used for facial landmark prediction, please refer to my previous post on the basics of facial landmarks.
To execute the script:
- Make sure you’ve installed/upgraded the imutils library via
pip install --upgrade imutils
. - Use the “Downloads” section below to download the code + example image + pre-trained dlib facial landmark predictor).
From there, you can issue the following command:
$ python pi_facial_landmarks.py
You should then see the following output with the facial landmarks correctly displayed on the input image:
Fun Fact: The picture above is of me during my undergraduate college days — I actually had hair back then!
Unfortunately, from my tests, the Raspberry Pi 3 is not fast enough to perform facial landmark detection in real-time. In my experiments there was a significant lag between polling the next frame from the video stream, followed by applying facial landmark prediction, even when using a threaded video stream for optimal performance. The reason for this is because the face detection process is extremely slow.
Keep in mind that the Raspberry Pi 3 processor runs at only 1.2Ghz while the processor on my Mac (and likely your machine) runs at 3.1GHz (or similar). This is a huge increase in speed.
Methods to speeding up dlib’s facial landmark predictor can be found here — I will be reviewing them in a future blog post with accompanying Python implementations to help us obtain real-time facial landmark prediction performance on the Raspberry Pi.
What's next? We recommend PyImageSearch University.
86 total classes • 115+ hours of on-demand code walkthrough videos • Last updated: October 2024
★★★★★ 4.84 (128 Ratings) • 16,000+ Students Enrolled
I strongly believe that if you had the right teacher you could master computer vision and deep learning.
Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?
That’s not the case.
All you need to master computer vision and deep learning is for someone to explain things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to change education and how complex Artificial Intelligence topics are taught.
If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to successfully and confidently apply computer vision to your work, research, and projects. Join me in computer vision mastery.
Inside PyImageSearch University you'll find:
- ✓ 86 courses on essential computer vision, deep learning, and OpenCV topics
- ✓ 86 Certificates of Completion
- ✓ 115+ hours of on-demand video
- ✓ Brand new courses released regularly, ensuring you can keep up with state-of-the-art techniques
- ✓ Pre-configured Jupyter Notebooks in Google Colab
- ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
- ✓ Access to centralized code repos for all 540+ tutorials on PyImageSearch
- ✓ Easy one-click downloads for code, datasets, pre-trained models, etc.
- ✓ Access on mobile, laptop, desktop, etc.
Summary
In today’s blog post we learned how to compile and install dlib with Python bindings on the Raspberry Pi.
In order to install dlib without error on the Raspberry Pi, we had to take a number of precautions related to memory usage, including:
- Increasing the amount of swap available to our system.
- Booting our Raspberry Pi to the terminal rather than the desktop.
- Reducing memory allocated to the GPU and giving it to main memory instead.
By performing these three steps we were able to reclaim enough memory to install dlib on our Raspberry Pi. However, now we’ve run into the issue that the Pi isn’t quite fast enough for real-time facial landmark prediction. We’ll address how to speedup facial landmark prediction in a future tutorial.
Finally, I wanted to mention that next week’s tutorial is on drowsiness detection while driving a motor vehicle, a heavily requested blog post here on PyImageSearch:
I’m super excited to be demonstrating how to build a drowsiness detector from scratch, so to ensure you are notified when this can’t miss blog post goes live, be sure to enter your email address in the form below!
Download the Source Code and FREE 17-page Resource Guide
Enter your email address below to get a .zip of the code and a FREE 17-page Resource Guide on Computer Vision, OpenCV, and Deep Learning. Inside you'll find my hand-picked tutorials, books, courses, and libraries to help you master CV and DL!
Lorenzo
Hi, an alternative is to use zram: I was able to build dlib with 750MB or zram. Just switch to a text mode runlevel, stop every memory hungry process and you are good to go. I used a config similar to this one (but with 750):
https://gist.github.com/sultanqasim/79799883c6b81c710e36a38008dfa374
Had the same speed problem though. I think I’ll use openCV for a quick detection on the Pi, forward the valid frames to a remote server and handle the false positive, alignment, etc, with a second pass of detection with dlib.
Still have to try the neon optimizations, if I figure out how, but I do not expect miracles.
https://github.com/davisking/dlib/issues/276
Wait, it seems like they commited a neon improvement two days ago!
https://github.com/davisking/dlib/issues/557
Now they only need to add multi-core support 🙂
Adrian Rosebrock
Thank you for sharing your solution Lorenzo!
Renic
We will be waiting for your next post anxiously, please don’t make us wait 🙂
Adrian Rosebrock
Thanks Renic, it will be a great blog post!
Sandara Park
Hi, I followed the instructions step by step, but when I trying to do “pip install scipy” and “pip install scikit-image” on rapsberry pi, it always shows errors like “Failed building wheel for pillow”, “Failed building wheel for scipy”…….sth like that. So what can I do?
Adrian Rosebrock
Hey Sandra — what is the error message you are getting when trying to install scikit-image and the SciPy dependency? I’m guessing you’re running out of RAM, in which case do:
And see if that helps resolve the issue.
Thimira Amaratunga
Awesome!
I was thinking there’s no way Dlib will work on a Raspberry PI.
Thanks for showing how to get it working. This opens up a lot of possibilities for me.
I was trying to figure out a way to have multiple cameras connected to process faces.
Now I can try a set of Raspberry Pis with the camera modules attached, do the pre-processing on them, and send the results to a central node for further processing.
Thanks again.
Adrian Rosebrock
Thanks Thimira, I appreciate the comment 🙂 Congrats on getting dlib installed on your Raspberry Pi!
delta1071
Hi Adrian,
Thanks for another awesome, easy-to-follow tutorial. After successfully compiling dlib and verifying the install via Python, I have tried to run the script in both my cv and dlib_python3 virtual environments. In the cv env.,the script errors out with a “no module named dlib” message. In my dlib virtual env.,I’m getting a “no module named cv” error. I’m not sure if this is a symlink issue (I’m sure my cv2.so file is properly linked), or if something else is going on. Any ideas? Thank you.
Adrian Rosebrock
This sounds like a sym-link issue for sure. Double and triple-check that you have correctly sym-linked in your
cv2.so
file into yourdlib_python3
virtual environment.hoho
have same problem how can I fix it?
Jesse Wiklanki
How is that accomplished. Also I am using python 2
Adrian Rosebrock
You need to check the
site-packages
directory of your Python virtual environment and ensure that thecv2.so
file points to your global install of OpenCV. For more information, please see my tutorials on installing OpenCV on the Raspberry Pi. I would also suggest reading up on how sym-links work.Shital
Hello, i followed all the steps correctly, and got succeeded in every step but my opencv and dlib not working together,
Can you please help me
Adrian Rosebrock
Can you elaborate more on what you mean by “opencv and dlib are not working together”?
Guy T
to solve scipy and scikit-image errors i used apt-get:
sudo apt-get install python-scipy
sudo apt-get install python-skimage
Thank you very much Adrian!!
cant wait for the post about boosting up dlib on RPI!
Adrian Rosebrock
Hi Guy — I WOULD NOT recommend installing SciPy and scikit-image this way if you are using Python virtual environments. Using
apt-get
to install these libraries will install them globally on your system AND they could potentially be out of date. Use pip instead:jorge
thank very much.
I been learning a lot with your blog, now I had installed opencv and dlib in RPi noticine the speed issue.
So for a real time facia application to detect micro-expressions the best is going with what architecture.
Thank for the advice.
Adrian Rosebrock
For detecting facial expressions or emotions I would recommend training a custom emotion recognizer. I detail how to do train a custom facial expression recognizer inside Deep Learning for Computer Vision with Python.
Tom
Hi Adrian,
Using similar method (just by increasing swap space) I have successfully installed dlib on RPi using cmake by following your tutorial for doing it on desktop (it probably was the guru’s course). Just today I came across https://github.com/davisking/dlib/issues/557 where backercp shares his performance tests (HOG’s) for different compilation flags when building C apps. When he is enabling “-O3 -mfpu=neon -fprofile-use” there’s an over 6x speed boost! Would you have any advice about how to prepare dlib “installation” on RPi with these flags enabled?
Thanks,
Tom
Adrian Rosebrock
Hi Tom — optimizing dlib for the Raspberry Pi will likely be a blog post in the future. I’m in the process of compiling and putting together a list of performance tips and tricks.
gaurav gupta
Hi Adrian,
Have you completed this ?
Adrian Rosebrock
I have not had a chance to write the updated blog post for the Raspberry Pi as I’ve been busy working on the new deep learning book. I will try to make the post more of a priority.
yewon
Thank you for your tutorials! I can download dlib successfully (in virtualenv) and reset my swapfile size, boot option, memory split. But when i run the code(pi_facial_landmark.py) in virtualenv, error occurs! “no module named imutils”.
So I installed the imutils with “pip install –upgrade imutile”.
And then, I run the code again. Although i install the imutils, it also occur error like “no module named imutils”
Adrian Rosebrock
Did you make sure you installed imutils inside your virtual environment? You can confirm this via
pip freeze
Martin
Hi, i confirm imutils via pip freeze, and i can see imutils==0.4.3, what can i do?
Adrian Rosebrock
That is indeed very strange. It sounds like your “python” version and “pip” version do not match up. Make sure the “pip” you used to install imutils matches your Python version.
Eslam
The same here but for dlib it appears at pip freeze and shows error when typing import dlib …
How to ensure this relation between pip and python
Adrian Rosebrock
I doubt the “pip” command has frozen, it’s probably just compiling the package (if required). Check your CPU usage for the “pip” process to confirm.
June
Hi~
I’m wating for your post(drowsiness detection on rpi3)
When i can see your post?
thanks
Adrian Rosebrock
Hi June — I haven’t written the post yet, but it’s in my queue.
Damian
I get errors with Access denied ir permission denied when trying to mkdir for virtualenviroment , scikit-image And dlib installing :/
Adrian Rosebrock
Make sure you are logged in as the “pi” user and that you are not trying to install the libraries globally on your system (in which case you would need sudo permissions). This is likely why you are getting the permissions error.
Shivani Junawane
When is your next bolg post – drowsiness detection while driving a motor vehicle coming… What date?… Eagerly waiting. .
Adrian Rosebrock
Hi Shivani — the driver drowsiness detection post was posted way back on May 8th. You can read it here.
Enrique
Hello Adrian! I am waiting for too much time with pip install… and i don´t know that i can do
Adrian Rosebrock
It will take awhile to install dlib on your Raspberry Pi. Be patient while it compiles and installs.
Yousuf Fahim
I have successfully installed dlib but still when I try to import dlib, it shows an error “No module named dlib”. What might be the problem.
Adrian Rosebrock
Did you use Python virtual environments to install dlib? Or did you install dlib globally? If you used Python virtual environments (1) ensure that dlib did successfully install and (2) that you are in the appropriate Python virtual environment.
rohan
i got same problem with dlib. i did to use virtual environment but still i get error that no module name dlib
Adrian Rosebrock
In that case, double-check your install of dlib and make sure the install completed without any errors. It could be the dlib install failed.
Zaiq Ismail
I did the boot options selection. but before setting the memory split I restarted the R pi. Now it shows a black screen. I tried configuring config.txt. But still the black screen appears. I’m using Rasbian Stretch on a Raspberry Pi2 if that helps
Adrian Rosebrock
Hi Zaiq — I’m sorry to hear about the black screen issue; however, I’m not sure what the exact issue is. Can you try SSH’ing into the Pi, resetting the memory split, and then rebooting? It sounds like you allocated too much memory and now the graphics are unable to display.
harsha
i have the same problem .
cannot find solution
please tell me how?
Denis Brion
Well, I am glad you show som dlib examples, I discovered recently (tutorials are less comprehensive than OCV’s ones).
I managed to get dlib compiled on RPIB3 (1G RAM) and nanopi M1 (512 M RAM) with the following steps
#desactivate built in SD swap partition (is it multiple writes resilient?)
sudo swapoff -a
# mount an external disk
[ -d ~/disk ] || mkdir ~disk
[ -f ~/disk/gros ] && swapon ~/disk/gros
I assume ~/disk/gros has been created as a swapfile and is 2G long.
One can verify swap is desactiated witjh “top” (after removing swap, swap length becomes 0; after adding external swap file, … swap length becomes the file length…)
This fully worked for RPI B3 (compiling dlib for C++ and Python; compiling exampels).
For nanopi: full library and most of the C++ examples could be build.
It was so slow trying to make the python bindings that I gave up…
Advantages of this configuration:
you need a big swap file only when compiling; else, you go back to the default configuration at the next reboot (dphys modifies config files)
this is a usual GNUlinux manipulation (AFAIK, dphys is not standard)
TaeYeon
Hello! My name is TaeYeon Yu.
I am a highschool student in Korea. so I may make a slip of the tongue. please forgive me!
My question is about rasberry pi.
One day I saw your blog posting and was interested in it. So I tried to download dlib library in my rasberry pi while following your posting here.
I did step 3 and confused by how to use ‘virtualenv’ in Rasbian.
Then I was sad and decided to keep going this tutorial next day.
However the accident happened the very next day!!!!!!!!!!!!!!!!!!!
My Rasbian monitor screen changed this style(I sent this photo to your mail !)
I want to make my rasberry pi screen back
please help me thank you for reading this!
Adrian Rosebrock
Hi TaeYeon — it’s great to hear that you are getting into in computer vision while in high school! I have answered your query over email. For other readers who run into this issue, the problem was that the X Window server did not start.
ibrahim
make sure your cv2.so bindings are properly sym-linked into the site-packages directory of your Python virtual environment.
I did not understand that can you explain adrian ? So ı dont use cv2 and dlib together .
Adrian Rosebrock
To start, make sure you read up on Python virtual environments. This will help you understand Python virtual environments and why we use them. Each Python install has a “site-packages” directory. This is where libraries are installed into. You need to sym-link your resulting bindings into the “site-packages” directory of your Python virtual environment, exactly as I do in this tutorial.
GIBIN
Sir
After I compiled this dlib func in my terminal, it is shown as successful. But I can’t access it from my python 2.7 outside my terminal. Can u please help me out to rectify this error
thank u
Adrian Rosebrock
Hey Gibin — can you elaborate on what you mean by “outside your terminal”? How are you trying to access the dlib library?
JaneLI
Hi Adrian, why my installation of scipy take such a long time? I follow your tutorial use “pip install scipy” under the virtual environment, It hangs at “Running setup.py bdist_wheel for scipy…” . What should I do?
Adrian Rosebrock
It’s likely not hanging. Run the “top” command and monitor the processors. You should see it compiling and using much of your CPU. Compiling and installing SciPy on a Raspberry Pi will take a good many hours. I would suggest running it overnight while you sleep.
JP
how can i get access in to my python virtual environment? and is downloading scipy requires internet connection? im getting plenty of errors in installing scipy and i dont know how to get into my python virtual envi so i put the pip scipy code and the other in the cv environment ((cv) pi@raspberrypi : ) sorry if this question is too dumb but im just a newbi in this field thanks for you reply 🙂
JP
also i cannot use mkvirtualenv py3_dlib -p python3 to create a virtual environment
Adrian Rosebrock
1. Yes, installing SciPy does require an internet connection.
2. Did you install virtualenv and virtualenvwrapper?
JP
i have an error saying unable to open shape_predictor_68_face_landmarks.dat i don’t know where the problem is?
Adrian Rosebrock
You need to use the “Downloads” section of this post to download the example script and
shape_predictor_68_face_landmarks.dat
file. Then, transfer the code + .dat file to your Raspberry Pi. After that you can execute the script.Kshitij B
Hi Adrian.. I have just install dlib as per above tutorial.. But when i check for i am getting an error Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named dlib
I have install dlib as per above tutorial two times but still no progress.. And yes i m using opencv2.4.9 then does that will make any problem.. and i hve install virtualenv and virtualenvwrapper And i m running it for your drowsiness code.. Please help me its urgent…
Adrian Rosebrock
It sounds like dlib may not actually be installed. You should run:
$ pip freeze
And inspect the output. If “dlib” isn’t listed then dlib was not installed.
Bala
RuntimeError: Error deserializing object of type int
i have installed dlib on my Rpi but i am unable to access the .dat file. It throws the above error.
Please help
Huihuang
Hi , did you solve it?
I also had this error.
Could you please tell me how can i solve it?
Many thanks
luckynote
Hi Adrian.. I have installed in my RPi B3, but it is only running 3+ seconds by landmark. However, it had 0.20 seconds by opencv to face detection. I don’t know how to optimize the speed, so that least at 1 second. Could you give me hope?
Adrian Rosebrock
Facial landmark detection should be even faster than face detection so it sounds like there might be an issue with the install or your code itself. Are you following a tutorial here on PyImageSearch to apply facial landmarks? And which method are you using to detect the actual faces?
Sa-rang
Hi Adrian.
Thank you for the easy explanation.
But when I reboot Pi after finishing Step #6: Reset your swap file size, boot options, and memory split, only black screen appears .
I checked that the swap file size returned into 100MB and returing memory split into 64 . I also checked that my boot option has changed into desktop(auto-logging on mode) .
I spent whole 2-days and am really exhausted to do it whole over again.
Could you help me sir? At least could you tell me how to return everything just before step 6?
Best regards, Sa-rang
Adrian Rosebrock
Hey Sa-rang, I’m sorry to hear about the black screen issue. I’m not sure why that may happen. I believe it may have something to do with you, perhaps accidentally, reducing the amount of RAM allocated to the video output. Make sure you run the “raspi-config” command and ensure you allocated some RAM to the GPU. As far as returning everything prior to Step #6 you may just want to consider re-flashing your SD card with a new Raspbian .img.
Sa-rang
I want to run raspi-config too, but I can do nothing because of the black screen. After googling I found that modifying “config.txt” in Windows could be helpful, so I added “hdmi_safe=1”. As you told that there might be a problem in gpu memory split, I changed gpu_mem 16,64,128,256.
But nothing changed. There was still black screen in the monitor. Because there is still blinking green light, I think it is something wrong in setting, not in raspberry pi or sd card.
After all the effort, I guess it is time to let pi go and re-install every step. thanks for the reply.
Adrian Rosebrock
Sorry I could not be of more help here! But I’m not sure what the exact issue would be. My suggestion would be to start with a fresh install of Raspbian if at all possible.
Sa-rang
Hi adrian. I have 2 questions about swapping size and memory split. Does it change raspberry pi’s memory setting or sd card’s setting? Now i have been trying to recover jessie on th Pi, but still nothing can see on the screen. I have 2 monitors and 3 sd cards (16gb and 2 of 64gb). I tried Every cases of sd card and monitor. Guess what? Still no image in the screen! So I think it is wrong with pi.
I just wonder that my previous setting change made Pi burn to death. Just like You mentioned that step 1 could burn the memory. Do you think the pi is dead? So quickly?
Adrian Rosebrock
It would technically change both. The swap size is a Raspbian configuration but does have an impact on the physical Pi itself. The memory setting is stored via the OS but would impact the physical hardware.
As far as the issue goes I doubt you would have killed the SD card so quickly unless it was already defective or had some other issue. It could just have been a faulty Pi or faulty SD card.
Sa-rang
Thank you for your support. I bought 3 raspberry pis and 3 new sd cards. This time I’m going to follow your newer post ; the easy way to install dlib. I’ll comment here about the result. Best regards, Sa-rang.
Venu
Hello Adrian, i have install dlib with your guide and it work. Can we get the explanation on the shape_predictor_68_face_landmark.dat thank you
Adrian Rosebrock
The .dat file is your facial landmark predictor. It was trained via the dlib library and associated dlib tools. It’s a binary file that is read by dlib as it contains the machine learning information to localize facial landmarks.
Amare Mahtsentu
Hi Adrian: nice to meet you…..you have said that the boot options should be “console auto login” ….but what if I need to edit some line of code in the desktop? can I enable it again while editing and disable it for memory savage…?
Thank you
Adrian Rosebrock
I’m not sure what you mean by “edit some line of code in the desktop? You could always start the Raspberry Pi GUI if you boot into the command line if you would like.
Amare Mahtsentu
the display of the pi desktop on the laptop is giving a black with a text message ” can not currently show the desktop” if the boot option is set to “console auto login” ….that means unable to get the files in my pi…. except the terminal ( on putty)
Sanjiv Sharma
hello sir
i am sanjiv sharma
i am installing scipy and its on “setup bdlist_weel fot scipy” from 1 hour what should i do
Adrian Rosebrock
You should let it run and install. The SciPy library is quite large and can take many hours to compile and install.
Stephen
Hi Adrian/ Guy T,
I also ran into some issues when running through the procedure. scikit-image would not install due to ‘cython’ being missing.
I managed to solve this buy doing:
pip install cython
pip install scikit-image
All is now well 🙂 all the other steps worked with no issues at all.
I’d also like to take this opportunity to thank you Adrian for a fantastic site and set of tutorials. I was new to Python not programming, these are by far the most clear I have found and have given me a great foundation to grow from.
I’m sure the book will be fantastic also.
Adrian Rosebrock
Thanks so much Stephen! 🙂
suren
hello adrian im a student from malaysia..i wanted to ask y after i installed all the library and try with the Facial landmark detection with dlib and the Raspberry Pi it says that no imultis module.but i installed everything successfully
Adrian Rosebrock
It sounds like you forgot to install the imutils library:
$ pip install imutils
lah
To speed up compilation, reduce RAM consumption during build process, you can use distcc https://wiki.gentoo.org/wiki/Distcc
It is very easy to setup. Raspberry PI is a distcc master node that sends some of its compilations job to some distcc clients (e.g. your powerful laptop)
In order to use distcc when building python package, man distcc and read MASQUERADING section
Eslam
I can’t access virtual environment!
-bash: mkvirtualenv: command not found
What shall I do?
Adrian Rosebrock
You haven’t installed virtualenv and virtualenvwrapper. Make sure they are properly installed.
Adam
I had to pull the GitHub repository and build it from source.
Anas Ahmed
Your tutorials help me alot. I am a beginner in RaspberryPi and followed your tutorials of OpenCV and dlib installation and finally done it with ease.
I have a query, that I have used already built virtual environment (i.e: cv; you asked to create in opencv tutorial) for installing Numpy, SciPy, scikit-image and dlib. Is it ok?
Furthermore, I am working on an Eye-Controlled Vehicle. Can you please suggest a camera and how to increase real-time processing as I need high accuracy?
Adrian Rosebrock
Yes, you can use Python virtual environments, that’s perfectly okay. As far as your second question goes, I don’t have much experience with eye tracking so I’d be a bit hesitant in recommending a camera. Sorry I couldn’t help more there!
Barry
Hi Adrian,
I got as far as trying to install scipy (pip install scipy) – I left it running for approx. 2 hours, but my RPi just seemed to shutdown after that. Is there any other way to install it?
Thanks,
Adrian Rosebrock
Try installing it again. It may take a few hours to install SciPy on the Raspberry Pi.
Barry
Yep, it worked after a couple of tries. Thanks.
Dexter
Hi Adrian! I am a newbie on this topic. Took about over a week to get OPENCV installed on a virtual environment following your tutorials – really enjoyed it. I am stuck on installing dlib – took over a couple of hours and still compiling on my RPi3.
Personally, I don’t mind paying for a pre-loaded image file with all the necessary OPENCV, dlib and imutils loaded, and with your tutorial examples – that would save me a ton of hours mucking around the compilation and downloading the examples.
Are you open to preparing a working image for download? Again, I am open to paying for it just to save me tons of time preparing the RPi3 myself.
Thanks.
-Dexter
Adrian Rosebrock
Hi Dexter — have you taken a look at Practical Python and OpenCV? The Quickstart Bundle and Hardcopy Bundle include a pre-configured, downloadable Raspbian .img file. You would just download the .img file, flash it to your SD card, and boot! It would save you a ton of time and hassle.
Tanmay
Is it really necessary to increase swap file space to install dlib.
I did as per your steps but it did not even show swap file size row.
Plus I direclty used pip install dlib but it took 2hrs and failed.
Please help.
Adrian Rosebrock
It sounds like you may have had an issue increasing your swap size. Go back to that stpe and try again.
Abubakar
hi adrian, the pi does not finish booting after updating the memory split.
it stops at: i2c /dev entries driver’. and gets stuck.
what do you advice i do?
i cant even access anything.
Adrian Rosebrock
I’m sorry to hear that, Abubakar, although I don’t think that’s related to the memory split. I would suggest re-installing Raspbian and trying again.
Abubakar
thanks adrian
i formatted the sd card. such a heart break. trying to start a-fresh (drowsiness detection system on pi). im kinda outta time. how many days do u think it would take me to get things back to normal? (installing the libraries and stuff).
Adrian Rosebrock
If time is a pressing issue then I would take a look at the Quickstart Bundle and Hardcopy Bundle of my book, Practical Python and OpenCV. Those bundles include a pre-configured Raspbian .img file with OpenCV, dlib, and all the other computer vision + image processing libraries you need pre-installed. Just download the .img file, flash it to your Pi, and boot. You’ll be up and running with the drowsiness detection code in a matter of minutes.
Abubakar
ok thanks for replying adrian.
erm..just one more question:
all these libraries i installed so far (dlib,cv2, scipy, numpy, imutils etc.), how can i access them when i vnc (vnc viewer) to my pi. some of them cant be found. worse thing, u cant use the command ‘workon’ while using vnc viewer. so what do i do?
Adrian Rosebrock
You can use the “workon” command from VNC. Just open up a terminal, run “source ~/.profile” and then “workon your_env_name”.
Zubair Ahmed
Another well done tutorial
Just installed Dlib using this on my brand new RaspPi
Adrian Rosebrock
Congrats on getting dlib installed!
SangHee Park
Thank you for such a nice tutorial!
This helped me a lot.
I did exactly same to increase swapfile size.
but when I put free -m the toal Swap comes out 1867 not 1023 is this fine?
my memory is 16GB.
If it’s not fine how could I fix it?
yatharth arora
hi..
thanks for the tutorial
when i type pip3 install dlib
my terminal is stuck on – building wheel for dlib(setup.py) from the last 2 hours…
please help….!!!!!!!!!!!!!!!!1
Adrian Rosebrock
That’s normal — it may take awhile for your RPi to compile dlib.