Package io.github.jspinak.brobot.util.image.constants
package io.github.jspinak.brobot.util.image.constants
Provides predefined constants and enumerations for image processing.
This package contains constant definitions, particularly color constants in BGR format used throughout the image processing utilities. These constants ensure consistency in color representation and provide convenient access to commonly used colors in computer vision operations.
Core Components
BgrColorConstants
- Predefined BGR color values for OpenCV operations
BGR Color Format
OpenCV uses BGR (Blue-Green-Red) color ordering by default, which differs from the more common RGB format. This package provides constants in the correct BGR format to avoid color channel confusion.
Available Colors
BgrColorConstants provides BGR values for:
- Primary Colors: Blue, Green, Red
- Secondary Colors: Cyan, Magenta, Yellow
- Neutral Colors: Black, White, Gray variations
- Common Colors: Orange, Purple, Pink, Brown
- Special Values: Transparent, Default markers
Color Value Structure
Each color is defined as a Scalar with three or four components:
- Blue Channel: First component (0-255)
- Green Channel: Second component (0-255)
- Red Channel: Third component (0-255)
- Alpha Channel: Optional fourth component (0-255)
Usage Examples
// Draw a red rectangle on an image
Imgproc.rectangle(
image,
new Point(10, 10),
new Point(100, 100),
BgrColorConstants.RED,
2 // thickness
);
// Fill region with blue color
Mat mask = new Mat(image.size(), CvType.CV_8UC3, BgrColorConstants.BLUE);
// Create color range for detection
Scalar lowerBound = BgrColorConstants.GREEN.mul(0.8);
Scalar upperBound = BgrColorConstants.GREEN.mul(1.2);
Core.inRange(image, lowerBound, upperBound, mask);
// Draw with custom opacity
Scalar semiTransparentRed = new Scalar(0, 0, 255, 128); // 50% opacity
Color Space Considerations
- BGR is OpenCV's default; RGB requires conversion
- HSV color space may be better for color detection
- Grayscale operations ignore color channels
- Alpha channel support depends on image type
Common Use Cases
- Debug Visualization: Highlight regions with distinct colors
- Annotation: Draw bounding boxes and markers
- Masking: Create color-based masks
- Thresholding: Define color ranges for detection
- UI Elements: Consistent colors across visualizations
Best Practices
- Use constants instead of hardcoded BGR values
- Document any custom color definitions
- Consider color blindness in visualization choices
- Test colors on different backgrounds
- Validate color space before using constants
Extension Guidelines
When adding new constants:
- Follow BGR ordering convention
- Provide clear, descriptive names
- Include Javadoc with RGB equivalent
- Consider adding color variations (light/dark)
- Test visual appearance in target context
- Since:
- 1.0
- See Also:
-
Enum Classes