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 { 
 
  private: 
 
  // histogram parameters 
  float hranges[2]; 
   const float* ranges[3]; 
   int channels[3]; 
 
  float threshold;           // decision threshold 
  cv::Mat histogram;         // input histogram  
 
  public: 
 
  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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.