chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @file AddingImagesTrackbar.cpp
|
||||
* @brief Simple linear blender ( dst = alpha*src1 + beta*src2 )
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
using std::cout;
|
||||
|
||||
/** 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;
|
||||
|
||||
//![on_trackbar]
|
||||
/**
|
||||
* @function on_trackbar
|
||||
* @brief Callback for trackbar
|
||||
*/
|
||||
static void on_trackbar(int pos, void* userdata) {
|
||||
(void) userdata;
|
||||
alpha = (double)pos / alpha_slider_max;
|
||||
beta = (1.0 - alpha);
|
||||
addWeighted(src1, alpha, src2, beta, 0.0, dst);
|
||||
imshow("Linear Blend", dst);
|
||||
}
|
||||
//![on_trackbar]
|
||||
|
||||
/**
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
//![load]
|
||||
/// Read images (both must be of the same size and type)
|
||||
src1 = imread(samples::findFile("LinuxLogo.jpg"));
|
||||
src2 = imread(samples::findFile("WindowsLogo.jpg"));
|
||||
//![load]
|
||||
|
||||
if (src1.empty()) { cout << "Error loading src1 \n"; return -1; }
|
||||
if (src2.empty()) { cout << "Error loading src2 \n"; return -1; }
|
||||
|
||||
// Initialize trackbar value
|
||||
alpha_slider = 0;
|
||||
|
||||
//![window]
|
||||
namedWindow("Linear Blend", WINDOW_AUTOSIZE); //Create Window
|
||||
//![window]
|
||||
|
||||
//![create_trackbar]
|
||||
char TrackbarName[50];
|
||||
snprintf(TrackbarName, sizeof(TrackbarName), "Alpha x %d", alpha_slider_max);
|
||||
// Example userdata: Pass a pointer to an integer as userdata
|
||||
createTrackbar(TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar);
|
||||
//![create_trackbar]
|
||||
|
||||
/// Show initial result
|
||||
on_trackbar(alpha_slider, nullptr);
|
||||
|
||||
/// Wait for user input
|
||||
waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @file BasicLinearTransformsTrackbar.cpp
|
||||
* @brief Simple program to change contrast and brightness
|
||||
* @date Mon, June 6, 2011
|
||||
* @author OpenCV team
|
||||
*/
|
||||
|
||||
#include "opencv2/imgcodecs.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
// we're NOT "using namespace std;" here, to avoid collisions between the beta variable and std::beta in c++17
|
||||
using namespace cv;
|
||||
|
||||
/** Global Variables */
|
||||
const int alpha_max = 5;
|
||||
const int beta_max = 125;
|
||||
int alpha; /**< Simple contrast control */
|
||||
int beta; /**< Simple brightness control*/
|
||||
|
||||
/** Matrices to store images */
|
||||
Mat image;
|
||||
|
||||
/**
|
||||
* @function on_trackbar
|
||||
* @brief Called whenever any of alpha or beta changes
|
||||
*/
|
||||
static void on_trackbar( int, void* )
|
||||
{
|
||||
Mat new_image = Mat::zeros( image.size(), image.type() );
|
||||
|
||||
for( int y = 0; y < image.rows; y++ )
|
||||
for( int x = 0; x < image.cols; x++ )
|
||||
for( int c = 0; c < 3; c++ )
|
||||
new_image.at<Vec3b>(y,x)[c] = saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
|
||||
|
||||
imshow("New Image", new_image);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @function main
|
||||
* @brief Main function
|
||||
*/
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
/// Read image given by user
|
||||
String imageName("lena.jpg"); // by default
|
||||
if (argc > 1)
|
||||
{
|
||||
imageName = argv[1];
|
||||
}
|
||||
image = imread( samples::findFile( imageName ) );
|
||||
|
||||
/// Initialize values
|
||||
alpha = 1;
|
||||
beta = 0;
|
||||
|
||||
/// Create Windows
|
||||
namedWindow("Original Image", 1);
|
||||
namedWindow("New Image", 1);
|
||||
|
||||
/// Create Trackbars
|
||||
createTrackbar( "Contrast", "New Image", &alpha, alpha_max, on_trackbar );
|
||||
createTrackbar( "Brightness", "New Image", &beta, beta_max, on_trackbar );
|
||||
|
||||
/// Show some stuff
|
||||
imshow("Original Image", image);
|
||||
imshow("New Image", image);
|
||||
|
||||
/// Wait until user press some key
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user