Class Pattern

java.lang.Object
org.sikuli.script.Pattern

public class Pattern
extends Object
to define a more complex search target
- non-standard minimum similarity
- click target other than center
- image as in-memory image
  • Constructor Details

    • Pattern

      public Pattern()
      creates empty Pattern object at least setFilename() or setBImage() must be used before the Pattern object is ready for anything
    • Pattern

      public Pattern​(Pattern p)
      create a new Pattern from another (attribs are copied)
      Parameters:
      p - other Pattern
    • Pattern

      public Pattern​(Image img)
      create a Pattern with given image
      Parameters:
      img - Image
    • Pattern

      public Pattern​(String imgpath)
      create a Pattern based on an image file name
      Parameters:
      imgpath - image filename
    • Pattern

      public Pattern​(URL url)
      Pattern from a Java resource (Object.class.getResource)
      Parameters:
      url - image file URL
    • Pattern

      public Pattern​(BufferedImage bimg)
      A Pattern from a BufferedImage
      Parameters:
      bimg - BufferedImage
    • Pattern

      public Pattern​(ScreenImage simg)
      A Pattern from a ScreenImage
      Parameters:
      simg - ScreenImage
  • Method Details

    • resize

      public Pattern resize​(float factor)
    • getResize

      public float getResize()
    • isImagePattern

      public boolean isImagePattern()
      true if Pattern was created from Image
      Returns:
      true/false
    • isValid

      public boolean isValid()
      check wether the image is valid
      Returns:
      true if image is useable
    • getMask

      public Mat getMask()
    • hasMask

      public boolean hasMask()
    • mask

      public Pattern mask()
    • asMask

      public Pattern asMask()
    • mask

      public Pattern mask​(String sMask)
    • mask

      public Pattern mask​(Image iMask)
    • mask

      public Pattern mask​(Pattern pMask)
    • withMask

      public Pattern withMask​(Pattern pMask)
    • withMask

      public Pattern withMask()
    • setFilename

      public Pattern setFilename​(String fileName)
      set a new image for this pattern
      Parameters:
      fileName - image filename
      Returns:
      the Pattern itself
    • setFilename

      public Pattern setFilename​(URL fileURL)
      set a new image for this pattern
      Parameters:
      fileURL - image file URL
      Returns:
      the Pattern itself
    • setFilename

      public Pattern setFilename​(Image img)
      set a new image for this pattern
      Parameters:
      img - Image
      Returns:
      the Pattern itself
    • getFilename

      public String getFilename()
      the current image's absolute filepath
      will return null, if image is in jar or in web
      use getFileURL in this case
      Returns:
      might be null
    • getFileURL

      public URL getFileURL()
      the current image's URL
      Returns:
      might be null
    • similar

      public Pattern similar​(double sim)
      sets the minimum Similarity to use with findX
      Parameters:
      sim - value 0 to 1
      Returns:
      the Pattern object itself
    • exact

      public Pattern exact()
      sets the minimum Similarity to 0.99 which means exact match
      Returns:
      the Pattern object itself
    • getSimilar

      public double getSimilar()
      Returns:
      the current minimum similarity
    • targetOffset

      public Pattern targetOffset​(int dx, int dy)
      set the offset from the match's center to be used with mouse actions
      Parameters:
      dx - x offset
      dy - y offset
      Returns:
      the Pattern object itself
    • targetOffset

      public Pattern targetOffset​(Location loc)
      set the offset from the match's center to be used with mouse actions
      Parameters:
      loc - Location
      Returns:
      the Pattern object itself
    • getTargetOffset

      public Location getTargetOffset()
      Returns:
      the current offset
    • getBImage

      public BufferedImage getBImage()
      ONLY FOR INTERNAL USE! Might vanish without notice!
      Returns:
      might be null
    • setBImage

      public Pattern setBImage​(BufferedImage bimg)
      ONLY FOR INTERNAL USE! Might vanish without notice!
      Parameters:
      bimg - BufferedImage
      Returns:
      the Pattern object itself
    • setImage

      public Pattern setImage​(Image img)
      sets the Pattern's image
      Parameters:
      img - Image
      Returns:
      the Pattern object itself
    • getImage

      public Image getImage()
      get the Pattern's image
      Returns:
      Image
    • setTimeAfter

      public void setTimeAfter​(int secs)
      set the seconds to wait, after this pattern is acted on
      Parameters:
      secs - seconds
    • getTimeAfter

      public int getTimeAfter()

      TODO: Usage to be implemented! get the seconds to wait, after this pattern is acted on
      Returns:
      time in seconds
    • toString

      public String toString()
      Overrides:
      toString in class Object