# π PokerVision
> **PokerVision** is a computer-vision project that detects and classifies playing cards in real time using a YOLO model.
> It combines **synthetic dataset generation**, **YOLO training**, and a **real-time βDetect / Texas Holdβemβ demo** with optional equity estimation.
---
## π Features
- π¨ **Synthetic dataset generator** (random backgrounds + card variants)
- π§ **YOLO (Ultralytics)** training + inference for card classification
- π₯ **Real-time inference** from:
- Laptop webcam (index `0`, `1`, β¦)
- OBS Virtual Camera
- DroidCam / phone streams (HTTP/RTSP if your app provides it)
- π **Two realtime modes**
- **Detect mode**: show individual card detections (single boxes)
- **Holdβem mode**: cluster detections into *board + player hands* and (optionally) compute equities
- π§© Built-in camera probing: `--list_cams`
- β¨οΈ Quick mode toggle: press **`m`** (and **`q`** to quit)
- β β₯β¦β£ pretty suit symbols (optional, if your OpenCV build supports `cv2.freetype` + you provide a font)
---
## π Project Structure
```plaintext
PokerVision/
βββ data/
β βββ backgrounds/ # Background images for synthetic data
β βββ generated/ # Auto-generated images (often ignored by git)
β βββ raw_cards/ # Source card images (normal/inverted/real)
β βββ yolo_dataset/ # YOLO-formatted dataset (train/val images & labels)
β
βββ runs/ # YOLO training results (often ignored by git)
βββ src/
β βββ dataset_gen/ # Dataset generation scripts
β βββ realtime/ # Real-time demos
β β βββ webcam_card_corners.py
β βββ utils/ # Shared helper functions (e.g., CUDA check)
β
βββ cards.yaml # YOLO dataset config
βββ requirements.txt # Python dependencies
βββ .gitignore
βββ README.mdNote: folders like
runs/,data/generated/, and large weights are typically ignored by git.
git clone https://github.com/Yufan3/PokerVision.git
cd PokerVisionconda create -n pokervision python=3.10 -y
conda activate pokervisionpip install -r requirements.txtpython -m src.utils.check_cudaThis project opens a live window (cv2.namedWindow, cv2.imshow).
If you see an error like:
The function is not implemented ... in function 'cvNamedWindow'
You likely installed a headless OpenCV build or youβre in an environment without GUI support.
Fix by installing GUI-enabled OpenCV:
pip uninstall -y opencv-python-headless
pip install opencv-pythonGenerate a synthetic dataset (backgrounds + random card placements):
python -m src.dataset_gen.generate_datasetOutputs:
data/generated/
data/yolo_dataset/Train a detector on your dataset:
yolo detect train model=yolo11s.pt data=cards.yaml epochs=100 imgsz=640 batch=16 device=0Best weights will be saved to:
runs/detect/train*/weights/best.ptThe main realtime entrypoint is:
src/realtime/webcam_card_corners.py
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source 0Controls:
- Press
mto toggle Detect / Holdβem - Press
qto quit
# Start in Detect mode
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source 0 --start_mode detect
# Start in Holdβem mode
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source 0 --start_mode holdempython -m src.realtime.webcam_card_corners --list_camsIf your OBS/DroidCam virtual camera is running, it should appear as a usable index (often 1, 2, 3, ...).
- In OBS, click Start Virtual Camera
- Probe indices:
python -m src.realtime.webcam_card_corners --list_cams- Run using the correct index:
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source 1You can also try opening by name (depends on your system/OpenCV backend):
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source "OBS Virtual Camera" --backend dshowYour phone must provide a stream URL (HTTP/RTSP). Different apps use different URLs.
Typical patterns (examples only β check your appβs UI):
# Example HTTP stream (some apps)
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source "http://192.168.1.92:4747/video"
# Example RTSP stream (some apps)
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source "rtsp://192.168.1.92:8554/live"If youβre using an iPhone, you can use apps that expose an IP camera stream (RTSP/HTTP), or route it through OBS and use OBS Virtual Camera.
If your OpenCV supports cv2.freetype, PokerVision can render suit symbols.
pip install opencv-contrib-pythonOn Windows, a common option is:
C:\Windows\Fonts\seguisym.ttfRun:
python -m src.realtime.webcam_card_corners ^
--model runs/detect/train*/weights/best.pt ^
--source 0 ^
--font "C:\Windows\Fonts\seguisym.ttf"If cv2.freetype isnβt available, the script will fall back to plain OpenCV text rendering.
Try in this order:
- Confirm the camera exists:
python -m src.realtime.webcam_card_corners --list_cams- Use the index that opens successfully:
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source 1- For Windows virtual cams, force DirectShow:
python -m src.realtime.webcam_card_corners --model runs/detect/train*/weights/best.pt --source 1 --backend dshow- Close other apps that might be locking the camera (Zoom/Teams/Chrome/OBS preview windows, etc.)
If you see GUI errors, reinstall non-headless OpenCV:
pip uninstall -y opencv-python-headless
pip install opencv-pythonThis project is open-source under the MIT License.
See LICENSE for details.
::contentReference[oaicite:0]{index=0}