Title: Raspbian + OpenCV pre-configured and pre-installed. - PyImageSearch

URL Source: https://pyimagesearch.com/2016/11/21/raspbian-opencv-pre-configured-and-pre-installed/

Published Time: 2016-11-21T15: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)](https://pyimagesearch.com/wp-content/uploads/2016/11/raspbian_img_header.jpg)

_**Updated:** September 16th, 2019_

Ever since I wrote the first PyImageSearch tutorial on installing [OpenCV + Python on the Raspberry Pi B+ back in February 2015](https://pyimagesearch.com/2015/02/23/install-opencv-and-python-on-your-raspberry-pi-2-and-b/) it has been my _dream_ to offer a **_downloadable, pre-configured_** Raspbian .img file with OpenCV pre-installed.

**Since November 2016** (the original publish date of this post), **this dream has been a reality**.

I am pleased to announce that the following products ship with my downloadable Raspbian .img files **_pre-configured and pre-installed:_**

*   **_[Practical Python and OpenCV](https://pyimagesearch.com/practical-python-opencv/)_** (_Quickstart_ and _Hardcopy Bundles)_
*   _[**Raspberry Pi for Computer Vision**](https://pyimagesearch.com/raspberry-pi-for-computer-vision/) (Hobbyist, Hacker,_ and _Complete Bundles)_

There are **two files** included:

*   `Raspbian3B_4B.img.gz`  (compatible with RPi 3B, 3B+, 4B \[1GB, 2GB, and 4GB models\])
*   `RaspbianZeroW.img.gz`  (compatible with Pi Zero W)

All you have to do is download the .img files, flash the appropriate one to your SD card using BalenaEtcher, and boot your Pi.

From there, you’ll have a _complete Python + OpenCV development environment_ at your fingertips, all without the hassle of configuring, compiling, and installing OpenCV.

**To learn more about the Raspbian .img files, _keep reading._**

Raspbian Buster + OpenCV 4 out-of-the-box
-----------------------------------------

I went back to my recent tutorials on installing OpenCV on the Raspberry Pi and computed the amount of time it takes to perform each step.

You know what I found?

Even if you know _exactly_ what you are doing it can take significant time to compile and install OpenCV on your Raspberry Pi:

*   Over **55 minutes** on the Raspberry Pi 4B
*   Over **_2.2 hours_** to compile the Raspberry Pi 3B+.
*   Over **14 hours** to compile on the Raspberry Pi Zero W

In the past, I’ve emailed a sample of novice readers who successfully installed OpenCV on their Pi and asked how long it took them to complete the compile and installation process.

Perhaps not surprisingly I found the amount of time for novice readers to install OpenCV on their Raspberry Pi 3B+jumped nearly _4x_ to over **_8.7 hours (even longer for the Zero W)_**. I haven’t conducted a similar survey for the Raspberry Pi 4, but my guess is that it would take most people about 4 hours to configure their Raspberry Pi 4.

Clearly, the barrier to entry for many PyImageSearch readers trying to learn OpenCV and computer vision is _getting OpenCV itself installed_ on their Raspberry Pi.

In an effort to help these readers get the most out of their Raspberry Pi, I have decided to release my own _personal_ Raspbian .img files that have OpenCV **_pre-configured and pre-installed._**

**By bundling the pre-configured Raspbian .img together with either (1) [_Practical Python and OpenCV_](https://pyimagesearch.com/practical-python-opencv/), and/or (2) [_Raspberry Pi for Computer Vision_](https://pyimagesearch.com/raspberry-pi-for-computer-vision/) my goal is to:**

1.  Jumpstart your computer vision education by skipping the tedious process of installing OpenCV + Python on your Raspberry Pi.
2.  Provide you with a book with the best introduction to the world of computer vision and image processing that you can possibly get.

Of course, I will continue to _create_, _support_, and _provide help_ to any PyImageSearch reader who is using the many [free tutorials I offer on installing OpenCV + Python on the Raspberry Pi](https://pyimagesearch.com/opencv-tutorials-resources-guides/).

Again, this pre-configured Raspbian .img is intended for PyImageSearch readers who want to _**save time**_ and _**jumpstart their computer vision education.**_

If this doesn’t sound like you, no worries, I totally understand — I’ll be still be providing free tutorials to help you get OpenCV up and running on your Raspberry Pi. Just keep in mind that [customers of mine receive priority support from me](https://pyimagesearch.com/faqs/single-faq/can-i-send-you-emails-or-ask-you-questions/) (while you’re on that page [be sure to check out my other FAQs](https://pyimagesearch.com/faqs)).

The rest of this document describes how to _**install and use**_ the Raspbian pre-configured .img file included in your purchase of either_:_

*   **_[Practical Python and OpenCV](https://pyimagesearch.com/practical-python-opencv/)_** (_Quickstart_ and _Hardcopy Bundles)_
*   _[**Raspberry Pi for Computer Vision**](https://pyimagesearch.com/raspberry-pi-for-computer-vision/) (Hobbyist, Hacker,_ and _Complete Bundles)_

At the end of this guide, you’ll also find answers to frequently asked questions regarding the Raspbian + OpenCV .img file. If you have a question that is not covered in FAQ, [please send me a message](https://pyimagesearch.com/contact/).

### Download and unpack the archive

When you receive the link to your purchase, be sure to download the book, code, videos, and Raspbian. Each file is in the form of a .zip. The `Raspbian.zip`  contains the preconfigured images and a `README.txt`  file.

Go ahead and unzip the files using your favorite unarchiving utility (7zip, Keka, etc.). There is no need to extract the included .gz files since we will flash with them directly.

After you unzip `Raspbian.zip`  your folder should look like this:

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

**Figure 1:** After downloading the Raspbian.zip file, unpack it to obtain the .img.gz file that you’ll flash to your SD card directly with BalenaEtcher.

### Write OS image to a 32GB microSD card using BalenaEtcher

This Raspbian .img will work _**only**_ on **32GB microSD cards**. The .imgs are too large for 8GB or 16GB cards. To my knowledge, the Raspberry Pi does not support 64GB+ microSD cards.

I _recommend_ the high quality Sandisk 32GB 98MB/s cards. They are available at [Amazon](https://www.amazon.com/SanDisk-Ultra-microSDXC-Memory-Adapter/dp/B073JWXGNT/ref=sr_1_1?keywords=sandisk+microsd+32gb&qid=1568666896&sr=8-1) and many online distributors.

To write the pre-configured Raspbian .img to your card simply follow the [official Raspberry Pi documentation](https://www.raspberrypi.org/documentation/installation/installing-images/README.md). The recommended tool is [**BalenaEtcher**](https://www.balena.io/etcher/) (compatible with Mac, Linux, and Windows).

**BalenaEtcher can handle compressed files** such as .gz _(no need to extract the .img.gz before loading into Etcher)_.

[![Image 3](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/2016/11/raspbian_img_balenaetcher.jpg)

**Figure 2:** Flashing your pre-configured Raspbian .img with BalenaEtcher for your Raspberry Pi.

### Booting your Pi for the first time

After writing the the Raspbian .img to your card, insert the card into your Pi and boot it up.

The username is `pi` and the password is `raspberry`.

**On the first boot, your Raspbian filesystem needs to be expanded to fit the SD card.**

This means that you have to run `raspi-config => Advanced => Expand Filesystem`  manually.

After the expansion has completed your Pi will reboot and you will be able to use it as normal (the expansion of the filesystem is only necessary on the first boot).

Here is a screenshot of the disk utilization on my Pi after it has been auto-expanded:

[![Image 4](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/2016/11/raspbian_img_df-h.jpg)

**Figure 3:** After booting my Raspberry Pi for the first time your filesystem will be expanded to utilize the entire disk.

Notice that my _entire_ 32GB card is available and 35% is in use.

### Default WiFi

By default, your Raspberry Pi will attempt to connect to a network named `pyimagesearch`  with passphrase `computervision` .

This is useful if you are in a pickle:

*   Maybe you just flashed your microSD and you need to get connected quickly.
*   Perhaps you aren’t near your typical wireless and you want to hotspot your phone so that your Pi and laptop connect through your phone’s wireless network. Works with iPhone and Android.
*   Maybe you forgot your keyboard/mouse/HDMI screen and you need to do everything via SSH and VNC, but you can’t easily connect to your Pi at the moment.  Refer to this tutorial about [remote development and connectivity with your Raspberry Pi](https://pyimagesearch.com/2019/07/01/remote-development-on-the-raspberry-pi-or-amazon-ec2/).

We’ve used this method to get connected many times in the field. It is convenient, but it is a security risk. While we do not recommend using this wireless network long term since this password is public (in nearly all deployment applications you should delete the network + password from your Pi), it is a great way to get connected if you just flashed a microSD. We also recommend changing the default password associated with the username of your Raspberry Pi.

### Using Python and OpenCV on your Raspberry Pi

In order to gain access to OpenCV 4 (and OpenCV 3) with Python 3 bindings we leverage Python virtual environments. Each Python virtual environment is totally independent from one another ensuring there are no dependency or versioning issues.

In the remainder of this section, I explain (1) what Python virtual environments are and (2) how to access the Python 3 + OpenCV 3/4 environments.

#### What are Python virtual environments?

At the very core, Python virtual environments allow us to create _isolated, independent_ environments for each of our Python projects. This implies that **each project can have its own set of** **dependencies**, _regardless_ of which dependencies another project has.

In the context of OpenCV, this allows us to have _one_ virtual environment for OpenCV 4 and then _another_ virtual environment for OpenCV 3. Furthermore, we can have Intel OpenVINO and Google Coral virtual environments.

For a detailed look at Python virtual environments please refer to [this tutorial](https://realpython.com/blog/python/python-virtual-environments-a-primer/).

#### Python 2.7 support is deprecated

On January 1, 2020, Python.org will no longer be updating Python 2.7 (that goes for security updates too). Read [Python 2.7’s sunset announcement here](https://www.python.org/doc/sunset-python-2/).

**PyImageSearch officially no longer supports Python 2.7.** All future code is Python 3-compatible only.

#### What virtual environments are on the .imgs?

The **Raspberry Pi 3B/3B+/4B** .img contains the following environments:

*   `py3cv4` : Python 3.7 and OpenCV 4.1.1
*   `py3cv3` : Python 3.7 and OpenCV 3.4.7
*   `openvino` : Python 3.7 and OpenCV 4.1.1-openvino ([OpenVINO](https://software.intel.com/en-us/openvino-toolkit) is an Intel deep learning + hardware-optimized toolkit by Intel)
*   `coral` : Python 3.7 and OpenCV 4.1.1
*   `gopigo`  : Python 3.7 and OpenCV 4.1.1

The **Raspberry Pi Zero W** .img contains the following environments:

*   `py3cv4` : Python 3.7 and OpenCV 4.1.1
*   `py3cv3` : Python 3.7 and OpenCV 3.4.7

#### Accessing a virtual environment

There are two ways to access our virtual environments on the Raspbian .imgs.

**Option 1:** Use the `workon`  command

If, for example, you desire to use the Python 3 + OpenCV 4.1.1  environment simply use the workon command and the environment name:

$ workon py3cv4
(py3cv4) $

Notice that the bash prompt is then preceded with the environment name in parentheses.

_**Note:** The **OpenVINO** environment requires that you use the **Option 2** method below._

**Option 2:** Use the `source`  command

You can also just use the following command with the start scripts located in your home directory:

$ source ~/start\_py3cv4.sh
Starting Python 3.7 with OpenCV 4.1.1 bindings...
(py3cv4) $

If you use OpenVINO, an additional Intel-provided script will be called automatically via the “start” script:

$ source ~/start\_openvino.sh
Starting Python 3.7 with OpenCV-OpenVINO 4.1.1 bindings...
\[setupvars.sh\] OpenVINO environment initialized
(py3cv4) $

Your terminal will look like similar to this (I’m SSH’ed into my Raspberry Pi from macOS):

[![Image 5](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/2016/11/raspbian_img_openvino.jpg)

**Figure 4:** Starting the OpenVINO environment for the Movidius NCS on a Raspberry Pi pre-configured .img.

### Executing code from my books on your Raspberry Pi

There are multiple methods to access the source code for _Practical Python and OpenCV_ or _Raspberry Pi for Computer Vision_ on your Pi. The first is to use Chromium, Raspbian’s built-in web browser to download the .zip archive(s):

![Image 6: Figure 7: Downloading the source code from Practical Python and OpenCV using the Raspberry Pi web browser.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20375'%3E%3C/svg%3E)

**Figure 5:** Downloading the source code from Practical Python and OpenCV using the Raspberry Pi web browser.

Simply download the .zip directly to your Pi.

If the code currently resides on your laptop/desktop, you may also use your favorite SFTP/FTP client and transfer the code from your system to your Pi:

![Image 7: Figure 8: Utilize a SFTP/FTP client to transfer the Practical Python and OpenCV code from your system to the Raspberry Pi.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20438'%3E%3C/svg%3E)

**Figure 6:** Utilize a SFTP/FTP client to transfer the Practical Python and OpenCV code from your system to the Raspberry Pi.

Or you may want to manually write the code on the Pi using the built-in text editor as you follow along with the book:

![Image 8: Figure 9: Using the built-in text editor that ships with the Raspberry Pi to write code.](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20375'%3E%3C/svg%3E)

**Figure 7:** Using the built-in text editor that ships with the Raspberry Pi to write code.

I would suggest either downloading the book’s source code via web browser or using SFTP/FTP as this also includes the _datasets_ utilized in the book as well. However, manually coding along is a _great way to learn_ and I highly recommend it as well!

For more tips on how to **work remotely with your Raspberry Pi**, be sure to read my [**_Remote development on the Raspberry Pi_**](https://pyimagesearch.com/2019/07/01/remote-development-on-the-raspberry-pi-or-amazon-ec2/) blog post.

### Frequently Asked Questions (FAQ)

In this section, I detail the answers to frequently asked questions regarding the Raspberry Pi .img file.

#### Which Raspbian images are compatible with which respective hardware?

Here is the compatibility listing:

*   `Raspbian3B_4B.img.gz` :
    *   Raspberry Pi 4B (1GB, 2GB, and 4GB models)
    *   Raspberry Pi 3B+
    *   Raspberry Pi 3B
*   `RaspbianZeroW.img.gz` :
    *   Raspberry Pi Zero W

#### What if I want to install OpenCV + Python on my Raspberry Pi by myself?

By all means, I encourage you to do so. It’s a great exercise and you’ll learn _a lot_ about the Linux environment. I would suggest you follow one of my _**[many free tutorials](https://pyimagesearch.com/opencv-tutorials-resources-guides/)**_ on installing OpenCV + Python your Raspberry Pi.

Again, this pre-configured Raspbian image is intended for readers who want to _skip the install process_ and _jumpstart their education_.

#### How long will it take to install Python + OpenCV by hand?

I’ve ran the numbers and even if you know _exactly_ what you are doing it will take a bare minimum of **55 minutes** to compile and install OpenCV on a Raspberry Pi 4 and approximately **14 hours** on the Raspberry Pi Zero W.

If you have _never_ installed OpenCV before or you are _not familiar with Linux-based environments_ that number can easily jump to many times those numbers based on my survey of novice readers who successfully installed OpenCV on their Raspberry Pi.

In fact, to install everything on the **Raspberry Pi Zero W** including 2 environments (2 compiles of OpenCV) **it took approximately 6 days** (including overnight compiles).

It really comes down to _how much you value your time_ and _how quickly you want to get started learning computer vision_. I always encourage you to use my [free tutorials on installing OpenCV on the Raspberry Pi](https://pyimagesearch.com/opencv-tutorials-resources-guides/), but if you want to save yourself time (and headaches), then definitely consider going with the pre-configured Raspbian .img.

#### Which _Practical Python and OpenCV_ bundles is the Raspbian image included in?

The pre-configured Raspbian image is included in both the **_Quickstart Bundle_** and **_Hardcopy Bundle_** of _[Practical Python and OpenCV](https://pyimagesearch.com/practical-python-opencv/)_. The pre-configured Raspbian image is _not_ included in the Basic Bundle.

#### Which _Raspberry Pi for Computer Vision_ bundles is the Raspbian image included in?

The pre-configured Raspbian image is included all bundles: _**Hobbyist, Hacker,**_ and _**Complete Bundles.**_

#### After installing your distribution of Raspbian, how do I access Python + OpenCV?

See the _“Using Python and OpenCV on your Raspberry Pi”_ section above.

#### Is Wolfram’s Mathematica included in your Raspbian distribution?

No, I am not legally allowed to distribute a modified version of Raspbian (that is part of a product) with Mathematica installed.

#### How did you reduce the size of the Raspbian image file?

To start, I removed unneeded software such as Wolfram’s Mathematica and LibreOffice. Removing these two pieces of software alone saved nearly 1GB of space.

From there, the size of the main partition was reduced by zeroing all bits and compressing the file to .gz format.

#### **Which Operating System version of Raspbian is included?**

The latest .imgs run Raspbian Buster.

#### I have your previous StretchOS image. Why won’t the `workon` command work?

My previous .imgs did not have the virtualenvwrapper settings in the `~/.bashrc`  (they were placed in `~/.profile` ).

Therefore, you need to either (1) copy the virtualenvwrapper settings from `~/.profile`  to `~/.bashrc` , or (2) source the profile first via `source ~/.profile`.

#### What Python packages are installed on the Raspberry Pi?

After accessing any virtual environment (see _“Accessing a virtual environment”_) run `pip freeze`  to see a full list of Python packages installed.

In short, I have included **_all necessary Python packages_** you will need to be successful executing the examples in **_Raspberry Pi for Computer Vision_** and **_Practical Python and OpenCV_**, including OpenCV, NumPy, SciPy, scikit-learn, scikit-image, mahotas, and _many others_. Click the following image to enlarge it so you can see all the packages:

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

**Figure 8:** A listing of the packages installed in each of the environments on the Raspberry Pi Raspbian .img.

#### Where can I learn more about Python virtual environments?

My favorite resource and introduction to Python virtual environments can be found [here](https://realpython.com/blog/python/python-virtual-environments-a-primer/). I also discuss them in the first half of [this blog post](https://pyimagesearch.com/2016/05/02/accessing-rpi-gpio-and-gpio-zero-with-opencv-python/).

#### Where can I purchase a copy of _Practical Python and OpenCV?_

To purchase your copy of _Practical Python and OpenCV_, [simply click here](https://pyimagesearch.com/practical-python-opencv/), select your bundle (I recommend either the _Quickstart Bundle_ or the _Hardcopy Bundle_), and checkout.

#### Where can I purchase a copy of _Raspberry Pi for Computer Vision?_

To purchase your copy of _Raspberry Pi for Computer Vision_, [simply click here](https://pyimagesearch.com/raspberry-pi-for-computer-vision/), select your bundle (I recommend either the _Hacker Bundle_ or the _Complete Bundle_ if you really want to master the Raspberry Pi), and checkout.

#### Can I purchase the .img as a standalone product?

The .img files are intended to accompany my books as added benefits. I would recommend purchasing a book to gain access to the .img.

#### I have another question.

If you have a question not listed in this FAQ, [please send me a message](https://pyimagesearch.com/contact/).

Sound good?
-----------

[![Image 10](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20600%20361'%3E%3C/svg%3E)](https://pyimagesearch.com/faqs/single-faq/what-books-and-courses-do-you-offer-2/)

**Figure 9:** Purchase (1) [_Raspberry Pi for Computer Vision_](https://pyimagesearch.com/raspberry-pi-for-computer-vision/), or (2) [_Practical Python and OpenCV + Case Studies_](https://pyimagesearch.com/practical-python-opencv/) to get ahold of the pre-configured Raspbian .img files!

If you’re ready to put the .img to use on all of the Raspberry Pis you own, just purchase one of my books that come with the .img.

To purchase your copy of _Raspberry Pi for Computer Vision_, _[**just click here**](https://pyimagesearch.com/raspberry-pi-for-computer-vision/)._ All bundles come with the pre-configured Raspbian .img files.

Or to purchase your copy of _Practical Python and OpenCV_, _**[just use this link](https://pyimagesearch.com/practical-python-opencv/)**_. You will find the pre-configured Raspbian .img files inside both the _Quickstart Bundle_ and the _Hardcopy Bundle_ (the _Basic Bundle_ does not include the Raspbian .img).

To see all the products I offer, _[click here](https://pyimagesearch.com/faqs/single-faq/what-books-and-courses-do-you-offer-2/)_.

![Image 11](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.