Book Image

OpenCV Computer Vision Application Programming Cookbook Second Edition

By : Robert Laganiere
Book Image

OpenCV Computer Vision Application Programming Cookbook Second Edition

By: Robert Laganiere

Overview of this book

Table of Contents (18 chapters)
OpenCV Computer Vision Application Programming Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Backprojecting a histogram to detect specific image content


A histogram is an important characteristic of an image's content. If you look at an image area that shows a particular texture or a particular object, then the histogram of this area can be seen as a function that gives the probability that a given pixel belongs to this specific texture or object. In this recipe, you will learn how the concept of histogram backprojection can be advantageously used to detect specific image content.

How to do it...

Suppose you have an image and you wish to detect specific content inside it (for example, in the following image, the clouds in the sky). The first thing to do is to select a region of interest that contains a sample of what you are looking for. This region is the one inside the rectangle drawn on the following test image:

In our program, the region of interest is obtained as follows:

   cv::Mat imageROI;
   imageROI= image(cv::Rect(216,33,24,30)); // Cloud region

You then extract the histogram...