Create Tranck Bar:





        Mat src = imread("MyPic.JPG");
        namedWindow("My Window", 1);

        int iSliderValue1 = 50;
createTrackbar("Brightness", "My Window", &iSliderValue1, 100);

int iSliderValue2 = 50;
createTrackbar("Contrast", "My Window", &iSliderValue2, 100);
        
        Mat dst;
        src.convertTo(dst, -1, dContrast, iBrightness);

        imshow("My Window", dst);

         IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

//Uncomment the following line if you are compiling this code in Visual Studio
#include "stdafx.h"

#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv2/cv.h>
#include <opencv2/highgui.h>

using namespace cv;
using namespace std;

/// Global Variables
const int alpha_slider_max = 100;
int alpha_slider;
double alpha;
double beta;

/// Matrices to store images
Mat src1;
Mat src2;
Mat dst;

/**
* @function on_trackbar
* @brief Callback for trackbar
*/



//void on_trackbar(int, void*)
//{
// alpha = (double)alpha_slider / alpha_slider_max;
// beta = (1.0 - alpha);
//
// addWeighted(src1, alpha, src2, beta, 0.0, dst);
//
// imshow("Linear Blend", dst);
//}





int main(int argc, char** argv)
{
// Read original image 
Mat src = imread("MyPic.JPG");

//if fail to read the image
if (!src.data)
{
cout << "Error loading the image" << endl;
return -1;
}

// Create a window
namedWindow("My Window", 1);

//Create trackbar to change brightness
int iSliderValue1 = 50;
createTrackbar("Brightness", "My Window", &iSliderValue1, 100);

//Create trackbar to change contrast
int iSliderValue2 = 50;
createTrackbar("Contrast", "My Window", &iSliderValue2, 100);

while (true)
{
//Change the brightness and contrast of the image (For more infomation http://opencv-srf.blogspot.com/2013/07/change-contrast-of-image-or-video.html)
Mat dst;
int iBrightness = iSliderValue1 - 50;
double dContrast = iSliderValue2 / 50.0;
src.convertTo(dst, -1, dContrast, iBrightness);

//show the brightness and contrast adjusted image
imshow("My Window", dst);

// Wait until user press some key for 50ms
int iKey = waitKey(50);

//if user press 'ESC' key
if (iKey == 27)
{
break;
}
}

return 0;

}





        IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII


Comments

Popular posts from this blog

OpenCV Programming 1

Opencv Drawing Functions