 |
OpenCV
3.2.0
Open Source Computer Vision
|
An example for creating histograms of an image
#include <iostream>
using namespace std;
int _brightness = 100;
int _contrast = 100;
static void updateBrightnessContrast( int , void* )
{
int histSize = 64;
int brightness = _brightness - 100;
int contrast = _contrast - 100;
double a, b;
if( contrast > 0 )
{
double delta = 127.*contrast/100;
a = 255./(255. - delta*2);
b = a*(brightness - delta);
}
else
{
double delta = -128.*contrast/100;
a = (256.-delta*2)/255.;
b = a*brightness + delta;
}
for(
int i = 0;
i < histSize;
i++ )
imshow(
"histogram", histImage);
}
static void help()
{
std::cout << "\nThis program demonstrates the use of calcHist() -- histogram creation.\n"
<< "Usage: \n" << "demhist [image_name -- Defaults to ../data/baboon.jpg]" << std::endl;
}
const char* keys =
{
"{help h||}{@image|../data/baboon.jpg|input image file}"
};
int main( int argc, const char** argv )
{
if (parser.has("help"))
{
help();
return 0;
}
string inputImage = parser.get<string>(0);
image =
imread( inputImage, 0 );
if(image.empty())
{
std::cerr << "Cannot read image file: " << inputImage << std::endl;
return -1;
}
createTrackbar(
"brightness",
"image", &_brightness, 200, updateBrightnessContrast);
createTrackbar(
"contrast",
"image", &_contrast, 200, updateBrightnessContrast);
updateBrightnessContrast(0, 0);
return 0;
}
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition: mat.hpp:1959
static Scalar_< double > all(double v0)
returns a scalar with all elements set to v0
@ NORM_MINMAX
flag
Definition: base.hpp:196
_Tp & at(int i0=0)
Returns a reference to the specified array element.
int waitKey(int delay=0)
Waits for a pressed key.
#define CV_8U
Definition: interface.h:67
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
void convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
Converts an array to another data type with optional scaling.
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.
#define CV_32F
Definition: interface.h:72
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
int cols
Definition: mat.hpp:1959
int cvRound(double value)
Rounds floating-point number to the nearest integer.
Definition: fast_math.hpp:93
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
Point2i Point
Definition: types.hpp:183
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.
n-dimensional dense array class
Definition: mat.hpp:741
for i
Definition: modelConvert.m:63
Designed for command line parsing.
Definition: utility.hpp:735
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.
Definition: affine.hpp:52
static MatExpr ones(int rows, int cols, int type)
Returns an array of all 1's of the specified size and type.
static Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)