opencv灰度直方图统计

auto calcGrayHist=[](cv::Mat arg)->auto {
        //opencv-master\modules\imgproc\src\histogram.cpp
        constexpr int channels[]={ 0 };
        constexpr int dims=1;
        constexpr int histSize[]={ 256 };
        constexpr float range[]={ 0.f,255.f };
        const float *ranges[]={ range };
        constexpr bool uniform=true;
        constexpr bool accumulate=false;

        std::vector> varAns;
        try {

            varAns.resize(histSize[0],0.f);
            cv::MatND varAnsWrap(histSize[0],1,CV_32FC1,varAns.data());

            cv::calcHist(&arg,1,
                (const int*)channels,
                { /*mask*/ },
                varAnsWrap,
                dims,
                (const int*)histSize,
                (const float**)ranges,
                uniform,accumulate);

        }
        catch (...) {
            CPLUSPLUS_EXCEPTION(false);
            varAns.clear();
        }
        return std::move(varAns);
    };

opencv灰度直方图统计_第1张图片

cv::calcHist参数众多(设计失败的典型案例),只有结合opencv源代码才看得明白,所幸99%的情况下只用灰度直方图统计即可



你可能感兴趣的:(OpenCV3)