Book Image

OpenCV 3 Computer Vision Application Programming Cookbook - Third Edition

By : Robert Laganiere
Book Image

OpenCV 3 Computer Vision Application Programming Cookbook - Third Edition

By: Robert Laganiere

Overview of this book

Making your applications see has never been easier with OpenCV. With it, you can teach your robot how to follow your cat, write a program to correctly identify the members of One Direction, or even help you find the right colors for your redecoration. OpenCV 3 Computer Vision Application Programming Cookbook Third Edition provides a complete introduction to the OpenCV library and explains how to build your first computer vision program. You will be presented with a variety of computer vision algorithms and exposed to important concepts in image and video analysis that will enable you to build your own computer vision applications. This book helps you to get started with the library, and shows you how to install and deploy the OpenCV library to write effective computer vision applications following good programming practices. You will learn how to read and write images and manipulate their pixels. Different techniques for image enhancement and shape analysis will be presented. You will learn how to detect specific image features such as lines, circles or corners. You will be introduced to the concepts of mathematical morphology and image filtering. The most recent methods for image matching and object recognition are described, and you’ll discover how to process video from files or cameras, as well as how to detect and track moving objects. Techniques to achieve camera calibration and perform multiple-view analysis will also be explained. Finally, you’ll also get acquainted with recent approaches in machine learning and object classification.
Table of Contents (21 chapters)
OpenCV 3 Computer Vision Application Programming Cookbook - Third Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Filtering images using low-pass filters


In this first recipe, we will present some very basic low-pass filters. In the introductory section of this chapter, we learned that the objective of such filters is to reduce the amplitude of the image variations. One simple way to achieve this goal is to replace each pixel with the average value of the pixels around it. By doing this, the rapid intensity variations will be smoothed out and thus replaced by more gradual transitions.

How to do it...

The objective of the cv::blur function is to smooth an image by replacing each pixel with the average pixel value computed over a rectangular neighborhood. This low-pass filter is applied as follows:

cv::blur(image,result, cv::Size(5,5)); // size of the filter 

This kind of filter is also called a box filter. Here, we applied it by using a 5x5 filter in order to make the filter's effect more visible. Our original image is the following:

The result of the filter being applied on the preceding image is...