How to do it...

Here, we will make this simpler to use by specializing a class for the case of one-channel, gray-level images. For other types of images, you can always use the cv::calcHist function directly, which offers you all the flexibility that's required. The next section will explain each of its parameters. Then, we are going to implement our histogram class:

  1. Create a Histogram1D class, as follows:
// To create histograms of gray-level images class Histogram1D { private: int histSize[1]; // number of bins in histogram float hranges[2]; // range of values const float* ranges[1]; // pointer to the value ranges int channels[1]; // channel number to be examined public: Histogram1D() { // Prepare default arguments for 1D histogram histSize[0]= ...

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.