1.9 KiB
1.9 KiB
System Patterns
Model Architecture
-
Core ML Integration
- Vision framework for image handling
- Direct category mapping
- No intermediate transformations
-
Classification Flow
Image → VNImageRequestHandler → VNCoreMLRequest → VNClassificationObservation → SquareClassification -
Category System
- 12 piece categories:
- white_pawn to white_king
- black_pawn to black_king
- Empty square fallback
- No background variations in model
- 12 piece categories:
Processing Pipeline
-
Board Detection
- VNDetectRectanglesRequest
- Aspect ratio validation
- Square extraction
-
Image Processing
- Contrast enhancement
- Edge sharpening
- Noise reduction
- Center crop
-
Classification
- Vision framework integration
- Confidence threshold
- Error handling
Code Organization
-
Recognition Layer
PieceRecognizer ├── Model loading ├── Image preprocessing └── Classification handling -
Model Layer
SquareClassification ├── Category mapping ├── Piece type/color └── Empty square handling -
Core Components
BoardDetector ├── Rectangle detection ├── Square extraction └── Position validation
Data Flow
-
Capture
ScreenCapture → Raw Image → Board Rectangle -
Processing
Board Rectangle → Individual Squares → Preprocessed Images -
Classification
Preprocessed Images → ML Model → Piece Categories → Chess Position
Key Patterns
-
Direct Integration
- Vision framework throughout
- No intermediate conversions
- Consistent image handling
-
Error Handling
- Early validation
- Graceful fallbacks
- Detailed logging
-
Performance
- Shared CIContext
- Efficient image processing
- Optimized model loading