Class OpenCVPatternMatcher

java.lang.Object
io.github.jspinak.brobot.core.services.OpenCVPatternMatcher
All Implemented Interfaces:
PatternMatcher

@Component @Primary public class OpenCVPatternMatcher extends Object implements PatternMatcher
OpenCV-based implementation of the PatternMatcher interface.

This implementation uses Sikuli's Finder (which wraps OpenCV) for pattern matching operations. It is completely independent of the Find action and other high-level Brobot components, providing pure pattern matching functionality.

Key characteristics:

  • No dependencies on Find or Action classes
  • Thread-safe through stateless operations
  • Properly manages Finder resources
  • Handles pattern size validation
Since:
2.0.0
  • Constructor Details

    • OpenCVPatternMatcher

      public OpenCVPatternMatcher()
  • Method Details

    • findPatterns

      public List<PatternMatcher.MatchResult> findPatterns(BufferedImage screen, Pattern pattern, PatternMatcher.MatchOptions options)
      Description copied from interface: PatternMatcher
      Finds patterns within a screen image.

      This method performs the core pattern matching operation, searching for occurrences of the pattern within the screen image. The implementation may use any pattern matching algorithm (template matching, feature matching, etc.).

      Specified by:
      findPatterns in interface PatternMatcher
      Parameters:
      screen - The screen image to search within
      pattern - The pattern to search for
      options - Configuration for the matching operation
      Returns:
      List of match results, empty if no matches found
    • findPatternsInRegion

      public List<PatternMatcher.MatchResult> findPatternsInRegion(BufferedImage screen, Pattern pattern, int regionX, int regionY, int regionWidth, int regionHeight, PatternMatcher.MatchOptions options)
      Description copied from interface: PatternMatcher
      Finds patterns within a specific region of the screen.

      This method optimizes pattern matching by searching only within a specified region of the screen image, improving performance for targeted searches.

      Specified by:
      findPatternsInRegion in interface PatternMatcher
      Parameters:
      screen - The screen image to search within
      pattern - The pattern to search for
      regionX - X coordinate of the search region
      regionY - Y coordinate of the search region
      regionWidth - Width of the search region
      regionHeight - Height of the search region
      options - Configuration for the matching operation
      Returns:
      List of match results, empty if no matches found
    • supportsPattern

      public boolean supportsPattern(Pattern pattern)
      Description copied from interface: PatternMatcher
      Checks if this matcher supports a specific pattern type.

      This allows for specialized matchers that only handle certain types of patterns (e.g., text patterns, color patterns).

      Specified by:
      supportsPattern in interface PatternMatcher
      Parameters:
      pattern - The pattern to check
      Returns:
      true if this matcher can handle the pattern type
    • getImplementationName

      public String getImplementationName()
      Description copied from interface: PatternMatcher
      Gets the name of this pattern matcher implementation.

      Used for logging and debugging to identify which matcher is being used.

      Specified by:
      getImplementationName in interface PatternMatcher
      Returns:
      Implementation name (e.g., "OpenCV", "Sikuli", "Mock")