/ 03 — Computer Vision

Card Detection

A webcam prototype that detects multiple playing cards, straightens angled frames and identifies a captured six-card set with ORB feature matching.

Role
Solo Developer
Timeframe
2025
Status
Shipped
Six-card live detection result showing the Two of Hearts, Jack of Clubs, Ten of Spades, Queen of Diamonds, King of Hearts and Ace of Spades
PythonOpenCVNumPy
01 / Problem

Playing cards make a compact computer-vision problem: the camera has to separate each white rectangle from the table, handle rotation and glare, then decide whether the card matches anything it has seen before. A weak matcher will confidently assign the wrong name to every unfamiliar card.

02 / Approach

I split detection from recognition. Contour analysis finds convex quadrilaterals and a perspective transform flattens each one to the same size. I capture reference images from the deck, cache their ORB descriptors at startup and require both a minimum score and a clear margin over the next candidate before showing a name.

03 / What I built

Contour detection and perspective correction

Filters the threshold mask by area, shape, aspect ratio and convexity, then warps each detected card into a consistent 300 × 420 image.

ORB matching with rejection

Compares cached binary descriptors with Hamming distance and Lowe’s ratio test. Weak or ambiguous results stay labeled Unknown.

Capture and debug tools

Builds templates from the webcam, labels every live contour and exposes the threshold mask plus normalized crops for tuning and saved evidence.

04 / Outcome
6 / 6
cards identified together
18 / 18
template checks at −30°, 0° and +30°
Unknown
uncaptured Ten of Hearts rejected
05 / Learnings

Most of the improvement came from making the inputs consistent. Once each contour was ordered, flattened and resized the same way, ORB had a fair comparison to make. The rejection threshold mattered just as much: admitting uncertainty is better than attaching a confident wrong label.