1.9 KiB
1.9 KiB
System Architecture
Piece Recognition Pipeline
-
Board Detection
- VNDetectRectanglesRequest for board location
- Aspect ratio and size validation
- Square extraction with equal dimensions
-
Image Preprocessing
- Contrast and brightness adjustment
- Unsharp mask for edge enhancement
- Consistent image scaling
-
ML Classification
- CoreML model prediction
- Confidence score analysis
- Position-based adjustments
Recognition Patterns
Square Classification
-
Empty Square Detection
- Exact empty_dark/empty_light matching
- High confidence threshold (>0.9)
- Early detection and return
-
Piece Recognition
- Strict label format validation
- Position-based confidence adjustment
- Piece count tracking
-
Error Prevention
- Empty square validation
- Label format checking
- Position rule enforcement
Classification Flow
-
Input Validation
- Image dimensions check
- Model availability check
- Configuration setup
-
Square Analysis
- Empty square check first
- Piece classification second
- Position validation last
-
Confidence Checks
- Empty squares: >0.9
- Pieces: >0.98 with >5.0 ratio
- Position adjustments
-
Error Handling
- Clear error messages
- Detailed logging
- Safe fallbacks
Validation Patterns
-
Piece Count Rules
- Maximum 1: king, queen
- Maximum 2: rooks, bishops, knights
- Maximum 8: pawns
- Track by color and type
-
Position Rules
- Kings: not on opponent's back rank
- Pawns: no backward movement
- All pieces: within board bounds
- All pieces: valid movement patterns
-
Piece Tracking
- Maximum piece counts
- Color-specific tracking
- Total position validation
- Captured piece limits
-
Recognition Flow
- Empty square detection first
- Piece classification second
- Position validation last
- Clear error reporting