1

I am using opencv_249 dll in java. Using below code to compare two image matrices. The code is throwing some exception which I am not able to resolve.

static double compareImages(Mat main, Mat temp){
    main.convertTo(main, CvType.CV_32FC3);
    temp.convertTo(temp, CvType.CV_32FC3);
    Core.normalize(main, temp, 1.0, 0.0, Core.NORM_L1);
    double s=Imgproc.compareHist(main, temp, Imgproc.CV_COMP_CORREL);
    return s;
}

The code is throwing following exception:

OpenCV Error: Assertion failed (H1.type() == H2.type() && H1.type() == CV_32F) in cv::compareHist, 
file ..\..\..\..\opencv\modules\imgproc\src\histogram.cpp, 
line 1985 
Exception in thread "main" 
CvException [org.opencv.core.CvException: 
cv::Exception: ..\..\..\..\opencv\modules\imgproc\src\histogram.cpp:1985: 
error: (-215) H1.type() == H2.type() && H1.type() == CV_32F 
in function cv::compareHist ] 
at org.opencv.imgproc.Imgproc.compareHist_0(Native Method) 
at org.opencv.imgproc.Imgproc.compareHist(Imgproc.java:3051) 
at ImageComparator.main(ImageComparator.java:88)

Could anyone tell what is being missed out in the code?

HRgiger
  • 2,750
  • 26
  • 37
  • I dont know the java api but I would try two thing: According to assertion error, seems like convert operation was not successful and one of the image types was not CV_32F anymore while you call compareHist, so try using new reference 'Mat convertedMain = main.convertTo(main, CvType.CV_32FC3);' or maybe normalize line messing up the things – HRgiger Mar 31 '17 at 09:54

1 Answers1

0

****OpenCV Error: Assertion failed (H1.type() == H2.type() && H1.type() == CV_32F) in...

As the error message tells you an assertion failed. Both input image have to be of the same type and that type must be CV_32F.

Maybe you noticed that your input type is CV_32FC3?

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • I tried using "CV_32F" type also, still the same error persists. – sharmishtha kulkarni Apr 03 '17 at 11:13
  • @sharmishthakulkarni well if the assertion fails then at least one of those statements is false... check the type of main and temp after the convertTo call. I am no OpenCV expert but the examples I saw and common sense tell me that you should not or cannot convert types in-place. So try creating new Mat instances and use them as destination in your convertTo-calls. – Piglet Apr 03 '17 at 11:32