直方图及模板

Posted on 2020-05-27 16:55  金色的省略号  阅读(199)  评论(0编辑  收藏  举报

  在分析图像,物体,视频信息的过程中,我们常常把看到的对象,用直方图Histogram表示,直方图广泛应用于计算机视觉应用,直方图是一种用来揭示数据分布的统计特性的工具

  OpenCV提供一种数据类型来表达直方图,这个数据类型可以表达一维至多维的直方图,并包括必要的数据以支持均匀或非均匀的组宽,它配备各种有用的函数来方便对直方图进行各种操作,可以使用cv::Mat,也可以使用vector<>或者cv::SparseMat

  OpenCV使用数组来表示直方图,这里的数组和用来表示其他数据的数组没有任何区别,当我们把一个数组视为直方图时,它就具有和普通数组完全不同的含义,例如,若一个n维数组被视为直方图,数组中的每个元素表达的是该n维直方图中对应组中的计数结果; 

  cv::calcHist(): 可以从一个或多个数组中创建直方图,直方图的维度取决于输入数组的数量

    void cv::calcHist(
        const cv::Mat* images, // C-style array of images, 8U or 32F
        int nimages, // number of images in 'images' array
        const int* channels, // C-style list of int's, lists channels
        cv::InputArray mask, // in 'images' count, iff 'mask' nonzero
        cv::OutputArray hist, // output histogram array
        int dims, // hist dimensionality < cv::MAX_DIMS (32)
        const int* histSize, // C-style array, hist sizes in each dim
        const float** ranges, // C-style array, 'dims' pairs set bin sizes
        bool uniform = true, // true for uniform binning
        bool accumulate = false // true, add to 'hist' else replace
    );