Home Data Raspberry Pi Computer Vision Programming - Second Edition

Raspberry Pi Computer Vision Programming - Second Edition

By Ashwin Pajankar
books-svg-icon Book
eBook $26.99 $17.99
Print $38.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $26.99 $17.99
Print $38.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Chapter 2: Preparing the Raspberry Pi for Computer Vision
About this book
Raspberry Pi is one of the popular single-board computers of our generation. All the major image processing and computer vision algorithms and operations can be implemented easily with OpenCV on Raspberry Pi. This updated second edition is packed with cutting-edge examples and new topics, and covers the latest versions of key technologies such as Python 3, Raspberry Pi, and OpenCV. This book will equip you with the skills required to successfully design and implement your own OpenCV, Raspberry Pi, and Python-based computer vision projects. At the start, you'll learn the basics of Python 3, and the fundamentals of single-board computers and NumPy. Next, you'll discover how to install OpenCV 4 for Python 3 on Raspberry Pi, before covering major techniques and algorithms in image processing, manipulation, and computer vision. By working through the steps in each chapter, you'll understand essential OpenCV features. Later sections will take you through creating graphical user interface (GUI) apps with GPIO and OpenCV. You'll also learn to use the new computer vision library, Mahotas, to perform various image processing operations. Finally, you'll explore the Jupyter Notebook and how to set up a Windows computer and Ubuntu for computer vision. By the end of this book, you'll be able to confidently build and deploy computer vision apps.
Publication date:
June 2020
Publisher
Packt
Pages
306
ISBN
9781800207219

 

Chapter 2: Preparing the Raspberry Pi for Computer Vision

In the previous chapter, we learned the fundamentals of single-board computers, computer vision, and OpenCV. We learned the detailed specifications of the Raspberry Pi (RPi) 4B and the RPi Zero W. We also learned how to set up Raspbian OS on all the RPi boards models in detail.

In this chapter, we will learn how to prepare our RPi board for computer vision. Continuing from where we left off in the previous chapter, we will start by installing the OpenCV library for computer vision and the other necessary software for remotely accessing the desktop, as well as Command Prompt. We will learn how to transfer files between an RPi and a Windows PC. We will also learn how to exploit the computation power of the RPi by overclocking it and installing a heatsink on it to reduce the temperature of the processor.

The topics that we'll cover in this chapter are as follows:

  • Remotely logging into the RPi with SSH
  • Remote...
 

Remotely logging into the RPi with SSH

We can remotely access the Command Prompt of the RPi board using various software from Windows. We can run all the Linux commands that do not involve the GUI remotely from Windows. As you may recall, we discussed how to enable SSH with the Raspberry Pi Configuration tool in Chapter 1, Introduction to Computer Vision and Raspberry Pi. It enables remote login through SSH.

In order to get started, follow these steps:

  1. First, we need to install any SSH software available for free. The most popular is PuTTY (https://www.putty.org/). I prefer to use another popular SSH client that comes with SFTP known as the Bitvise SSH client. You can download the installation file for Windows from https://www.bitvise.com/ssh-client-download and install it. After doing that, open the Bitvise SSH client. The following window will appear:

    Figure 2.1 – Bitwise Connection window

    Enter a hostname, username, and password. The hostname is nothing but the...

 

Remote desktop access

The Bitvise SSH client is great for file transfers and accessing the Command Prompt terminal of RPi. However, we need to use another piece of software to access the desktop of RPi remotely. There are two methods we can follow. The first one is VNC (we learned how to enable it in Chapter 1, Introduction to Computer Vision and Raspberry Pi, using the Raspberry Pi Configuration tool), while the other is using Windows' built-in Remote Desktop Connection utility. We can find it in the Windows search bar, as follows:


Figure 2.5 – Remote Desktop Connection option in the Windows search bar

But before we can use it, we need to install xrdp on the RPi. Installing it is very easy. We just need to run the following command at LXTerminal on the RPi:

sudo apt-get install xrdp -y

Information

You might want to read more about xrdp at http://xrdp.org/.

Once xrdp has been installed on the RPi, you need to follow these steps...

 

Installing OpenCV on an RPi board

Follow these steps to install OpenCV on the RPi:

  1. First, we need to install a few dependencies. Run the following command to install all these dependencies:
    sudo apt-get install -y libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev libqtgui4 libqt4-test
  2. Once the installation is successful, we can install OpenCV on the RPi:
    pip3 install opencv-python==4.0.1.24
  3. Once the installation of OpenCV is successful, we can verify it by running the following command:
    python3 -c "import cv2; print(cv2.__version__)"

    The following should be the output:

    4.0.1

This means that the installation is completed and that we can import OpenCV in our Python 3 programs.

Next, we will learn how to overclock the RPi 4B and how to install heatsink on it.

 

Heatsinks and overclocking RPi 4B

Overclocking means running the processors at higher speeds than those that are intended. When we overclock the processors, their temperature tends to rise and they radiate more heat. Raspberry Pi board models do not come with any built-in coolers. You can buy passive heatsinks from many online shops such as Amazon. The following is an example of a heatsink with a fan:

Figure 2.9 – Small heatsink for RPi

The heatsink fan can be powered by connecting it to a 5V or 3.3V power supply. The speed of the fan depends on the voltage, and we can connect it to the RPi power pins. We will learn more about the GPIO and the power pins of RPi in the next chapter. The best and the most effective heatsink that I found was the ICE Tower fan for the RPi 4B (https://www.seeedstudio.com/ICE-Tower-CPU-Cooling-Fan-for-Raspberry-pi-Support-Pi-4-p-4097.html).

The following is my own Pi with the ICE Tower mounted on it:

...
 

Summary

In this chapter, we learned how to remotely log into the RPi and how to access the RPi desktop remotely with RDP. We also learned how to install OpenCV and how to verify it. Also, we learned how to overclock an RPi board.

We will be using all the skills we learned in this chapter throughout this book for accessing the Command Prompt and desktop of Raspbian OS remotely while writing programs for computer vision. We will also use file transfer quite a few times, as well as the OpenCV library in most programs.

In the next chapter, we will learn the basics of Python, NumPy, matplotlib, and the RPi GPIO library. We will also learn about the SciPy ecosystem.

About the Author
  • Ashwin Pajankar

    Ashwin Pajankar is an author, a YouTuber, and an instructor. He graduated from the International Institute of Information Technology, Hyderabad, with an MTech in Computer Science and Engineering. He has been writing programs for over two and a half decades. He is proficient in Linux, Unix shell scripting, C, C++, Java, JavaScript, Python, PowerShell, Golang, HTML, and assembly language. He has worked on single-board computers such as Raspberry Pi and Banana Pro. He is also proficient with microcontroller boards such as Arduino and the BBC Micro:bit. He is currently self-employed and teaches on Udemy and YouTube. He also organizes programming boot camps for working professionals and software companies.

    Browse publications by this author
Latest Reviews (5 reviews total)
I have rated it 5 star because so far it is what I expected but I'm a long way from finishing it. It is a computer imaging starter book and that is what I needed, and so far the detail and explanations are easy to follow and understand without getting in over my head. On that basis, I can tentatively recommend the book, but cannot give a final recommendation until I have finished it.
To many to review.so this is where I end
Good product. Just Started reading.
Raspberry Pi Computer Vision Programming - Second Edition
Unlock this book and the full library FREE for 7 days
Start now