21 void Hist_and_Backproj(
int,
void* );
27 int main(
int,
char** argv )
30 src =
imread( argv[1], 1 );
35 hue.create( hsv.size(), hsv.depth() );
40 const char* window_image =
"Source image";
42 createTrackbar(
"* Hue bins: ", window_image, &bins, 180, Hist_and_Backproj );
43 Hist_and_Backproj(0, 0);
46 imshow( window_image, src );
58 void Hist_and_Backproj(
int,
void* )
61 int histSize =
MAX( bins, 2 );
62 float hue_range[] = { 0, 180 };
63 const float* ranges = { hue_range };
66 calcHist( &hue, 1, 0,
Mat(), hist, 1, &histSize, &ranges,
true,
false );
74 imshow(
"BackProj", backproj );
77 int w = 400;
int h = 400;
78 int bin_w =
cvRound( (
double) w / histSize );
81 for(
int i = 0; i < bins; i ++ )
84 imshow(
"Histogram", histImg );
convert RGB/BGR to HSV (hue saturation value), color conversions
Definition: imgproc.hpp:554
void calcBackProject(const Mat *images, int nimages, const int *channels, InputArray hist, OutputArray backProject, const float **ranges, double scale=1, bool uniform=true)
Calculates the back projection of a histogram.
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
Converts an image from one color space to another.
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
static MatExpr zeros(int rows, int cols, int type)
Returns a zero array of the specified size and type.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
#define MAX(a, b)
Definition: cvdef.h:184
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: defs.h:364
void mixChannels(const Mat *src, size_t nsrcs, Mat *dst, size_t ndsts, const int *fromTo, size_t npairs)
Copies specified channels from input arrays to the specified channels of output arrays.
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
Point2i Point
Definition: types.hpp:181
int waitKey(int delay=0)
Waits for a pressed key.