Warum kann ich bei der Durchführung von Vorlagenanpassungen keine genauen Übereinstimmungen erhalten?Java

Java-Forum
Anonymous
 Warum kann ich bei der Durchführung von Vorlagenanpassungen keine genauen Übereinstimmungen erhalten?

Post by Anonymous »

Ich führe eine einfache Vorlage für mich aus, aber für das Leben von mir kann ich immer noch nicht herausfinden, warum ich keine korrekten Übereinstimmungen bekomme. Ich habe es auch mit einem skalierenden invarianten Ansatz ausprobiert, aber auch nicht geholfen. src = "https://i.static.net/lrzpywtd.jpg"/>
Und was ich tue:

Code: Select all

public static boolean isIconPresent(String largeImagePath, String iconPath, double threshold) {
// Load images
Mat largeImageColor = Imgcodecs.imread(largeImagePath);
Mat iconColor = Imgcodecs.imread(iconPath);

if (largeImageColor.empty() || iconColor.empty()) {
throw new IllegalArgumentException("Could not load images.");
}

// Convert to grayscale (optional)
Mat largeImage = new Mat();
Mat icon = new Mat();
Imgproc.cvtColor(largeImageColor, largeImage, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(iconColor, icon, Imgproc.COLOR_BGR2GRAY);

// Result matrix
int resultCols = largeImage.cols() - icon.cols() + 1;
int resultRows = largeImage.rows() - icon.rows() + 1;
Mat result = new Mat(resultRows, resultCols, CvType.CV_32FC1);

// Template matching
Imgproc.matchTemplate(largeImage, icon, result, Imgproc.TM_CCOEFF_NORMED);

// Get match location
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
Point matchLoc = mmr.maxLoc;
double maxVal = mmr.maxVal;

System.out.println("Match confidence: " + maxVal);

return maxVal >= threshold;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post