Class ImageUtils

java.lang.Object
com.hp.lft.sdk.utils.ImageUtils

public class ImageUtils extends Object
A class for image utilities, such as OCR, image comparisons, and image find operations.
  • Constructor Details

    • ImageUtils

      public ImageUtils()
  • Method Details

    • getText

      public static String getText(RenderedImage image) throws GeneralLeanFtException
      Returns all text within the supplied image.
      Parameters:
      image - the image to use for the search.
      Returns:
      all text within the supplied image.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • getText

      public static String getText(RenderedImage image, Rectangle textArea) throws GeneralLeanFtException
      Returns all text within the supplied rectangle inside the supplied image.
      Parameters:
      image - the image to use for the search.
      textArea - an inner rectangle within the image.
      Returns:
      all text within the supplied rectangle inside the supplied image.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • locateText

      public static Rectangle[] locateText(RenderedImage image, String textToFind) throws GeneralLeanFtException
      Returns all rectangular areas within the supplied image that contain the specified text.
      Parameters:
      image - the image to use for the search.
      textToFind - the text string to find.
      Returns:
      all rectangular areas within the supplied image that contain the specified text.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • locateText

      public static Rectangle[] locateText(RenderedImage image, String textToFind, Rectangle textArea) throws GeneralLeanFtException
      Returns all rectangular areas within the supplied rectangle that contain the specified text.
      Parameters:
      image - the image to use for the search.
      textToFind - the text string to find.
      textArea - an inner rectangle within the image.
      Returns:
      all rectangular areas within the supplied rectangle that contain the specified text.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • locateImage

      public static Point locateImage(RenderedImage sourceImage, RenderedImage imageToFind) throws GeneralLeanFtException
      Locates an image inside the provided source image, with a default similarity of 100%.
      Parameters:
      sourceImage - the source image to check.
      imageToFind - the image to locate within the sourceImage.
      Returns:
      the point where the image was located, or null if it was not found.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • locateImage

      public static Point locateImage(RenderedImage sourceImage, RenderedImage imageToFind, byte similarity) throws GeneralLeanFtException
      Locates an image inside the provided source image.
      Parameters:
      sourceImage - the source image to check.
      imageToFind - the image to locate within the source image.
      similarity - the minimum similarity (as a percentage), above which the find is considered successful.
      Returns:
      the point where the image was located, or null if it was not found.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • getImageLocations

      public static Point[] getImageLocations(RenderedImage sourceImage, RenderedImage imageToFind) throws GeneralLeanFtException
      Returns the first 100 locations of an image inside the source image, with a default similarity of 100%. If the number of images found exceeds 100 images, an GeneralLeanFtException is thrown.
      Parameters:
      sourceImage - the source image to check.
      imageToFind - the image to locate within the sourceImage.
      Returns:
      an array of points where the image was located.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • getImageLocations

      public static Point[] getImageLocations(RenderedImage sourceImage, RenderedImage imageToFind, byte similarity) throws GeneralLeanFtException
      Returns the first 100 locations of an image inside the source image that meet the provided similarity threshold. If the number of images found exceeds 100 images, an GeneralLeanFtException is thrown.
      Parameters:
      sourceImage - the source image to check.
      imageToFind - the image to locate within the source image.
      similarity - the minimum similarity (as a percentage), above which the find is considered successful.
      Returns:
      an array of points where the image was located.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • compareImages

      public static boolean compareImages(RenderedImage firstImage, RenderedImage secondImage) throws GeneralLeanFtException
      Checks whether two images are identical.
      Parameters:
      firstImage - the expected image.
      secondImage - the image to compare to the expected image.
      Returns:
      true if the images are identical, else false.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • compareImages

      public static boolean compareImages(RenderedImage firstImage, RenderedImage secondImage, byte pixelTolerance) throws GeneralLeanFtException
      Checks whether two images are a match, given the specified pixel tolerance value.
      Parameters:
      firstImage - the expected image.
      secondImage - the image to compare to the expected image.
      pixelTolerance - the percentage of pixels that can differ between the two images, and still be considered a match.
      Returns:
      true if the images match, else false.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • compareImages

      public static boolean compareImages(RenderedImage firstImage, RenderedImage secondImage, byte pixelTolerance, byte rgbTolerance) throws GeneralLeanFtException
      Checks whether two images are a match, given the specified pixel and RGB tolerance values.
      Parameters:
      firstImage - the expected image.
      secondImage - the image to compare to the expected image.
      pixelTolerance - the percentage of pixels that can differ between the two images, and still be considered a match.
      rgbTolerance - the percent by which the RGB values of the pixels in the two images can differ, and still be considered a match.
      Returns:
      true if the images match, else false.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • compareImages

      public static boolean compareImages(RenderedImage firstImage, RenderedImage secondImage, ImageMaskArea maskArea) throws GeneralLeanFtException
      Checks whether the defined mask areas within two images are identical.
      Parameters:
      firstImage - the expected image.
      secondImage - the image to compare to the expected image.
      maskArea - the mask area within the two images to use for the comparison.
      Returns:
      true if the mask areas within the images are identical and the two full images are the same size, else false.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • compareImages

      public static boolean compareImages(RenderedImage firstImage, RenderedImage secondImage, ImageMaskArea maskArea, byte pixelTolerance) throws GeneralLeanFtException
      Checks whether the defined mask areas within two images match, given the specified pixel tolerance value.
      Parameters:
      firstImage - the expected image.
      secondImage - the image to compare to the expected image.
      maskArea - the mask area within the two images to use for the comparison.
      pixelTolerance - the percent by which the RGB values of the pixels in the two images can differ, and still be considered a match.
      Returns:
      true if the mask areas within the images match and the two full images are the same size, else false.
      Throws:
      GeneralLeanFtException - if error occurs during execution
    • compareImages

      public static boolean compareImages(RenderedImage firstImage, RenderedImage secondImage, ImageMaskArea maskArea, byte pixelTolerance, byte rgbTolerance) throws GeneralLeanFtException
      Checks whether the defined mask areas within two images match, given the specified pixel and RGB tolerance values.
      Parameters:
      firstImage - the expected image.
      secondImage - the image to compare to the expected image.
      maskArea - the mask area within the two images to use for the comparison.
      pixelTolerance - the percentage of pixels that can differ between the two images, and still be considered a match.
      rgbTolerance - the percent by which the RGB values of the pixels in the two images can differ, and still be considered a match.
      Returns:
      true if the mask areas within the images match and the two full images are the same size, else false.
      Throws:
      GeneralLeanFtException - if error occurs during execution