Book Image

Raspberry Pi Computer Vision Programming - Second Edition

By : Ashwin Pajankar
5 (1)
Book Image

Raspberry Pi Computer Vision Programming - Second Edition

5 (1)
By: Ashwin Pajankar

Overview of 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.
Table of Contents (15 chapters)

Arithmetic operations on images

We know that images are nothing but NumPy ndarrays and we can perform arithmetic operations on images just as we can perform them on ndarrays. If we know how to apply numerical or arithmetic operations to matrices, then we should not have any trouble doing the same when the operands for those operations are images. Images must be of the same size and must have the same number of channels for us to perform arithmetic operations on them, and these operations are performed on individual pixels. There are many arithmetic operations, such as addition and subtraction. The first is the addition operation. We can add two images by using either the NumPy Addition or the add() function in OpenCV, as follows:

import cv2
img1 = cv2.imread('/home/pi/book/dataset/4.2.03.tiff', 1)
img2 = cv2.imread('/home/pi/book/dataset/4.2.05.tiff', 1)
cv2.imshow('NumPy Addition', img1 + img2 )
cv2.imshow('OpenCV Addition', cv2.add(img1...