All Projects

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.

Computer VisionArchivedYOLOv5, 52 classesGPL-3.02 peoplefrom scratch
52
Card classes
0.75
Detection confidence
2s
Debounce window
~105 lines
Game logic

Overview

Phase 1

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.

Phase 2

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
What didn't ship

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.

  1. 01
    Webcam

    live card detection, 52 classes

  2. 02
    Debounce

    card must hold 2s to count

  3. 03
    Tarneeb engine

    trump suit + rank order → winner

Stack

YOLOv5full model repo, 52-class card detectorOpenCVwebcam capture + annotationRoboflow / makesense.aimanual card labeling

Output

Card detection output
No. Cards: 7
Club: KC, 2C
Spade: 6S, JS, AS
Heart: QH, 4H
Diamond: _
Tarneeb round resolution
Enter Tarneeb: D
Winner: Fourth
First Player: 3S
Second Player: AS
Third Player: 5S
Fourth Player: 3D

Reproduce it

Local
$ 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