#include <iostream>
using namespace cv;
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 =
{
"{@image|../data/baboon.jpg|input image file}"
};
int main(
int argc,
const char** argv )
{
help();
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;
}