Book Image

Raspberry Pi Computer Vision Programming

By : Ashwin Pajankar
Book Image

Raspberry Pi Computer Vision Programming

By: Ashwin Pajankar

Overview of this book

<p>This book will provide you with the skills you need to successfully design and implement your own Raspberry Pi and Python-based computer vision projects.</p> <p>From the beginning, this book will cover how to set up your Raspberry Pi for computer vision applications, exploring the basics of OpenCV, and how to design and implement real-life computer vision applications on your own. By sequentially working through the steps in each chapter, you will quickly be able to master the features of OpenCV. In the end of the book, you will also be introduced to SimpleCV, which is another powerful computer vision library for Python. Featuring plenty of coding examples and exercises, this book offers you an unparalleled learning experience.</p>
Table of Contents (17 chapters)
Raspberry Pi Computer Vision Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
5
Let's Make Some Noise
Index

Arithmetic operations on images


In this section, we will have a look at the various arithmetic operations that can be performed on images. Images are represented as matrices in OpenCV. So, arithmetic operations on images are similar to the arithmetic operations on matrices. Images must be of the same size for you to perform arithmetic operations on the images, and these operations are performed on individual pixels.

  • cv2.add(): This function is used to add two images, where the images are passed as parameters.

  • cv2.subtract(): This function is used to subtract an image from another.

Note

We know that the subtraction operation is not commutative. So, cv2.subtract(img1,img2) and cv2.(img2,img1) will yield different results, whereas cv2.add(img1,img2) and cv2.add(img2,img1) will yield the same result as the addition operation is commutative. Both the images have to be of same size and type, as explained before.

Check out the following code:

import cv2
img1 = cv2.imread('/home/pi/book/test_set/4.2...