Pattern Creation Tools Guide
Overviewโ
This guide helps you choose the best tool for creating pattern images that work with Brobot's pattern matching system. The choice of pattern creation tool directly impacts the accuracy of your UI automation.
Recommended Toolsโ
๐ Optimal Tools for Pattern Creationโ
These tools provide the best pattern matching during runtime automation:
1. Windows Snipping Tool (RECOMMENDED)โ
- Resolution: 1920x1080 (physical)
- Runtime Match Rate: 95-100% with Brobot's JAVACV_FFMPEG capture provider
- Platform: Windows only
- Why it's best: Produces the cleanest, artifact-free patterns
- How to use:
- Press
Win + Shift + Sto open Snipping Tool - Select the area you want to capture
- Save as PNG in your project's
images/directory
- Press
For detailed provider comparison, see the Capture Methods Comparison.
2. macOS Screenshot Toolโ
- Platform: macOS
- Runtime Match Rate: 95-100%
- How to use: Press
Cmd + Shift + 4
3. Linux Screenshot Toolsโ
- Platform: Linux
- Runtime Match Rate: 95-100%
- Tools: GNOME Screenshot or Spectacle
โ Alternative Tools (Lower Match Rates)โ
SikuliX IDEโ
- Resolution: Variable (depends on DPI settings)
- Runtime Match Rate: 70-80% (can be used for testing similarity)
- Platform: Cross-platform
- Use case: Testing similarity thresholds, not for pattern creation
Brobot FFmpeg Toolโ
- Resolution: 1920x1080 (physical)
- Runtime Match Rate: 70-80% when used for patterns
- Platform: Cross-platform
- Note: Better for testing than pattern creation
โ ๏ธ Not Recommended (< 70% Similarity)โ
- Screenshot tools that apply compression or filters
- Browser-based screenshot extensions
- Tools that capture at non-standard resolutions
- Robot-based custom tools (typically 59-69% similarity)
Brobot Configurationโ
Default Configuration (Optimal)โ
The default Brobot configuration is optimized for patterns created with Windows Snipping Tool, SikuliX IDE, or Brobot FFmpeg Tool. See the Properties Reference for complete configuration options.
# Already configured in brobot-defaults.properties
brobot.capture.provider=JAVACV_FFMPEG
brobot.dpi.disable=true
brobot.dpi.resize-factor=1.0
This configuration:
- Captures at physical resolution (1920x1080)
- Disables DPI awareness to avoid scaling issues
- Uses no pattern scaling for 1:1 pixel matching
- Provides 100% similarity with recommended tools
For more on DPI handling, see the DPI Resolution Guide.
Alternative Configuration (For Logical Resolution Tools)โ
If you're using tools that capture at logical resolution (1536x864 with 125% DPI scaling):
# application.properties
brobot.capture.provider=SIKULIX
brobot.dpi.disable=false
brobot.dpi.resize-factor=1.0
Pattern Creation Workflowโ
Step 1: Choose Your Toolโ
- For best results: Use OS native screenshot tools
- Windows: Windows Snipping Tool (Win+Shift+S)
- macOS: Built-in screenshot (Cmd+Shift+4)
- Linux: GNOME Screenshot or Spectacle
- For testing patterns: Use Brobot Pattern Capture Tool
- If you have existing patterns: Test their match rates and consider recapturing with native tools
Step 2: Capture Patternsโ
- Ensure your display is at the target resolution
- Capture UI elements with your chosen tool
- Save as PNG files (avoid JPEG to prevent compression artifacts)
- Use descriptive names:
button-submit.png,field-username.png
Step 3: Organize Patternsโ
your-project/
โโโ images/
โ โโโ login-page/
โ โ โโโ button-login.png
โ โ โโโ field-username.png
โ โ โโโ field-password.png
โ โโโ main-menu/
โ โโโ menu-file.png
โ โโโ menu-edit.png
Step 4: Verify Pattern Matchingโ
Test your patterns to ensure they match correctly. For more details, see the States Guide and Action API.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import io.github.jspinak.brobot.action.Action;
import io.github.jspinak.brobot.action.ActionResult;
import io.github.jspinak.brobot.model.state.StateImage;
import io.github.jspinak.brobot.model.match.Match;
@Component
public class PatternVerificationExample {
@Autowired
private Action action;
public void verifyPattern() {
StateImage pattern = new StateImage.Builder()
.addPattern("button-login.png") // Use addPattern, not withImage
.build();
ActionResult result = action.find(pattern);
// Get similarity score from best match
if (result.getBestMatch().isPresent()) {
Match bestMatch = result.getBestMatch().get();
System.out.println("Similarity: " + bestMatch.getScore());
// Should be > 0.94 for optimal tools
} else {
System.out.println("No match found");
}
}
}
Troubleshootingโ
Low Similarity Scoresโ
If you're getting similarity scores below 90%:
-
Check Resolution Mismatch
- Pattern: 1920x1080, Capture: 1536x864 โ ~77% similarity
- Solution: Use matching capture provider or enable scaling
- See the DPI Resolution Guide for troubleshooting
-
Check DPI Settings
# In your application.properties
brobot.dpi.disable=true # For physical resolution -
Verify Tool Output
- Some tools apply compression or filters
- Always save as PNG, not JPEG
- Check file size - unusually small files may be compressed
Pattern Not Foundโ
-
Lower similarity threshold if needed:
brobot.action.similarity=0.85 # Default is 0.95 -
Check if pattern is unique enough:
- Avoid capturing too small areas
- Include distinctive features
- Avoid areas with changing content
Resolution Compatibility Tableโ
| Pattern Creation Tool | Best Brobot Provider | Runtime Match Rate | Recommendation |
|---|---|---|---|
| Windows Snipping Tool | JAVACV_FFMPEG | 95-100% | RECOMMENDED |
| macOS Screenshot | JAVACV_FFMPEG | 95-100% | RECOMMENDED |
| Linux Screenshot | JAVACV_FFMPEG | 95-100% | RECOMMENDED |
| Brobot FFmpeg Tool | JAVACV_FFMPEG | 70-80% | Testing only |
| SikuliX IDE | JAVACV_FFMPEG | 70-80% | Testing only |
Best Practicesโ
DO:โ
- โ Use PNG format for patterns
- โ Capture at the same resolution you'll run automation
- โ Include unique visual elements in patterns
- โ Test patterns immediately after creation
- โ Organize patterns by screen/state
DON'T:โ
- โ Use JPEG format (compression artifacts)
- โ Capture patterns with transparency
- โ Include dynamic content (timestamps, counters)
- โ Make patterns too small (< 20x20 pixels)
- โ Mix patterns from different tools without testing
Platform-Specific Notesโ
Windowsโ
- Windows Snipping Tool is built-in and optimal
- Captures at physical resolution regardless of DPI scaling
- Perfect compatibility with default Brobot configuration
macOSโ
- Use built-in screenshot tool (Cmd+Shift+4) for best results - achieves 95-100% match rates
- Alternative: SikuliX IDE for cross-platform consistency
- Verify resolution before creating many patterns
Linuxโ
- SikuliX IDE recommended
- Native screenshot tools vary by distribution
- Test compatibility before creating pattern library
WSL (Windows Subsystem for Linux)โ
โ ๏ธ CRITICAL LIMITATION: WSL cannot capture the Windows desktop
- Pattern matching will NOT work in WSL - captures return black/empty images
- Development only - Use WSL for coding, not for running pattern matching
- Solutions:
- Run Brobot on Windows directly (use PowerShell or Command Prompt)
- Use mock mode for testing in WSL (
brobot.mock=true) - Create patterns on Windows, test on Windows
Migration Guideโ
From Existing Patternsโ
If you have patterns created with other tools:
-
Identify pattern resolution:
# Check image properties
file pattern.png
# Or use image viewer to check dimensions -
Adjust Brobot configuration:
- 1920x1080 patterns โ Use default configuration
- 1536x864 patterns โ Switch to SIKULIX provider
- Other resolutions โ May need custom scaling
-
Test and verify:
For more on ActionConfig, see the ActionConfig Overview.
import io.github.jspinak.brobot.action.Action;
import io.github.jspinak.brobot.action.ActionResult;
import io.github.jspinak.brobot.action.basic.find.PatternFindOptions;
import io.github.jspinak.brobot.model.state.StateImage;
import org.springframework.beans.factory.annotation.Autowired;
@Component
public class MigrationTest {
@Autowired
private Action action;
public void testMigratedPattern() {
// Run similarity test with lower threshold
PatternFindOptions options = new PatternFindOptions.Builder()
.setSimilarity(0.7) // Start low for testing
.build();
StateImage pattern = new StateImage.Builder()
.addPattern("legacy-button.png")
.build();
ActionResult result = action.perform(options, pattern.asObjectCollection());
if (result.isSuccess()) {
System.out.println("Found " + result.size() + " matches");
}
}
}
Frequently Asked Questionsโ
Q: Why do different tools have different similarity scores?โ
A: Tools capture screens differently - some use logical resolution (DPI-aware), others use physical resolution. Rendering engines also differ slightly between tools.
Q: Can I mix patterns from different tools?โ
A: Not recommended. Stick to one tool for consistency. If you must mix, group patterns by tool and adjust configuration per state.
Q: What if my screen resolution is different from 1920x1080?โ
A: Create patterns at your target resolution. Brobot will capture at the same resolution. The key is consistency between pattern creation and execution.
Q: How can I verify which resolution my patterns are?โ
A: Check the image properties or use Brobot's debug mode to log pattern dimensions:
brobot.screenshot.save-snapshots=true
brobot.console.actions.enabled=true
Summaryโ
For optimal pattern matching:
- Use OS native screenshot tools - Windows Snipping Tool, macOS Screenshot, or Linux Screenshot tools
- Keep default Brobot configuration - JAVACV_FFMPEG for runtime capture
- Save patterns as PNG - Avoid compression artifacts
- Organize patterns by state - Easier maintenance
Key insight: Clean, artifact-free patterns from native OS tools match better during runtime than patterns captured with the same tool used for runtime capture. This counterintuitive result occurs because noise and artifacts compound when present in both pattern and runtime images.
Note: Match rate claims are based on testing configurations. Results may vary based on your specific environment, display settings, and Windows version.
Related Documentationโ
Getting Startedโ
- Installation Guide - Platform setup including WSL considerations
- States in Brobot - Understanding StateImage patterns
- Action Hierarchy - Using patterns with Actions
Capture Systemโ
- Modular Capture System - Understanding JAVACV_FFMPEG and other providers
- Capture Methods Comparison - Detailed comparison of all capture providers
- DPI Resolution Guide - Handling DPI scaling and resolution mismatches
- Pattern Capture Tool Guide - Using Brobot's built-in pattern capture tool
Configurationโ
- Properties Reference - Complete list of Brobot properties including similarity, capture provider, and DPI settings
- ActionConfig Overview - Configuring pattern matching with PatternFindOptions
- ActionConfig Reference - Complete ActionConfig API including similarity configuration
Testing & Debuggingโ
- Mock Mode Guide - Testing patterns without display (essential for WSL/headless environments)
- Debugging Pattern Matching - Troubleshooting pattern matching issues
- Integration Testing - Testing automation with patterns
Advanced Topicsโ
- Reusable Patterns - Creating pattern libraries and reusable configurations
- Convenience Methods - Simplified API for pattern finding and clicking