#include <iostream>
#include <fstream>
#include <sstream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>


int main( int argc, char* argv[] )
{

    cv::Mat a = cv::Mat::eye( 3, 3, CV_64FC1 );
    cv::Mat b = cv::Mat::ones( 3, 3, CV_64FC1 );
    std::cout << (a+b) << std::endl;


    // Load image

    cv::Mat I = cv::imread( "input.jpg" );
    if( I.rows == 0 || I.cols == 0 )
    {
        std::cout << "Load failed" << std::endl;
        return -1;
    }

    std::cout << "Loaded a " << I.rows << "x" << I.cols << " image channels: " << I.channels() <<  std::endl;

    cv::imshow( "test", I );
    cv::waitKey( 0 );


    cv::Mat Ig;
    cv::cvtColor( I, Ig, CV_RGB2GRAY );
    std::cout << "Ig channels: " << Ig.channels()  << std::endl;

    cv::imshow( "test", Ig );
    cv::waitKey( 0 );


    cv::Mat Ineg( Ig.rows, Ig.cols, CV_8UC1 );

    if( Ig.isContinuous() )
    {
        std::cout << "Ig is continuous!" << std::endl;
        const unsigned char* pIgData = Ig.ptr( 0 );
        const unsigned char* pIgDataEnd = pIgData + Ig.cols*Ig.rows;
        unsigned char* pInegData = Ineg.ptr( 0 );

        while( pIgData < pIgDataEnd )
        {
            *pInegData++ = 255 - *pIgData++;
        }
    }


    cv::imshow( "test", Ineg );
    cv::waitKey( 0 );


    return 0;
}


