Frage

ich gehe eine Anwendung für Bildvergleich auf Java zu entwickeln. Dazu habe ich euklidische Algorithmus gewählt. Diese Anwendung beinhaltet mit 2 Bildern. 1. Ist-Bild 2. Teil des aktuellen Bildes.

Algorithmus sollte den Teil des Bildes mit tatsächlichem Bild vergleichen. Wenn das Teil in tatsächlichem Bild existiert, sollte es einen Wert als Anpassungs Erfolg zurück.

Kann jemand geben Sie mir die algorithmischen Schritte? Code auf Java versteht sich ..!

War es hilfreich?

Lösung

Hier ist eine relativ einfache Idee, mit einigen Teilen absichtlich weggelassen, da die Frage, wie Hausaufgaben riecht.

public static boolean contains(Image large, Image small) {
  final int largeWidth = large.getWidth(), largeHeight = large.getHeight();
  final int smallWidth = small.getWidth(), smallHeight = small.getHeight();

  if (smallWidth > largeWidth || smallHeight > largeHeight) {
    return false;
  }

  for (int x = 0; x < largeWidth - smallWidth; x++) {
    for (int y = 0; y < largeHeight - smallHeight; y++) {
      if (subImageEquals(large, x, y, small)) {
        return true;
      }
    }
  }
  return false;
}

private static boolean subImageEquals(Image large, int x, int y, Image small) {
  // TODO: checks whether all pixels starting at (x, y) match
  // those of the small image.
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top