算法实现(不调用函数)
#include
#include
using namespace std;
using namespace cv;
//实现灰度直方图的绘制
void drawpicture(Mat &inpicture, Mat &outpicture)
{
MatND hist;
const int bins = 256;
int hist_size[] = { bins };
float range[] = { 0, 256 };
const float* ranges[] = { range };
int channels[] = { 0 };
calcHist(&inpicture, 1, channels, Mat(), hist, 1, hist_size, ranges, true, false);
double maxnum;
minMaxLoc(hist, 0, &maxnum, 0, 0);
int scale = 1;
int histheight = 256;
for (int i = 0; i < bins; i++)
{
float binvalue = hist.at(i);
int height = cvRound(binvalue*histheight / maxnum);
// 绘制长方形
rectangle(outpicture, Point(i*scale, histheight), Point((i + 1)*scale, histheight