void draw_Histogram(const cv::Mat &src_im, cv::Mat &hist_im){ //use filitchp made libraly //github : "https://github.com/filitchp/opencv-histlib" // //引数 -> 入力画像,ヒストグラム用のMat型 cv::Mat dst; if(src_im.channels() == 1) cv::cvtColor(src_im, dst, CV_GRAY2BGR); else src_im.copyTo(dst); CHistLib *Histogram = new CHistLib; cv::MatND HistB, HistG, HistR; Histogram->ComputeHistogramBGR(dst, HistB, HistG, HistR); Histogram->DrawHistogramBGR(HistB, HistG, HistR, hist_im); delete Histogram; }
//----------------------------------------------------------------------------- // Description: // This example draws a color histogram from a photo. It is broken up into // two steps to show how get access to the histogram vectors //----------------------------------------------------------------------------- void DrawPhotoBgrHistogram() { CHistLib Histogram; // Open the image Mat ImageBGR = imread("images/sunset.jpg"); assert(!ImageBGR.empty()); // Generate a color channel (BGR) histogram Mat HistImageBGR; MatND HistB; MatND HistG; MatND HistR; Histogram.ComputeHistogramBGR(ImageBGR, HistB, HistG, HistR); Histogram.DrawHistogramBGR(HistB, HistG, HistR, HistImageBGR); // Save the histogram image string ImageName("sunset.bgr.hist.png"); if (imwrite(ImageName, HistImageBGR)) { cout << "Created BGR histogram: " << ImageName << endl; } }