19 int main(
int,
char** argv )
24 src =
imread( argv[1], 1 );
30 vector<Mat> bgr_planes;
31 split( src, bgr_planes );
37 float range[] = { 0, 256 } ;
42 Mat b_hist, g_hist, r_hist;
45 calcHist( &bgr_planes[0], 1, 0,
Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
46 calcHist( &bgr_planes[1], 1, 0,
Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
47 calcHist( &bgr_planes[2], 1, 0,
Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
50 int hist_w = 512;
int hist_h = 400;
51 int bin_w =
cvRound( (
double) hist_w/histSize );
61 for(
int i = 1; i < histSize; i++ )
65 Scalar( 255, 0, 0), 2, 8, 0 );
68 Scalar( 0, 255, 0), 2, 8, 0 );
71 Scalar( 0, 0, 255), 2, 8, 0 );
76 imshow(
"calcHist Demo", histImage );
bool empty() const
Returns true if the array has no elements.
Scalar_< double > Scalar
Definition: types.hpp:597
void split(const Mat &src, Mat *mvbegin)
Divides a multi-channel array into several single-channel arrays.
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions ...
Definition: mat.hpp:1865
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
Template class for 2D points specified by its coordinates x and y.
Definition: types.hpp:147
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: defs.h:364
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
void accumulate(InputArray src, InputOutputArray dst, InputArray mask=noArray())
Adds an image to the accumulator.
static Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
#define CV_8UC3
Definition: cvdef.h:118
void calcHist(const Mat *images, int nimages, const int *channels, InputArray mask, OutputArray hist, int dims, const int *histSize, const float **ranges, bool uniform=true, bool accumulate=false)
Calculates a histogram of a set of arrays.
Definition: highgui.hpp:138
flag
Definition: base.hpp:176
int main(int argc, const char *argv[])
Definition: facerec_demo.cpp:67
n-dimensional dense array class
Definition: mat.hpp:726
_Tp & at(int i0=0)
Returns a reference to the specified array element.
Point2i Point
Definition: types.hpp:181
int waitKey(int delay=0)
Waits for a pressed key.
void histRange(InputArray src, OutputArray hist, InputArray levels, Stream &stream=Stream::Null())
Calculates a histogram with bins determined by the levels array.