我需要检查银行卡上的 Logo 。是否可以以这样的方式修复我的代码:当 Logo 不匹配时,系统不会搜索相似的元素,而是抛出异常?
我尝试更改阈值方法中的变量,但没有结果。
private static void isTemplateImageExist(String sourceScreenshotPath,
String sourceScreenshot,
String templateScreenshotPath,
String templateImage,
String resultImage){
CustomLogger.info("Getting images for comparing");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat source = Highgui.imread(sourceScreenshotPath + sourceScreenshot, Highgui.CV_LOAD_IMAGE_COLOR);
Mat template = Highgui.imread(templateScreenshotPath + templateImage);
Mat outputImage = new Mat();
int machMethod = Imgproc.TM_CCOEFF;
CustomLogger.info("Comparing images");
//Template matching method
Imgproc.threshold(source, outputImage, 1, 250, Imgproc.THRESH_TOZERO);
Imgproc.matchTemplate(source, template, outputImage, machMethod);
drawRectangleOnResultImage(outputImage,source,template,sourceScreenshotPath,resultImage);
}
如果 Logo 不匹配,我希望看到异常。
最佳答案
使用outputImage
获取最小值和最大值。检查最大值是否大于某个所需的阈值。如果最大值不大于该阈值,则抛出
异常
。
关于java - 使用openCV模板匹配器,在没有所需对象的情况下,无论如何都能找到匹配项。如何获得异常(exception)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56393694/