Welcome to the Moss Machine project! This open-source initiative provides a comprehensive system for automating the sorting, recognition, and management of Trading Card Game (TCG) cards. The system supports 317 different card games including Magic: The Gathering, Pokemon, Yu-Gi-Oh!, and many others.
The Moss Machine combines perceptual hash-based computer vision, multi-threaded processing, and hardware integration to create a high-performance, scalable card sorting solution. Whether you’re a collector, player, or developer, this project offers tools and guidance to build your own automated card sorting system with speeds capable of processing cards in under 2 seconds per scan.
Open Source & Community Driven
Fully open source code with transparent development. Contributions and modifications are encouraged—please credit the original source when creating derivatives.
OptimizedCardScanner class with multi-threaded game scanninggames table: 317 games with ID, name, display_name, total_cardscards_* tables: One table per game (e.g., cards_magic, cards_pokemon, cards_yugioh)sets table: Set information per game with set codes and card countspip install opencv-python pillow imagehash pyserial numpy
unified_card_database.db in the project directory# Command-line mode (single image)
python optimized_scanner.py card.jpg --cache
# Interactive mode with Arduino
python optimized_scanner.py --interactive --serial-port COM3
# Realtime webcam mode
python optimized_scanner.py --realtime --cache
# GUI mode
python gui_interface_enhanced.py
Upload Main.ino to Arduino Mega 2560
# List all supported games
python optimized_scanner.py --list-games
# List sets for Magic (game ID 167)
python optimized_scanner.py --list-sets 167
# Scan a card, filter to Magic only
python optimized_scanner.py card.jpg -g Magic --cache
# Scan with set filter (Alpha and Beta)
python optimized_scanner.py card.jpg -s LEA -s LEB
# Filter by foil type and rarity
python optimized_scanner.py card.jpg -f Foil -r M -r R
# Adaptive scan with relaxed thresholds
python optimized_scanner.py card.jpg -t 20 --min-confidence 70
max_workers: Thread pool size (default: 8)cache_enabled: Enable in-memory hash caching (default: True)threshold: Match threshold, lower = stricter (default: 10)top_n: Number of top matches to return (default: 10)min_confidence: Minimum confidence % for Method 1 (default: 85.0)scan_cooldown: Seconds between auto-scans (default: 2.0)Xcal, Ycal, Zcal: Movement calibration multipliers (350, 475, 140)speed: XY movement speed in microseconds (default: 700)zspeed, zespeed: Z-axis speeds (75, 120)initial_pickup_distance: Z distance to pickup position (6000 steps)initial_drop_distance: Z distance to drop position (4000 steps)pickup_threshold: Distance threshold for successful pickup (40mm)release_threshold: Distance threshold for successful release (40mm)HCC: Homing cycle count - rehome every N cards (default: 10)XCourseCorrection, YCourseCorrection: Fine-tune positioning (0, 1)X[6][5] and Y[4][7] define physical tray positions









Disclaimer:
This system is intended for hobbyist and educational use. Always test with non-valuable cards first. Handle valuable or rare cards with care—never trust automated sorting in critical scenarios. The project is open source; use at your own risk.
![]() |
![]() |
![]() |
|---|---|---|
| Join our Discord: https://discord.gg/2gNWpV6UjW |
Reddit: r/MossMachine |
Repository: GitHub |
Help keep my motivation
Other non-related support:
This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0).
Please give credit to the original authors when creating derivatives.
Happy Sorting!