Class Image

  • Direct Known Subclasses:
    ScreenImage

    public class Image
    extends org.sikuli.script.Element
    This class hides the complexity behind image names given as string.
    It's companion is ImagePath that maintains a list of places, where image files are loaded from.
    An Image object:
    - has a name, either given or taken from the basename
    - keeps it's pixel content in a configurable cache avoiding reload from source
    - remembers, where it was found when searched the last time
    - can be sourced from the filesystem, from jars, from the web and from other in memory images
    - has features for basic image manipulation and presentation
    - contains the stuff to communicate with the underlying OpenCV based search engine
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.sikuli.script.Element

        org.sikuli.script.Element.Interpolation
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean wasRecaptured  
      • Fields inherited from class org.sikuli.script.Element

        h, w, x, y
    • Constructor Summary

      Constructors 
      Constructor Description
      Image​(java.lang.Class clazz, java.lang.String resource)
      Creates an Image from a resource file on classpath.
      Image​(SUFEBMP what)
      Create an Image from various sources.
      Image​(SUFEBMP what, java.lang.String name)
      Create an Image from various sources.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Image create​(java.io.File imageFile)
      create a new image from the given file
      file ending .png is added if missing (currently valid: png, jpg, jpeg)
      relative filename: [...path.../]name[.png] is searched on current image path
      absolute filename is taken as is if image exists, it is loaded to cache
      already loaded image with same name (given path) is reused (taken from cache)
      static Image create​(java.lang.String fName)
      create a new image from a filename
      file ending .png is added if missing (currently valid: png, jpg, jpeg)
      relative filename: [...path.../]name[.png] is searched on current image path
      absolute filename is taken as is if image exists, it is loaded to cache
      already loaded image with same name (given path) is reused (taken from cache)
      static Image create​(java.net.URL url)
      create a new image from the given url
      file ending .png is added if missing
      filename: ...url-path.../name[.png] is loaded from the url and and cached
      already loaded image with same url is reused (reference) and taken from cache
      static Image create​(Image image)
      create a new Image as copy of the given Image
      static java.awt.image.BufferedImage createSubimage​(java.awt.image.BufferedImage bimg, java.awt.Rectangle rect)  
      static Image getDefaultInstance4py()  
      java.lang.String getFilename()  
      static boolean getIDEshouldReload()  
      java.awt.Rectangle getLastSeen()
      if the image was already found before
      double getLastSeenScore()
      if the image was already found before
      Image getMask()  
      java.lang.String getNameAsText()  
      Image getSub​(int part)
      create a sub image from this image
      Image getSub​(int x, int y, int w, int h)
      create a sub image from this image
      Image getSub​(Region reg)  
      java.net.URL getURL()  
      boolean hasMask()  
      boolean isAbsolute()  
      boolean isBundled()
      INTERNAL USE: image is contained in a bundle (.sikuli)
      boolean isFile()  
      boolean isMasked()  
      boolean isRecaptured()  
      <SUFEBMP> Image mask​(SUFEBMP what)  
      Image masked()  
      Location offset()
      Get the value of offset
      Image offset​(int x, int y)
      Set the value of offset
      Image offset​(Location offset)
      Set the value of offset
      Image setFileURL​(java.net.URL fileURL)  
      static void setIDEshouldReload​(org.sikuli.script.Element img)  
      Image setIsAbsolute​(boolean val)  
      Image setLastSeen​(java.awt.Rectangle lastSeen, double sim)
      Internal Use: set the last seen info after a find
      double similarity()
      Get the value of similarity
      Image similarity​(double similarity)
      Set the value of similarity
      int waitAfter()
      Get the value of waitAfter
      Image waitAfter​(int waitAfter)
      Set the value of waitAfter
      • Methods inherited from class org.sikuli.script.Element

        asFakeImage, asMaskImage, asText, black, black, cacheStats, click, click, click, cloneContent, collectLines, collectLinesText, collectWords, collectWordsText, createURL, createURL, delayClick, diffPercentage, exists, exists, existsT, existsText, file, fileName, find, findAll, findAllByColumn, findAllByRow, findAllT, findAllText, findAny, findAnyList, findBest, findBestList, findChanges, findLine, findLines, findLines, findT, findText, findWord, findWords, findWords, getAll, getAutoWaitTimeout, getBufferedImage, getBufferedImage, getCache, getCenter, getContent, getFindFailedHandler, getFindFailedResponse, getH, getImage, getImage, getLastMatch, getLastMatches, getMatchLastSeen, getName, getObserveScanRate, getOtherScreen, getPoint, getRect, getRepeatWaitTime, getScreen, getSize, getTarget, getThrowException, getValidImageFilename, getW, getWaitScanRate, getX, getY, has, has, hasT, hasText, hasURL, hover, hover, ignoreLastSeen, initScreen, intersection, isFakeImage, isInside, isMaskImage, isOtherScreen, isText, isValid, isVirtual, match, match, matches, matches, mean, meanColor, mouseDown, mouseMove, mouseMove, mouseMove, mouseUp, mouseUp, plain, plain, reload, reload, reLocate, resetCache, resetFindFailedResponse, resetThrowException, resize, resize, sameSize, save, save, save, set, set, setAutoWaitTimeout, setCenter, setContent, setFindFailedHandler, setFindFailedResponse, setH, setLocation, setMissingAbort, setMissingPrompt, setName, setObserveScanRate, setOtherScreen, setRect, setRect, setRect, setRepeatWaitTime, setScreen, setThrowException, setVirtual, setW, setWaitScanRate, setX, setX, setY, setY, size, size, stdDev, text, textChar, textLine, textLines, textWord, textWords, toString, traceOff, traceOn, union, unionAll, unionAny, unionAnyList, updateContent, url, url, url, virtual, wait, wait, wait, waitVanish, waitVanish, white
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • wasRecaptured

        public boolean wasRecaptured
    • Constructor Detail

      • Image

        public Image​(SUFEBMP what)
        Create an Image from various sources.
         - from a file (String, URL, File)
         - from an Element (Region, Image, ...)
         - from a BufferedImage or OpenCV Mat
         - from a Pattern including the Pattern specific attributes
         
        Type Parameters:
        SUFEBMP - see source variants
        Parameters:
        what - the source
      • Image

        public Image​(SUFEBMP what,
                     java.lang.String name)
        Create an Image from various sources.
         - from a file (String, URL, File)
         - from an Element (Region, Image, ...)
         - from a BufferedImage or OpenCV Mat
         
        Type Parameters:
        SUFEBMP - see source variants
        Parameters:
        what - the source
        name - to identify non-file images
      • Image

        public Image​(java.lang.Class clazz,
                     java.lang.String resource)
        Creates an Image from a resource file on classpath.
        Parameters:
        clazz - a class found on classpath as reference
        resource - the resource identifier (.png is assumed)
    • Method Detail

      • getDefaultInstance4py

        public static Image getDefaultInstance4py()
      • getFilename

        public java.lang.String getFilename()
        Returns:
        the image's absolute filename or null if jar, http or in memory image
      • getLastSeen

        public java.awt.Rectangle getLastSeen()
        if the image was already found before
        Returns:
        the rectangle where it was found
      • getLastSeenScore

        public double getLastSeenScore()
        if the image was already found before
        Returns:
        the similarity score
      • setLastSeen

        public Image setLastSeen​(java.awt.Rectangle lastSeen,
                                 double sim)
        Internal Use: set the last seen info after a find
        Parameters:
        lastSeen - Match
        sim - SimilarityScore
        Returns:
        the image
      • hasMask

        public boolean hasMask()
      • getMask

        public Image getMask()
      • mask

        public <SUFEBMP> Image mask​(SUFEBMP what)
      • masked

        public Image masked()
      • isMasked

        public boolean isMasked()
      • similarity

        public double similarity()
        Get the value of similarity
        Returns:
        the value of similarity
      • similarity

        public Image similarity​(double similarity)
        Set the value of similarity
        Parameters:
        similarity - new value of similarity
      • offset

        public Location offset()
        Get the value of offset
        Returns:
        the value of offset
      • offset

        public Image offset​(Location offset)
        Set the value of offset
        Parameters:
        offset - new value of offset
      • offset

        public Image offset​(int x,
                            int y)
        Set the value of offset
        Parameters:
        x - new value of offset
        y - new value of offset
      • waitAfter

        public int waitAfter()
        Get the value of waitAfter
        Returns:
        the value of waitAfter
      • waitAfter

        public Image waitAfter​(int waitAfter)
        Set the value of waitAfter
        Parameters:
        waitAfter - new value of waitAfter
      • createSubimage

        public static java.awt.image.BufferedImage createSubimage​(java.awt.image.BufferedImage bimg,
                                                                  java.awt.Rectangle rect)
      • getNameAsText

        public java.lang.String getNameAsText()
      • isBundled

        public boolean isBundled()
        INTERNAL USE: image is contained in a bundle (.sikuli)
        Returns:
        true/false
      • create

        public static Image create​(Image image)
        create a new Image as copy of the given Image
        Parameters:
        image - given Image
        Returns:
        new Image
      • create

        public static Image create​(java.lang.String fName)
        create a new image from a filename
        file ending .png is added if missing (currently valid: png, jpg, jpeg)
        relative filename: [...path.../]name[.png] is searched on current image path
        absolute filename is taken as is if image exists, it is loaded to cache
        already loaded image with same name (given path) is reused (taken from cache)

        if image not found, it might be a text to be searched (imageIsText = true)

        Parameters:
        fName - image filename
        Returns:
        an Image object (might not be valid - check with isValid())
      • create

        public static Image create​(java.io.File imageFile)
        create a new image from the given file
        file ending .png is added if missing (currently valid: png, jpg, jpeg)
        relative filename: [...path.../]name[.png] is searched on current image path
        absolute filename is taken as is if image exists, it is loaded to cache
        already loaded image with same name (given path) is reused (taken from cache)

        if image not found, it might be a text to be searched (imageIsText = true)

        Parameters:
        imageFile - a Java File object
        Returns:
        an Image object (might not be valid - check with isValid())
      • create

        public static Image create​(java.net.URL url)
        create a new image from the given url
        file ending .png is added if missing
        filename: ...url-path.../name[.png] is loaded from the url and and cached
        already loaded image with same url is reused (reference) and taken from cache
        Parameters:
        url - image file URL
        Returns:
        the image
      • getSub

        public Image getSub​(int part)
        create a sub image from this image
        Parameters:
        part - (the constants Region.XXX as used with Region.getTile(int))
        Returns:
        the sub image
      • getSub

        public Image getSub​(int x,
                            int y,
                            int w,
                            int h)
        create a sub image from this image
        Parameters:
        x - pixel column
        y - pixel row
        w - width
        h - height
        Returns:
        the new image
      • getURL

        public java.net.URL getURL()
        Returns:
        the evaluated url for this image (might be null)
      • setFileURL

        public Image setFileURL​(java.net.URL fileURL)
      • isFile

        public boolean isFile()
      • isAbsolute

        public boolean isAbsolute()
        Returns:
        true if image was given with absolute filepath
      • setIsAbsolute

        public Image setIsAbsolute​(boolean val)
      • setIDEshouldReload

        public static void setIDEshouldReload​(org.sikuli.script.Element img)
      • getIDEshouldReload

        public static boolean getIDEshouldReload()
      • isRecaptured

        public boolean isRecaptured()