Skip to main content
Version: Latest

Image Find Debugging System

Comprehensive debugging system for troubleshooting image pattern matching issues in Brobot applications.

Overviewโ€‹

The Image Find Debugging System provides detailed insights into why patterns may not be found during automation. It uses Spring AOP to intercept find operations and provides:

  • Colorful console output with match details (Windows support via Jansi)
  • Visual annotations on screenshots showing search regions and matches
  • Comparison grids showing pattern vs found regions
  • Session-based file organization for easy debugging
  • Performance metrics and similarity scores
  • HTML/JSON reports for analysis

Featuresโ€‹

1. Colorful Console Outputโ€‹

  • Real-time feedback with ANSI colors
  • Success/failure indicators with visual symbols (โœ… โŒ)
  • Similarity scores and timing information
  • Pattern dimensions and match counts

2. Visual Debuggingโ€‹

  • Annotated screenshots showing search regions
  • Match highlights with similarity scores
  • Comparison grids showing pattern vs matched regions
  • Failed region indicators

3. Detailed Reportsโ€‹

  • HTML reports with interactive timeline
  • JSON reports for programmatic analysis
  • Session statistics and summaries
  • Performance metrics

4. File Savingโ€‹

  • Screenshots of each find operation
  • Pattern images for reference
  • Visual comparison grids
  • All outputs organized by session

Quick Startโ€‹

Enable Debuggingโ€‹

Add to your run command:

# Windows/Linux live automation with debugging
./gradlew bootRun --args='--spring.profiles.active=debug'

Debug Output Locationโ€‹

Debug files are saved to:

debug/image-finding/
โ”œโ”€โ”€ session-20250913-102030/
โ”‚ โ”œโ”€โ”€ 001-LoginButton/
โ”‚ โ”‚ โ”œโ”€โ”€ screenshot.png
โ”‚ โ”‚ โ”œโ”€โ”€ pattern.png
โ”‚ โ”‚ โ”œโ”€โ”€ annotated.png
โ”‚ โ”‚ โ””โ”€โ”€ comparison-grid.png
โ”‚ โ”œโ”€โ”€ 002-SubmitButton/
โ”‚ โ”‚ โ””โ”€โ”€ ... similar files ...
โ”‚ โ””โ”€โ”€ session-summary.json

Configurationโ€‹

Profile-Based Configurationโ€‹

Brobot uses Spring profiles for clean configuration:

ProfilePurposeProperties File
(none)Live automationapplication.properties
debugLive with debuggingapplication-debug.properties
mockTesting without GUIapplication-mock.properties
mock,debugMock with debuggingBoth profiles combined

Key Propertiesโ€‹

# Master switch
brobot.debug.image.enabled=true

# Debug level (OFF, BASIC, DETAILED, VISUAL, FULL)
brobot.debug.image.level=DETAILED

# File saving
brobot.debug.image.save-screenshots=true
brobot.debug.image.save-patterns=true
brobot.debug.image.save-comparisons=true
brobot.debug.image.output-dir=debug/image-finding

# Visual features
brobot.debug.image.visual.enabled=true
brobot.debug.image.visual.show-search-regions=true
brobot.debug.image.visual.show-match-scores=true
brobot.debug.image.visual.highlight-best-match=true
brobot.debug.image.visual.create-comparison-grid=true

# Console output (Windows support via Jansi)
brobot.debug.image.console.use-colors=true
brobot.debug.image.console.show-box=true
brobot.debug.image.console.show-timestamp=true

Debug Levelsโ€‹

OFFโ€‹

No debugging output

BASICโ€‹

  • Success/failure status
  • Basic timing information

DETAILEDโ€‹

Everything from BASIC plus:

  • Similarity scores
  • Search parameters
  • Match locations
  • Failure reasons

VISUALโ€‹

Everything from DETAILED plus:

  • Visual annotations
  • Screenshot saving
  • Comparison grids

FULLโ€‹

Everything from VISUAL plus:

  • Memory usage
  • Performance metrics
  • Complete operation traces

Console Outputโ€‹

Colorful Output on Windowsโ€‹

The debug system uses the Jansi library to enable ANSI colors on Windows terminals:

โœ… IMAGE FIND DEBUGGER: Session initialized
โ†’ FIND START: LoginButton
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ FIND OPERATION DEBUG โ•‘
โ• โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•ฃ
โ•‘ Pattern: LoginButton โ•‘
โ•‘ Similarity: 0.85 โ•‘
โ•‘ Status: โœ“ SUCCESS โ•‘
โ•‘ Best Match: 0.92 at (450, 320) โ•‘
โ•‘ Time: 145ms โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

Color Meaningsโ€‹

  • ๐ŸŸข Green: Successful matches
  • ๐Ÿ”ด Red: Failed searches or errors
  • ๐ŸŸก Yellow: Warnings or low similarity scores
  • ๐Ÿ”ต Blue: Headers and important information
  • โšช Gray: Detailed/verbose information

Visual Outputโ€‹

Annotated Screenshotsโ€‹

  • Blue dashed lines: Search regions
  • Green rectangles: Successful matches
  • Yellow rectangle: Best match
  • Red X: Failed searches

Comparison Gridsโ€‹

Side-by-side comparison of:

  • Original pattern
  • Found matches
  • Similarity scores

Report Generationโ€‹

HTML Reportsโ€‹

Located at: debug/image-finding/{session-id}/reports/report.html

Contains:

  • Session summary statistics
  • Timeline of all operations
  • Success rate metrics
  • Interactive operation cards

JSON Reportsโ€‹

Located at: debug/image-finding/{session-id}/reports/report.json

Structured data for:

  • Automated analysis
  • CI/CD integration
  • Performance tracking

Troubleshooting Common Issuesโ€‹

Images Not Foundโ€‹

  1. Check similarity threshold

    brobot.find.similarity=0.7  # Lower for more lenient matching
  2. Verify image format

    • Use PNG format for best results
    • Avoid JPEG for UI elements
    • Ensure no scaling/compression
  3. Review debug output

    • Check "best score" in console
    • Look at visual comparisons
    • Examine failure reasons

Performance Issuesโ€‹

  1. Adjust debug level

    brobot.debug.image.level=BASIC  # Reduce overhead
  2. Disable file saving

    brobot.debug.image.save-screenshots=false
    brobot.debug.image.save-patterns=false

Issue: Images Cut with Windows Snipping Tool Not Foundโ€‹

Symptoms: Patterns captured with Win+Shift+S aren't matching

Debug Steps:

  1. Enable DETAILED or VISUAL debugging:
brobot.debug.image.level=VISUAL
  1. Check the debug output for:

    • DPI differences between pattern and screen
    • Color depth mismatches
    • Scaling issues
  2. Review the comparison grid to see visual differences

Common Solutions:

  • Lower similarity threshold: brobot.find.similarity=0.7
  • Check DPI settings in Windows Display Settings
  • Ensure consistent color profiles
  • Save patterns as PNG format
  • Avoid resizing after capture

Issue: No Debug Output Appearingโ€‹

Check:

  1. Correct profile is active:
# Look for: "The following 1 profile is active: "debug""
  1. Debug is enabled in properties:
brobot.debug.image.enabled=true
  1. AOP interceptor is initialized:
โœ… FindOperationInterceptor initialized

Issue: No Colors in Console (Windows)โ€‹

Solution: The Jansi library should auto-enable colors. If not:

  1. Check Jansi is in classpath:
implementation 'org.fusesource.jansi:jansi:2.4.0'
  1. Verify initialization message:
[Brobot Debug] Windows detected - ANSI colors enabled via Jansi
  1. Try different terminal (Windows Terminal, Git Bash, etc.)

Integration with CI/CDโ€‹

GitHub Actionsโ€‹

- name: Run tests with debug
run: ./gradlew test --args='--spring.profiles.active=debug'

- name: Upload debug artifacts
if: failure()
uses: actions/upload-artifact@v2
with:
name: debug-reports
path: debug/image-finding/**

Jenkinsโ€‹

stage('Test with Debug') {
steps {
sh './gradlew test -Dspring.profiles.active=debug'
}
post {
failure {
archiveArtifacts artifacts: 'debug/image-finding/**'
}
}
}

API Usageโ€‹

Programmatic Accessโ€‹

@Autowired
private ImageFindDebugger debugger;

// Initialize session
debugger.initializeSession();

// Debug operations are automatically intercepted
ActionResult result = action.find(stateImage);

// Finalize and generate reports
debugger.finalizeSession();

Custom Debug Infoโ€‹

ImageFindDebugger.FindDebugInfo debugInfo = 
debugger.debugFindOperation(objectCollection, options, result);

System.out.println("Operation ID: " + debugInfo.getOperationId());
System.out.println("Best Score: " + debugInfo.getBestScore());
System.out.println("Duration: " + debugInfo.getSearchDuration() + "ms");

Best Practicesโ€‹

  1. Development: Use DETAILED or VISUAL level
  2. Testing: Use BASIC level with file saving disabled
  3. Production: Keep debugging OFF or use BASIC for critical operations
  4. CI/CD: Enable on failure with artifact collection

Performance Impactโ€‹

LevelConsole OutputFile I/OPerformance Impact
OFFNoneNone0%
BASICMinimalNone~2%
DETAILEDModerateNone~5%
VISUALHeavyHeavy~15-20%
FULLVery HeavyVery Heavy~25-30%

Architectureโ€‹

Componentsโ€‹

  1. ImageDebugConfig: Configuration management via Spring properties
  2. FindOperationInterceptor: AOP aspect intercepting find operations
  3. ImageFindDebugger: Core orchestrator for debug operations
  4. VisualDebugRenderer: Creates annotated images and comparisons
  5. AnsiColor: Console coloring with Windows support via Jansi

Spring AOP Integrationโ€‹

The system uses @Aspect and @Around advice to intercept:

  • Find.perform() operations
  • FindPipeline.saveMatchesToStateImages() calls

This provides transparent debugging without code changes.

Advanced Featuresโ€‹

Custom Debug Handlersโ€‹

Implement custom debug handling:

@Component
public class CustomDebugHandler {

@EventListener
public void handleFindDebugEvent(FindDebugEvent event) {
// Custom logic for debug events
if (event.getSimilarity() < 0.5) {
// Alert on very low similarities
notifyLowSimilarity(event);
}
}
}

Programmatic Controlโ€‹

@Autowired
private ImageDebugConfig debugConfig;

// Temporarily enable debugging
debugConfig.setEnabled(true);
debugConfig.setLevel(DebugLevel.VISUAL);

// Perform find operation
ActionResult result = action.find(stateImage);

// Restore settings
debugConfig.setEnabled(false);