Title: Install OpenCV 4 on Raspberry Pi 4 and Raspbian Buster - PyImageSearch

URL Source: https://pyimagesearch.com/2019/09/16/install-opencv-4-on-raspberry-pi-4-and-raspbian-buster/

Published Time: 2019-09-16T14:00:57+00:00

Markdown Content:
![Image 1](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20450'%3E%3C/svg%3E)

In this tutorial, you will learn how to install OpenCV 4 on the Raspberry Pi 4 and Raspbian Buster.

You will learn how to install OpenCV 4 on Raspbian Buster via both:

1.  **A simple pip-install method** (which can be completed in a matter of minutes)
2.  **Compiling from source** (which will take longer but will give you access to the full, optimized install of OpenCV)

**To learn more about installing OpenCV 4 on the Raspberry Pi 4 and Raspbian Buster, _just keep reading._**

_**2019-11-21 Update:**_ _An update has been issued to this blog post due to compatibility issues with OpenCV using the pip install method. Be sure to find the updates via `ctrl + f` as you search for “2019-11-21 Update”._

In this tutorial, we will install and test OpenCV 4 on Raspbian Buster in five simple, easy-to-follow steps.

If you’ve ever compiled OpenCV from scratch before, you know that the process is _especially time-consuming_ and even _painstakingly frustrating_ if you miss a key step or if you are new to Linux and Bash.

**In Q4 2018, a [new, faster method for installing OpenCV on the Raspberry Pi](https://pyimagesearch.com/2018/09/19/pip-install-opencv/) (i.e., a pip install) was made possible thanks to the hard work of the following people:**

*   [Olli-Pekka Heinisuo](https://github.com/skvark) — maintainer of the [opencv-contrib-python package on PyPi](https://pypi.org/project/opencv-contrib-python/)
*   [Ben Nuttall](https://github.com/bennuttall) — from the Raspberry Pi community-run [piwheels.org](https://www.piwheels.org/), a Python package repository providing ARM wheels (i.e., pre-compiled binaries packages) for the Raspberry Pi
*   [Dave Jones](https://github.com/waveform80) — creator of the `picamera` Python module

Installing OpenCV via pip is easier than ever. In fact, you can be up and running (**Step #1 – Step #4a**) in less than 10 minutes.

**But what’s the catch?**

Using pip to install OpenCV is great, but for some projects (including many educational projects on PyImageSearch.com and in my books/courses) **you might want the complete install of OpenCV (which the pip install _won’t_ give you).**

Don’t worry, I’ve got you covered in **Step #4b** below — you’ll learn to use CMake and Make to compile OpenCV 4 on BusterOS from scratch.

Let’s dive in!

### Before we begin: Grab your Raspberry Pi 4 and flash BusterOS to your microSD

Let’s review the **hardware requirements** for this tutorial:

*   **Raspberry Pi:** This tutorial assumes you are using a _**Raspberry Pi 4B 1GB, 2GB** or **4GB**_ hardware.
*   **Operating system:** These instructions _**only apply to Raspbian Buster**_.
*   **32GB microSD:** I recommend the high-quality SanDisk 32GB 98Mb/s cards. Here’s an example on [Amazon](https://amzn.to/2Lv9C4O) (however you can purchase them on your favorite online distributor).
*   **microSD adapter:** You’ll need to purchase a microSD to USB adapter so you can flash the memory card from your laptop.

If you don’t already have a Raspberry Pi 4, I highly recommend CanaKits ([which are available on Amazon](https://amzn.to/2ZWLnFr)) and directly through [Canakit’s website](https://www.canakit.com/). Most of their kits come with a Raspberry Pi, power adapter, microSD, microSD adapter, heatsinks, and more!

[![Image 2](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20450'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_hardware.jpg)

**Figure 1:** Hardware for installing OpenCV 4 on your Raspberry Pi 4 running Raspbian Buster.

Once you have the hardware ready, you’ll need to **flash a fresh copy of the Raspbian Buster operating system** to the microSD card.

1.  Head on over to the [official BusterOS download page](https://www.raspberrypi.org/downloads/raspbian/) (**Figure 2**), and start your download. I recommend the _“Raspbian Buster with Desktop and recommended software”_.
2.  Download [Balena Etcher](https://www.balena.io/etcher/) — software for flashing memory cards. It works on every major OS.
3.  Use Etcher to flash BusterOS to your memory card (**Figure 3**).

[![Image 3](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20651'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_download_os.jpg)

**Figure 2:** Download Raspbian Buster for your Raspberry Pi and OpenCV 4.

After downloading the Raspbian Buster .img file you can flash it to your micro-SD card using Etcher:

[![Image 4](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20389'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_etcher.jpg)

**Figure 3:** Flash Raspbian Buster with Etcher. We will use BusterOS to install OpenCV 4 on our Raspberry Pi 4.

After a few minutes the flashing process should be complete — slot the micro-SD card into your Raspberry Pi 4 and then boot.

From there you can move on to the rest of the OpenCV install steps in this guide.

### Step #1: Expand filesystem and reclaim space

For the remainder of this tutorial I’ll be making the following assumptions:

1.  You are working with a brand new, fresh install of **Raspbian Buster** (see the previous section to learn how to flash Buster to your microSD).
2.  You are comfortable with the command line and Unix environments.
3.  You have an [SSH or VNC connection established with your Pi](https://pyimagesearch.com/2019/07/01/remote-development-on-the-raspberry-pi-or-amazon-ec2/). Alternatively, you could use a keyboard + mouse + screen.

Go ahead and insert your microSD into your Raspberry Pi and boot it up with a screen attached.

Once booted, configure your WiFi/ethernet settings to connect to the internet (you’ll need an internet connection to download and install required packages for OpenCV).

From there you can [use SSH](https://pyimagesearch.com/2019/07/01/remote-development-on-the-raspberry-pi-or-amazon-ec2/) as I have done, or go ahead and open a terminal.

The first step is to run, `raspi-config` and expand your filesystem:

$ sudo raspi-config

And then select the _**“7 Advanced Options”**_ menu item:

[![Image 5](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20405'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_raspi_config.jpg)

**Figure 4:** The \`raspi-config\` configuration screen for Raspbian Buster. Select \`7 Advanced Options\` so that we can expand our filesystem.

Followed by selecting _**“A1 Expand filesystem”**_:

[![Image 6](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20405'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_raspi_config_expand_fs.jpg)

**Figure 5:** The \`A1 Expand Filesystem\` menu item allows you to expand the filesystem on your microSD card containing the Raspberry Pi Buster operating system. Then we can proceed to install OpenCV 4.

Once prompted, you should select the first option, _**“A1 Expand File System”**_, hit `enter` on your keyboard, arrow down to the _**“<Finish>”**_ button, and then reboot your Pi — you may be prompted to reboot, but if you aren’t you can execute:

$ sudo reboot

After rebooting, your file system should have been expanded to include all available space on your micro-SD card. You can verify that the disk has been expanded by executing `df -h` and examining the output:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  5.3G   23G  20% /
devtmpfs        1.8G     0  1.8G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  8.6M  1.9G   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   40M  213M  16% /boot
tmpfs           386M     0  386M   0% /run/user/1000

As you can see, my Raspbian filesystem has been expanded to include all 32GB of the micro-SD card.

However, even with my filesystem expanded, I have already used 15% of my 32GB card.

While it’s not required, I would suggest deleting both Wolfram Engine and LibreOffice to reclaim ~1GB of space on your Raspberry Pi:

$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice\*
$ sudo apt-get clean
$ sudo apt-get autoremove

### Step #2: Install dependencies

The following commands will update and upgrade any existing packages, followed by installing dependencies, I/O libraries, and optimization packages for OpenCV:

The first step is to update and upgrade any existing packages:

$ sudo apt-get update && sudo apt-get upgrade

We then need to install some developer tools, including [CMake](https://cmake.org/), which helps us configure the OpenCV build process:

$ sudo apt-get install build-essential cmake pkg-config

Next, we need to install some image I/O packages that allow us to load various image file formats from disk. Examples of such file formats include JPEG, PNG, TIFF, etc.:

$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng-dev

Just as we need image I/O packages, we also need video I/O packages. These libraries allow us to read various video file formats from disk as well as work directly with video streams:

$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev

The OpenCV library comes with a sub-module named `highgui` which is used to display images to our screen and build basic GUIs. In order to compile the `highgui` module, we need to install the GTK development library and prerequisites:

$ sudo apt-get install libfontconfig1-dev libcairo2-dev
$ sudo apt-get install libgdk-pixbuf2.0-dev libpango1.0-dev
$ sudo apt-get install libgtk2.0-dev libgtk-3-dev

Many operations inside of OpenCV (namely matrix operations) can be optimized further by installing a few extra dependencies:

$ sudo apt-get install libatlas-base-dev gfortran

These optimization libraries are _especially important_ for resource-constrained devices such as the Raspberry Pi.

The following pre-requisites are for **Step #4a** and they certainly won’t hurt for **Step #4b** either. They are for HDF5 datasets and Qt GUIs:

$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5

Lastly, let’s install Python 3 header files so we can compile OpenCV with Python bindings:

$ sudo apt-get install python3-dev

If you’re working with a fresh install of the OS, it is possible that these versions of Python are already at the newest version (you’ll see a terminal message stating this).

### Step #3: Create your Python virtual environment and install NumPy

We’ll be using Python **virtual environments**, a best practice when working with Python.

A Python virtual environment is an _isolated_ development/testing/production environment on your system — it is fully sequestered from other environments. Best of all, you can manage the Python packages inside your your virtual environment inside with pip (Python’s package manager).

Of course, there are alternatives for managing virtual environments and packages (namely Anaconda/conda). I’ve used/tried them all, but have settled on pip, [virtualenv](https://virtualenv.pypa.io/en/latest/), and [virtualenvwrapper](https://virtualenvwrapper.readthedocs.org/en/latest/) as the preferred tools that I install on all of my systems. If you use the same tools as me, you’ll receive the best support from me.

You can install pip using the following commands:

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
$ sudo python3 get-pip.py
$ sudo rm -rf ~/.cache/pip

Let’s install `virtualenv` and `virtualenvwrapper` now:

$ sudo pip install virtualenv virtualenvwrapper

Once both `virtualenv` and `virtualenvwrapper` have been installed, open up your `~/.bashrc` file:

$ nano ~/.bashrc

…and append the following lines to the _bottom_ of the file:

\# virtualenv and virtualenvwrapper
export WORKON\_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER\_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh

[![Image 7](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20424'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_bashrc.jpg)

**Figure 6:** Using the \`nano\` editor to update ~/.bashrc with \`virtualenvwrapper\` settings.

Save and exit via `ctrl + x` , `y` , `enter` .

From there, reload your `~/.bashrc` file to apply the changes to your current bash session:

$ source ~/.bashrc

Next, create your **Python 3 virtual environment:**

$ mkvirtualenv cv -p python3

Here we are creating a Python virtual environment named `cv` using Python 3. Going forward, I recommend Python 3 with OpenCV 4+.

_**Note:** Python 2.7 will reach end of its life on January 1st, 2020 so I **do not** recommend using Python 2.7._

You can name the virtual environment whatever you want, but I use `cv` as the standard naming convention here on PyImageSearch.

If you have a Raspberry Pi Camera Module attached to your RPi, you should install the **PiCamera API** now as well:

$ pip install "picamera\[array\]"

### Step #4(a or b): Decide if you want the 1-minute quick install or the 2-hour complete install

From here you need to make a decision about the rest of your install. There are two options.

1.  **Step #4a: pip install OpenCV 4:** If you decide to pip install OpenCV, you will be done **in a matter of seconds**. It is by far the _fastest, easiest_ method to install OpenCV. It is the method I recommend for 90% of people — especially _beginners_. After this step, you will _skip to_ **Step #5** to test your install.
2.  **Step #4b: Compile OpenCV 4 from source:** This method gives you the **full install** of OpenCV 4. It will take 2-4 hours depending on the processor in your Raspberry Pi.

As stated, I highly encourage you to use the pip instructions. They are faster and will work for 90% of your projects. Additionally, the patented algorithms can only be used for educational purposes (there are plenty of great alternatives to the patented algorithms too).

### Step #4a: pip install OpenCV 4

In a matter of seconds, you can **pip install OpenCV** into the `cv` virtual environment:

$ pip install opencv-contrib-python==4.1.0.25

_**2019-11-21 Update:** Readers have reported that some versions of OpenCV 4 as installed via pip do not work properly on the Raspberry Pi. You may encounter an \`**“undefined symbol: \_\_atomic\_fetch\_add8″\`** for `libatomic` error when you `import cv2` from Python if you do not use the specific version of OpenCV mentioned in the code block above._

If you watch the terminal output you’ll see that OpenCV 3.4 rather than OpenCV 4 was installed?

What gives?

At the time of this writing, PiWheels has _not_ been updated with pre-complied OpenCV 4 binaries for Raspbian Buster. PiWheels normally lags slightly behind the latest version of OpenCV, likely to ensure compatibility across the major Raspbian releases. **Once OpenCV 4 has been released for PiWheels I will update this section.**

That’s really all there is to it. You may skip to **Step #5** now to test your install.

### Step #4b: Compile OpenCV 4 from source

This option installs the full install of OpenCV including patented (“Non-free”) algorithms.

_**Note: Do not follow Step #4b if you followed Step #4a.**_

Let’s go ahead and download the OpenCV source code for both the [opencv](https://github.com/opencv/opencv) and [opencv\_contrib](https://github.com/opencv/opencv_contrib) repositories, followed by unarchiving them:

$ cd ~
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.1.1.zip
$ wget -O opencv\_contrib.zip https://github.com/opencv/opencv\_contrib/archive/4.1.1.zip
$ unzip opencv.zip
$ unzip opencv\_contrib.zip
$ mv opencv-4.1.1 opencv
$ mv opencv\_contrib-4.1.1 opencv\_contrib

For this blog post, we’ll be using **OpenCV 4.1.1**; however, as newer versions of OpenCV are released you can update the corresponding version numbers.

#### Increasing your SWAP space

Before you start the compile you must _**increase your SWAP space**_. Increasing the SWAP will enable you to compile OpenCV with _**all four cores**_ of the Raspberry Pi _(and_ without the compile hanging due to memory exhausting).

Go ahead and open up your `/etc/dphys-swapfile` file:

$ sudo nano /etc/dphys-swapfile

…and then edit the `CONF_SWAPSIZE` variable:

\# set size to absolute value, leaving empty (default) then uses computed value
#   you most likely don't want this, unless you have an special disk situation
# CONF\_SWAPSIZE=100
CONF\_SWAPSIZE=2048

Notice that I’m increasing the swap from 100MB to **2048MB**. This is critical to compiling OpenCV with multiple cores on Raspbian Buster.

_**2019-11-21 Update:** Our testing has shown that a 2048MB swap is most effective to prevent lock-ups while OpenCV compiles._

Save and exit via `ctrl + x` , `y` , `enter` .

_**If you do not increase SWAP it’s very likely that your Pi will hang during the compile.**_

From there, restart the swap service:

$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start

_**Note:** Increasing swap size is a great way to burn out your Raspberry Pi microSD card. Flash-based storage has a 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 OpenCV + Python just in case your card dies unexpectedly early. You can read more about large swap sizes corrupting memory cards on [this page](https://www.bitpi.co/2015/02/11/how-to-change-raspberry-pis-swapfile-size-on-rasbian/)._

#### Compile and install OpenCV 4 on Raspbian Buster

We’re now ready to compile and install the full, optimized OpenCV library on the Raspberry Pi 4.

Ensure you are in the `cv` virtual environment using the `workon` command:

$ workon cv

Then, go ahead and install NumPy (an OpenCV dependency) into the Python virtual environment:

$ pip install numpy

And from there configure your build:

$ cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE\_BUILD\_TYPE=RELEASE \\
    -D CMAKE\_INSTALL\_PREFIX=/usr/local \\
    -D OPENCV\_EXTRA\_MODULES\_PATH=~/opencv\_contrib/modules \\
    -D ENABLE\_NEON=ON \\
    -D ENABLE\_VFPV3=ON \\
    -D BUILD\_TESTS=OFF \\
    -D INSTALL\_PYTHON\_EXAMPLES=OFF \\
    -D OPENCV\_ENABLE\_NONFREE=ON \\
    -D CMAKE\_SHARED\_LINKER\_FLAGS=-latomic \\
    -D BUILD\_EXAMPLES=OFF ..

There are four CMake flags I’d like to bring to your attention:

*   **(1)** NEON and **(2)** VFPv3 optimization flags have been enabled. These lines ensure that you compile the fastest and most optimized OpenCV for the ARM processor on the Raspberry Pi (**Lines 7 and 8**).
    *   _**Note:** The **Raspberry Pi Zero W** hardware is not compatible with NEON or VFPv3. Be sure to remove **Lines 7 and 8** if you are compiling for a Raspberry Pi Zero W._
*   **(3)** Patented “NonFree” algorithms give you the full install of OpenCV (**Line 11**).
*   And by drilling into OpenCV’s source, it was determined that we need the **(4)** `-latomic` shared linker flag (**Line 12**).

I’d like to take a second now to bring awareness to a **common pitfall** for beginners:

*   In the terminal block above, you change directories into `~/opencv/` .
*   You then create a `build/` directory therein and change directories into it.
*   **If you try to execute CMake without being in the `~/opencv/build` directory, CMake will fail.** Try running `pwd` to see which working directory you are in _before_ running `cmake` .

The `cmake` command will take about 3-5 minutes to run as it prepares and configures OpenCV for the compile.

When CMake finishes, be sure to inspect the output of CMake under the Python 3 section:

[![Image 8](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20417'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_cmake.jpg)

**Figure 7:** CMake configures your OpenCV 4 compilation from source on your Raspberry Pi 4 running Buster.

Notice how the `Interpreter` , `Libraries` , `numpy` , and `packages` path variables have been properly set. Each of these refers to our `cv` virtual environment.

Now go ahead and **scroll up** to ensure that the **“Non-Free algorithms”** are set to be installed:

[![Image 9](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20417'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_cmake_nonfree.jpg)

**Figure 8:** Installing OpenCV 4 with “Non-free algorithms” on Raspbian Buster.

As you can see, “Non-free algorithms” for OpenCV 4 will be compiled + installed.

Now that we’ve prepared for our OpenCV 4 compilation, it is time to launch the compile process using all four cores:

$ make -j4

[![Image 10](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20424'%3E%3C/svg%3E)](https://pyimagesearch.com/wp-content/uploads/2019/09/install_opencv4_buster_make_complete.jpg)

**Figure 9:** We used Make to compile OpenCV 4 on a Raspberry Pi 4 running Raspbian Buster.

Running `make` could take anywhere from 1-4 hours depending on your Raspberry Pi hardware (this tutorial is compatible with the Raspberry Pi 3B, 3B+, and 4). The Raspberry Pi 4 is the fastest at the time of this writing.

Assuming OpenCV compiled without error (as in my screenshot above), you can install your optimized version of OpenCV on your Raspberry Pi:

$ sudo make install
$ sudo ldconfig

#### Reset your SWAP

_**Don’t forget to go back**_ to your `/etc/dphys-swapfile` file and:

1.  Reset `CONF_SWAPSIZE` to 100MB.
2.  Restart the swap service.

#### Sym-link your OpenCV 4 on the Raspberry Pi

Symbolic links are a way of pointing from one directory to a file or folder elsewhere on your system. For this sub-step, we will sym-link the `cv2.so` bindings into your `cv` virtual environment.

Let’s proceed to create our sym-link. Be sure to [use “tab-completion”](https://www.howtogeek.com/195207/use-tab-completion-to-type-commands-faster-on-any-operating-system/) for all paths below (rather than copying these commands blindly):

$ cd /usr/local/lib/python3.7/site-packages/cv2/python-3.7
$ sudo mv cv2.cpython-37m-arm-linux-gnueabihf.so cv2.so
$ cd ~/.virtualenvs/cv/lib/python3.7/site-packages/
$ ln -s /usr/local/lib/python3.7/site-packages/cv2/python-3.7/cv2.so cv2.so

Keep in mind that the exact paths may change and you should [use “tab-completion”](https://www.howtogeek.com/195207/use-tab-completion-to-type-commands-faster-on-any-operating-system/).

### Step 5: Testing your OpenCV 4 Raspberry Pi BusterOS install

As a quick sanity check, access the `cv` virtual environment, fire up a Python shell, and try to import the OpenCV library:

$ cd ~
$ workon cv
$ python
>>> import cv2
>>> cv2.\_\_version\_\_
'4.1.1'
>>>

**Congratulations!** You’ve just installed an OpenCV 4 on your Raspberry Pi.

If you are looking for some fun projects to work on with OpenCV 4, be sure to checkout my [Raspberry Pi archives](https://pyimagesearch.com/tag/raspberry-pi/).

### Frequently Asked Questions (FAQ)

**Q: What do I do when I encounter an `"undefined symbol: __atomic_fetch_add8"` error related to `libatomic.so`?**

A: The pip install has been giving readers troubles since OpenCV 4.1.1 (around the November 2019 timeframe). Be sure to install version `4.1.0.25` :

`$ pip install opencv-contrib-python==4.1.0.25`

What’s next?
------------

[![Image 11](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20338'%3E%3C/svg%3E)](https://pyimagesearch.com/raspberry-pi-for-computer-vision/)

Ready to put your Raspberry Pi and OpenCV install to work?

My brand new book, [_Raspberry Pi for Computer Vision_](https://pyimagesearch.com/raspberry-pi-for-computer-vision/), has **over 40 Computer Vision and Deep Learning projects** for embedded computer vision and Internet of Things (IoT) applications. You can build upon the projects in the book to solve problems around your home, business, and even for your clients. **Each of these projects place an emphasis on:**

*   Learning by doing
*   Rolling up your sleeves
*   Getting your hands dirty in code and implementation
*   Building _actual, real-world projects_ using the Raspberry Pi

**A handful of the highlighted projects include:**

*   Daytime and nighttime wildlife monitoring
*   Traffic counting and vehicle speed detection
*   Deep Learning classification, object detection, and instance segmentation on resource-constrained devices
*   Hand gesture recognition
*   Basic robot navigation
*   Security applications
*   Classroom attendance
*   _…and many more!_

The book also covers deep learning using the **Google Coral** and **Intel Movidius NCS** coprocessors along with **NVIDIA Jetson Nano** board.

If you’re interested in studying Computer Vision and Deep Learning on embedded devices, [_**you won’t find a better book than this one!**_](https://pyimagesearch.com/raspberry-pi-for-computer-vision/)

[Pick up your copy of _Raspberry Pi for Computer Vision_ today!](https://pyimagesearch.com/raspberry-pi-for-computer-vision/)

Summary
-------

In today’s tutorial, you learned how to install OpenCV 4 on your Raspberry Pi 4 running the Raspbian Buster operating system via two methods:

*   A simple **pip install** (fast and easy)
*   **Compiling from source** (takes longer, but gives you the full OpenCV install/optimizations)

The pip method to install OpenCV 4 is _by far the easiest way_ to install OpenCV (and the method I _recommend_ for 90% of projects). It is especially great for beginners too.

If you need the full install of OpenCV, you must compile from source. Compiling from source ensures that you have the full install including the “contrib” module with patented (“NonFree”) algorithms.

**While compiling from source is both (1) more complicated, and (2) more time-consuming, it is currently the only way to access all features of OpenCV.**

I hope you enjoyed today’s tutorial!

And if you’re ready to put your RPi and OpenCV install to work, be sure to check out my book, **[_Raspberry Pi for Computer Vision_](https://pyimagesearch.com/raspberry-pi-for-computer-vision/)** — inside the book you’ll learn how to build practical, real-world Computer Vision and Deep Learning applications on the Raspberry Pi, Google Coral, Movidius NCS, and NVIDIA Jetson Nano.

**Be be notified when future tutorials are published on the PyImageSearch blog (and download my free 17-page CV and DL Resource Guide PDF), _just enter your email address in the form below!_**

![Image 12](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20410%20567'%3E%3C/svg%3E)

#### Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF

Enter your email address below to **join the PyImageSearch Newsletter** and **download my FREE 17-page Resource Guide PDF** on Computer Vision, OpenCV, and Deep Learning.