opencv灰度直方图
感觉这个原理就是数学统计吧,直接上代码,哪有错的或者不懂得地方,欢迎交流。
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class jRect { //自己写了个jRect类,感觉是吃饱了撑着吧
public:
jRect(Point p,int w,int h)
:lefttop(p),rect_width(w),rect_height(h){}
Point lefttop;
int rect_width;
int rect_height;
};
void grayhist(Mat &input_gray,Mat &output_histogram, const Scalar &histColor,int hist_width=2);//绘制直方图
void drawjRect(Mat &input,jRect rect, const Scalar &jRectColor);//给直方图外边加个方框,为了好看
int main()
{
Mat src = imread("E://vs_program//images//Sakura_15.jpg");
imshow("src", src);
Mat src_gray;
cvtColor(src,src_gray,CV_BGR2GRAY);
imshow("src_gray", src_gray);
Mat output_histogram;
grayhist(src_gray, output_histogram,Scal