I have a Swing application and i'm having problems integrating an OpenCV matchTemplate.
This code works fine:
public static void main(String[] args) {
boolean checkMatchTemplate = ImageSimilarity.checkMatchTemplate("", "");
System.out.println(checkMatchTemplate);
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LoginMenu window = new LoginMenu();
window.frmLogin.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
But if i put my matchTemplate inside the run method it gives me an error.
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
boolean checkMatchTemplate = ImageSimilarity.checkMatchTemplate("", "");
System.out.println(checkMatchTemplate);
LoginMenu window = new LoginMenu();
window.frmLogin.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
This is the error:
libpng warning: Application was compiled with png.h from libpng-1.5.12
libpng warning: Application is running with png.c from libpng-1.2.50
libpng error: Incompatible libpng version in application and library
OpenCV Error: Assertion failed (corrsize.height <= img.rows + templ.rows - 1 && corrsize.width <= img.cols + templ.cols - 1) in crossCorr, file /home/diogo/Downloads/opencv-2.4.10/modules/imgproc/src/templmatch.cpp, line 70
CvException [org.opencv.core.CvException: cv::Exception: /home/diogo/Downloads/opencv-2.4.10/modules/imgproc/src/templmatch.cpp:70: error: (-215) corrsize.height <= img.rows + templ.rows - 1 && corrsize.width <= img.cols + templ.cols - 1 in function crossCorr
]
at org.opencv.imgproc.Imgproc.matchTemplate_0(Native Method)
at org.opencv.imgproc.Imgproc.matchTemplate(Imgproc.java:7637)
(...)
And this is the checkMatchTemplate method:
public static boolean checkMatchTemplate(String path, String template) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
int match_method = Imgproc.TM_SQDIFF_NORMED;
Mat img = Highgui.imread("/home/diogo/workspace/AmbiSig/lena.png");
Mat templ = Highgui.imread("/home/diogo/workspace/AmbiSig/template.png");
int result_cols = img.cols() - templ.cols() + 1;
int result_rows = img.rows() - templ.rows() + 1;
Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
Imgproc.matchTemplate(img, templ, result, match_method);
MinMaxLocResult mmr = Core.minMaxLoc(result);
if (mmr.minVal < thresholdMatch)
return true;
return false;
}
What do I need to do to make the matchTemplate work inside the run method? Thank you in advance :)