2.1 KiB
2.1 KiB
Technical Context
Development Environment
- macOS Application
- Swift & SwiftUI
- Xcode 14+
- Target: macOS 12.3+
Core Technologies
-
Vision Framework
- VNDetectRectanglesRequest for board detection
- VNCoreMLRequest for piece classification
- VNImageRequestHandler for image processing
-
Core ML Model
- Name: ChessPieceClassifier.mlmodel
- Input: RGB/RGBA images
- Output: Classification label
- Categories (exact names):
white_pawn, white_knight, white_bishop, white_rook, white_queen, white_king, black_pawn, black_knight, black_bishop, black_rook, black_queen, black_king
-
ScreenCaptureKit
- Window capture at 30 FPS
- Configurable cursor visibility
- Chess.com window detection
Image Processing
-
Preprocessing Pipeline
- Contrast enhancement (1.3x)
- Edge sharpening
- Noise reduction
- Color normalization
-
Square Extraction
- Aspect ratio validation
- Size normalization
- Center crop
Model Integration
-
Loading
let config = MLModelConfiguration() config.computeUnits = .all let model = try MLModel(contentsOf: modelURL) let vnModel = try VNCoreMLModel(for: model) -
Classification
let request = VNCoreMLRequest(model: vnModel) request.imageCropAndScaleOption = .centerCrop -
Result Handling
- Confidence threshold: 0.75
- Empty square fallback
- Direct category mapping
Dependencies
- Foundation
- Vision
- CoreML
- CoreImage
- ScreenCaptureKit
- SwiftUI
Error Handling
- Invalid dimensions
- Model loading failures
- Recognition errors
- Low confidence results
File Organization
ChessPrism/
├── Models/
│ ├── SquareClassification.swift # Model output mapping
│ └── ChessPosition.swift # Board state
├── Recognition/
│ ├── PieceRecognizer.swift # ML integration
│ ├── FenGenerator.swift # Position encoding
│ └── MoveDetector.swift # Move analysis
└── Core/
├── BoardDetector.swift # Square extraction
└── ScreenCapture.swift # Window capture