Class GetImageJavaCV

java.lang.Object
io.github.jspinak.brobot.imageUtils.GetImageJavaCV

@Component public class GetImageJavaCV extends Object
JavaCV-based image acquisition and conversion utilities for Brobot.

GetImageJavaCV provides comprehensive image loading, conversion, and capture functionality using the JavaCV library. JavaCV offers better integration with deep learning frameworks like DL4J (DeepLearning4J), making it the preferred choice for Brobot's computer vision operations. This class handles various image sources and color space conversions essential for pattern matching and state detection.

Key capabilities:

  • File Loading: Load images from files with automatic path resolution
  • Screen Capture: Capture screenshots of full screen or specific regions
  • Color Conversion: Convert between BGR and HSV color spaces
  • Region Masking: Extract specific regions from larger images
  • Batch Processing: Handle multiple images or regions efficiently
  • Time-Series Capture: Record screen changes over time

Image sources supported:

  • File system paths (absolute or bundle-relative)
  • Screen captures (full or regional)
  • BufferedImage conversions
  • Pattern and StateImage collections
  • Video frame grabbing via FFmpeg

Color space support:

  • BGR: Default OpenCV color format (Blue-Green-Red)
  • HSV: Hue-Saturation-Value for color-based matching
  • Automatic conversion based on ColorSchemaName parameter
  • In-place or new Mat conversions available

Common use cases:

  • Loading pattern images for template matching
  • Capturing screenshots for state detection
  • Converting images for color-based analysis
  • Extracting regions for focused processing
  • Recording screen sequences for analysis

Performance features:

  • Efficient batch operations for multiple images
  • Direct memory operations avoiding unnecessary copies
  • Configurable capture intervals for time-series data
  • Region-based capture to minimize data volume

Integration advantages:

  • Compatible with DL4J for deep learning models
  • Unified API across different image sources
  • Consistent color space handling
  • Seamless integration with Brobot's pattern matching

Time-series capture example:

 // Capture screen region every 0.5 seconds for 10 seconds
 MatVector frames = getImageJavaCV.getMatsFromScreen(
     region, 0.5, 10.0
 );
 

In the model-based approach, GetImageJavaCV serves as the primary image acquisition layer, providing consistent access to visual data regardless of source. This abstraction enables the framework to work with files during development, live screens during execution, and recorded data during testing, all through the same interface.

Since:
1.0
See Also:
  • Constructor Details

  • Method Details

    • convertToHSV

      public org.bytedeco.opencv.opencv_core.Mat convertToHSV(org.bytedeco.opencv.opencv_core.Mat bgr)
    • getHSV

      public org.bytedeco.opencv.opencv_core.Mat getHSV(org.bytedeco.opencv.opencv_core.Mat bgr)
    • getMatFromFilename

      public org.bytedeco.opencv.opencv_core.Mat getMatFromFilename(String imageName, ColorCluster.ColorSchemaName colorSchemaName)
    • getMatFromBundlePath

      public org.bytedeco.opencv.opencv_core.Mat getMatFromBundlePath(String imageName, ColorCluster.ColorSchemaName colorSchemaName)
    • getMatsFromFilenames

      public List<org.bytedeco.opencv.opencv_core.Mat> getMatsFromFilenames(List<String> filenames, ColorCluster.ColorSchemaName colorSchemaName)
    • getMats

      public List<org.bytedeco.opencv.opencv_core.Mat> getMats(StateImage img, ColorCluster.ColorSchemaName colorSchemaName)
    • getMats

      public List<org.bytedeco.opencv.opencv_core.Mat> getMats(List<Pattern> patterns, ColorCluster.ColorSchemaName colorSchemaName)
    • getMat

      public org.bytedeco.opencv.opencv_core.Mat getMat(String imageName, List<Region> regions, ColorCluster.ColorSchemaName colorSchemaName)
      Returns one Mat masked by the regions.
      Parameters:
      imageName - the name of the image to load
      regions - the regions to add to the Mat
      colorSchemaName - the color schema to use
      Returns:
      a Mat with only the given regions selected
    • getMats

      public List<org.bytedeco.opencv.opencv_core.Mat> getMats(String imageName, List<Region> regions, ColorCluster.ColorSchemaName colorSchemaName)
      Returns one Mat per region.
      Parameters:
      imageName - the name of the image to load
      regions - each region corresponds to a Mat
      colorSchemaName - the color schema to use
      Returns:
      a List of Mats corresponding to the regions
    • getMatFromFile

      public org.bytedeco.opencv.opencv_core.Mat getMatFromFile(String path, Region region, ColorCluster.ColorSchemaName colorSchemaName)
    • getMatFromScreen

      public org.bytedeco.opencv.opencv_core.Mat getMatFromScreen(Region region, ColorCluster.ColorSchemaName colorSchemaName)
    • getMatFromScreen

      public org.bytedeco.opencv.opencv_core.Mat getMatFromScreen(Region region)
    • getMatFromScreen

      public org.bytedeco.opencv.opencv_core.Mat getMatFromScreen(ColorCluster.ColorSchemaName colorSchemaName)
    • getMatFromScreen

      public org.bytedeco.opencv.opencv_core.Mat getMatFromScreen()
    • getMat

      public org.bytedeco.opencv.opencv_core.Mat getMat(BufferedImage image, boolean hsv)
    • getMatsFromScreen

      public List<org.bytedeco.opencv.opencv_core.Mat> getMatsFromScreen(List<Region> regions, boolean hsv)
    • bufferedImage2Mat

      public org.bytedeco.opencv.opencv_core.Mat bufferedImage2Mat(BufferedImage image)
    • getMatFromScreenWithJavaCV

      public org.bytedeco.opencv.opencv_core.Mat getMatFromScreenWithJavaCV()
    • getMatsFromScreen

      public org.bytedeco.opencv.opencv_core.MatVector getMatsFromScreen(Region region, double intervalSeconds, double totalSecondsToRun)
      Get a Mat from the screen at regular intervals.
      Parameters:
      region - the region to capture
      intervalSeconds - how often to capture the screen
      totalSecondsToRun - total time to capture screenshots
      Returns:
      a collection of Mat objects