Friday, 20 May 2016

Opencv C++ code of Operation on Arrays:absdiff


Here is the OpenCv C++ Example on Operation on Arrays by using absdiff()
It calculates the per-element absolute difference between two arrays or between an array and a scalar.


Syntax:
C++: void absdiff(InputArray src1, InputArray src2, OutputArray dst)



Parameters:
src1 – first input array or a scalar.
src2 – second input array or a scalar.
src – single input array.
value – scalar value.
dst – output array that has the same size and type as input arrays.



Here is the Opencv Code for calculating absolute difference of each element of matrix.
//Opencv C++ Example of Operation on Arrays:absdiff  
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
 
using namespace cv;
using namespace std;
 
int main( )
{
 
    Mat image1,image2,dst;
    image1 = imread("C:\\Users\\arjun\\Desktop\\opencv-logo.jpg",CV_LOAD_IMAGE_COLOR);
    if( !image1.data ) { printf("Error loading image1 \n"); return -1;}
    image2 = imread("C:\\Users\\arjun\\Desktop\\opencv-test.png",CV_LOAD_IMAGE_COLOR);
    if( !image2.data ) { printf("Error loading image2 \n"); return -1;}
           
    absdiff( image1,  image2,  dst);
  
    namedWindow( "Display window", CV_WINDOW_AUTOSIZE );  
    imshow( "Display window", image2 );                 

    namedWindow( "Display windo", CV_WINDOW_AUTOSIZE );  
    imshow( "Display windo", image1 );         

    namedWindow( "Result window", CV_WINDOW_AUTOSIZE );   
    imshow( "Result window", dst );
    
    //imwrite("C:\\Users\\arjun\\Desktop\\opencv-dst.jpg",dst);
    waitKey(0);                                         
    return 0;
}


Input Image1:



Input Image2:



Output Image:

No comments:

Post a Comment