Playing Card Detection & Tarneeb.
A YOLOv5 card detector feeding a from-scratch Tarneeb round-winner engine — built and debugged with a teammate over one semester.
Overview
Detecting all 52 cards
The model was trained on manually labeled card images (via makesense.ai and Roboflow) at roughly a 2,000-image scale — an author's-own-report admission that this run "wasn't accurate enough" for reliable play. A follow-up attempt at 25,000 images crashed the Colab training session before finishing, so despite what an older README claims, no 25K-image model was ever successfully trained and shipped — worth stating plainly rather than repeating the unverified number.
detect.py reports live counts and per-suit breakdowns as cards enter frame.
Tarneeb round-winner logic, hardest part first
A ~105-line engine tracks four players' cards against a chosen trump suit and a fixed rank order to determine the round winner. The genuinely hard problem, per the team's own writeup: a card only counts once it's held in frame for 2+ seconds, to avoid double-counting the same physical card as it's picked up, shown, and put back down.
- Enter Tarneeb
- trump suit chosen at round start
- Four players
- cards tracked in play order
- Winner
- resolved by trump + rank order
The web deployment attempt
A Streamlit deployment was attempted but not completed — the team's report describes not being able to connect browser input to the detection loop and stream results back live. The repo has a leftover app.py from that attempt; it was never a working deployed app, which is why this project only links to source, no live demo.
Method
A YOLOv5 model trained on all 52 standard cards detects what's on the table; a from-scratch Tarneeb engine tracks four players' cards and decides the round winner.
- 01Webcam
live card detection, 52 classes
- 02Debounce
card must hold 2s to count
- 03Tarneeb engine
trump suit + rank order → winner
Stack
Output
No. Cards: 7 Club: KC, 2C Spade: 6S, JS, AS Heart: QH, 4H Diamond: _
Enter Tarneeb: D Winner: Fourth First Player: 3S Second Player: AS Third Player: 5S Fourth Player: 3D
Reproduce it
$ git clone https://github.com/baselhusam/Playing-Cards-Detection-with-Tarneeb.git$ cd Playing-Cards-Detection-with-Tarneeb$ pip install -r requirements.txt$ python detect_trnb.py --weights best_weights.pt --img 640 --conf 0.75 --source 0