Ask Your Question
2

Comparing two images whether same or not

asked 2012-07-10 00:55:49 -0600

Unix gravatar image

I want to compare two images whether same or not by using opencv plugin in eclipse JUNO 12.04 I have been installed opencv2.4.2 in Ubuntu If I can do, please help me sample java code about this

Thanks a lot,

edit retag flag offensive close merge delete

Comments

3

You'd better specify what 'images are same' means for you:

* it can mean that both have exactly the same color in each pixel(i, j) - then you can just absdiff() them and countNonZero()

* or it can mean that the pictures contain the same objects but they differ by color-space or geometric transformations - in this case the analysis is not so trivial

Andrey Pavlenko gravatar imageAndrey Pavlenko ( 2012-07-10 03:48:23 -0600 )edit

If I want to compare pictures contain the same objects but they differ by color-space or geometric transformations - then what should be best approach?

surodip gravatar imagesurodip ( 2013-09-19 05:51:56 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
3

answered 2012-07-10 09:54:28 -0600

Kirill Kornyakov gravatar image

This OpenCV tutorial shows how you can compare two images. PSNR and SSIM metrics are used, which are usually used for analysis of denoising algorithms. SSIM is constructed in a way to be close to the human perception.

edit flag offensive delete link more
1

answered 2012-07-10 02:54:41 -0600

Abid Rahman K gravatar image
edit flag offensive delete link more

Comments

+1 In the future I'll link this answer to any SO answers I might write about this subject. Recursion is awesome.

karlphillip gravatar imagekarlphillip ( 2013-03-30 15:06:50 -0600 )edit
0

answered 2012-07-11 03:35:20 -0600

hype gravatar image

updated 2012-07-11 03:38:24 -0600

If you want to implement a "generic bitwise comparison" for cv::Mat you could write something like this:


bool cvMatEQ(const cv::Mat& data1, const cv::Mat& data2)
{
    bool success = true;
    // check if is multi dimensional
    if(data1.dims > 2 || data2.dims > 2)
    {
      if( data1.dims != data2.dims || data1.type() != data2.type() )
      {
        return false;
      }
      for(int32t dim = 0; dim < data1.dims; dim++){
        if(data1.size[dim] != data2.size[dim]){
          return false;
        }
      }
    }
    else
    {
      if(data1.size() != data2.size() || data1.channels() != data2.channels() || data1.type() != data2.type()){
        return false;
      }
    }
    int nrOfElements = data1.total()*data1.elemSize1();
    //bytewise comparison of data
    int cnt = 0;
    for(cnt = 0; cnt < nrOfElements && success; cnt++)
    {
      if(data1.data[cnt] != data2.data[cnt]){
        success = false;
      }
    }
    return success;
  }

edit flag offensive delete link more

Comments

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-07-11 05:32:41 -0600 )edit

What does "generic bitwise comparison" mean ? does it mean it works for two static images ? and how to compare and image with real time video ?

Ahmad Khalid gravatar imageAhmad Khalid ( 2017-08-09 12:18:48 -0600 )edit

Question Tools

Stats

Asked: 2012-07-10 00:55:49 -0600

Seen: 48,174 times

Last updated: Jul 11 '12