Backprojecting color histograms

Multidimensional histograms can also be backprojected onto an image. Let's define a class that encapsulates the backprojection process. First, we define the required attributes and initialize the data, as follows:

class ContentFinder { 
  // histogram parameters 
  float hranges[2]; 
   const float* ranges[3]; 
   int channels[3]; 
  float threshold;           // decision threshold 
  cv::Mat histogram;         // input histogram  
  ContentFinder() : threshold(0.1f) { 
    // in this class, all channels have the same range 
    ranges[0]= hranges;   
    ranges[1]= hranges;  
    ranges[2]= hranges;  

Next, we define a threshold parameter that will be used to create the binary map that shows the detection result. If this parameter is set to a negative ...

Get OpenCV 4 Computer Vision Application Programming Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.