Ask Your Question
0

error Sizes of input arguments do not match while using Core.compare

asked 2016-11-03 02:13:17 -0600

Karanbeer Kaur gravatar image

updated 2016-11-03 02:13:49 -0600

I am trying below code to compare 2 images. 

   Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
   Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
   Mat result = new Mat();
    Core.compare(img1,img2,result,Core.CMP_NE);
    int val = Core.countNonZero(result);

    if(val == 0) {
        //
        System.out.println("Duplicate Image");
    } else {
        //Different Image
        System.out.println("Different Image");
    }

But getting below error

OpenCV Error: Sizes of input arguments do not match (The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array') in compare, file /tmp/opencv3-20161019-20369-7r0q5p/modules/core/src/arithm.cpp, line 1253
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: /tmp/opencv3-20161019-20369-7r0q5p/modules/core/src/arithm.cpp:1253: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same type), nor 'array op scalar', nor 'scalar op array' in function compare
]
    at org.opencv.core.Core.compare_0(Native Method)
    at org.opencv.core.Core.compare(Core.java:1071)

Please suggest.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2016-11-03 02:21:06 -0600

berak gravatar image

updated 2016-11-03 02:22:29 -0600

make sure, both input images are valid and have the same dimensions

edit flag offensive delete link more

Comments

@break if the dimensions are different and still want to compare then what I need to do

Karanbeer Kaur gravatar imageKaranbeer Kaur ( 2016-11-03 02:37:04 -0600 )edit

resize(img1, img1, img2.size()) , maybe. (but no idea, if it makes sense at all)

berak gravatar imageberak ( 2016-11-03 02:44:28 -0600 )edit

@break It worked. but don't know logically its correct of not.

Karanbeer Kaur gravatar imageKaranbeer Kaur ( 2016-11-03 02:50:37 -0600 )edit

how would i know ?

main problem with most of your questions here is the lack of context. (X Y problem)

berak gravatar imageberak ( 2016-11-03 02:55:11 -0600 )edit

@break context is simple,I want to compare 2 images and then draw rectangle around the image difference. the only thing is I am new to opencv, if you will write theory only, It will be bit difficult for me to understand. It will be helpful if you can give some sample refrence

Karanbeer Kaur gravatar imageKaranbeer Kaur ( 2016-11-03 03:06:51 -0600 )edit

http://xyproblem.info/

  • what are your images ?
  • what does compare mean here, exactly ?
berak gravatar imageberak ( 2016-11-03 03:14:36 -0600 )edit
1

I have 2 jpg files having same dimensions.  e.g. in first image I have a line and in second image there is no line. I want to create another image that will show there is a difference pointing to that line with circle or square. I tried 

  1. matcher.match(descriptors1, descriptors2 ,matches);
  2. findContours and then used matchShapes
  3. Core.compare and then Core.countNonZero

  4. compareHist

but not clear which one of them is the best match

Using them I am able to find the images are equal or different, but not able to create new image that points the difference. Could you please provide some methods or link where from I get some help to complete this task.

Karanbeer Kaur gravatar imageKaranbeer Kaur ( 2016-11-04 01:22:48 -0600 )edit

yea, i know, you tried a lot already ;)

atm, i'd stick with the core.compare() idea. instead of counting the difference pixels, you could try to apply findContours() on the outcome (this would at least give you some location/shape information)

berak gravatar imageberak ( 2016-11-04 01:37:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-03 02:13:17 -0600

Seen: 2,669 times

Last updated: Nov 03 '16