Using OpenCV for image handling operations

1. Load an image and display it

//Loads image and displays
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main()
{
    cv::Mat image = cv::imread("spots2.jpg", CV_LOAD_IMAGE_COLOR);

    if( false == image.data )
    {
        std::cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
    cv::imshow( "Display window", image );
    cv::waitKey(0);
    return 0;
}

2. Add a trackbar to blend two images

#include <cv.h>
#include <highgui.h>

const int alpha_slider_max = 100;
int alpha_slider;
double alpha;
double beta;

cv::Mat src1;
cv::Mat src2;
cv::Mat dst;

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

int main( int argc, char** argv )
{
    // Read image ( same size, same type )
    src1 = cv::imread("LinuxLogo.jpg");
    src2 = cv::imread("WindowsLogo.jpg");

    if( false == src1.data )
    {
        std::cout << "Error loading src1" << std::endl;
        return -1;
    }

    if( false == src2.data )
    {
        std::cout << "Error loading src2" << std::endl;
        return -1;
    }

    alpha_slider = 0;

    // Create Windows and trackbars
    cv::namedWindow("Linear Blend", 1);
    char TrackbarName[50];
    sprintf( TrackbarName, "Alpha x %d", alpha_slider_max );

    cv::createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );
    on_trackbar( alpha_slider, 0 );

    // Wait until user presses some key
    cv::waitKey(0);
    return 0;
}