Mojenn's card reader looks at a table through a phone camera and names every card it can see. It works in two stages. The Spotter finds every card corner in the frame. The Sniper reads each corner's index, the rank and suit printed in the corner, and names the card.
Both stages used to work with axis-aligned bounding boxes (AABB): rectangles whose sides follow the edges of the image. That's the standard way to train an object detector, and the reader already worked with cards at any angle. Its hardest case was cards fanned very close together, where a tilted corner's AABB also takes in its neighbours. This article explains how both networks moved to object-aligned bounding boxes (OBB), boxes that turn with the card, and how much more accurate that made the reader.
The design goal throughout was simple: never name the wrong card. A corner the reader can't read only costs a prompt to move the phone closer. A wrong card that the app believes is much worse. Every choice below was tuned against wrong cards first.
Two networks, two resolutions
Why not have one detector find the corners and name the cards? Because of pixels. To run fast on a phone, the Spotter looks at a scaled-down copy of the camera frame, 1280 × 960 instead of the sensor's 4032 × 3024. That's plenty to see where the corners are, even far away, but a far card's index is then only a couple of dozen pixels tall, too few to tell an 8 from a 3. So once a corner is spotted, that region is cut from the original frame at full resolution, turned upright using the OBB's direction, then scaled and stretched to the Sniper's fixed input.

The phone captures the full sensor, 4032 × 3024 pixels.
A 1280 × 960 copy is enough to find every corner and its direction, quickly.
Each corner is cut from the original frame at full resolution, turned upright and scaled to 64 × 128.
The Sniper reads each strip, and accepts the read only when it is sure.

cut from the scaled copy3♣︎42%
cut from the full frame8♣︎89%
Splitting the work has a second advantage: speed. The Spotter runs once per frame, however many cards are on the table, but the Sniper runs once per corner, and a full table can show dozens of corners. So each frame, the app sends the Sniper only a fixed number of corners, which keeps the frame rate steady. Because every corner is followed from frame to frame, the app knows which cards are already recognized, and spends that budget where it helps most:
- a couple of corners that are already recognized, re-read in turn to check that every card is still where the app thinks it is;
- corners that are being read but aren't confirmed yet;
- corners seen for the first time;
- last, corners the Sniper couldn't read so far, such as partly covered ones, retried when there's room.
Every other recognized card keeps its name without being read again. That is what lets a phone follow a whole table without slowing down.
What an AABB holds on a crowded table
A card's index is a tall, narrow strip, more than twice as tall as it is wide, and it follows the card's angle. The smallest AABB around a tilted index grows quickly: at 45° it covers almost two and a half times the index's own area. In a tight fan, that extra area is where the next card's index sits. Try it:
On the photo at the top, the AABBs are on average 1.64× the size of the OBBs, and up to 2.75×. Compare the two views of the same corners:
The Sniper used to read a square crop around each AABB. It learned to read the corner in the middle and to ignore the neighbouring indexes around it, and it did. But a crop cut along an OBB is a simpler problem: it holds only the corner to recognize, centred, with no neighbouring card. The model trains more easily on it and gets more right. Moving to OBBs improved four things at once:
- Tighter crops. The Sniper sees one index and nothing else, even in the tightest fan.
- Better duplicate removal. The detector proposes several boxes per corner and removes the weaker ones that overlap a stronger one. OBBs of close tilted corners don't overlap, so neighbours are kept. More on this below.
- Orientation becomes information. The old Sniper read corners in any orientation, which meant learning every glyph at every angle and telling a 6 from a 9 by layout cues alone. With the OBB's direction, every crop can be turned upright first, so the rank is always on top.
- Partly covered corners join the training data. The new labels say how much of each corner is visible, so both networks now learn what to do with a corner half hidden under another card. Those are the corners most likely to be misread.
Stage 1: a Spotter that knows which way is up
The Spotter is a YOLOX-Tiny detector with a single class, "card corner". Besides each corner's centre and size, it now predicts the direction of the index's "up", toward the rank, as a unit vector. A unit vector covers the full 360°, so the Spotter tells the rank end from the suit end: an OBB is never just "tilted 30°", it is "tilted 30° with the rank at this end". The arrows in the photo above are that prediction. On held-out real photos the median angle error is about 1.5°, and no box points the wrong way.
Comparing true shapes
A detector produces many overlapping guesses for each corner. A clean-up step called non-maximum suppression (NMS) keeps the most confident guess and removes the others that overlap it too much. With AABBs, two tilted corners side by side can overlap a lot even when the corners themselves don't touch, and the clean-up then removes a real corner:
The filter takes the 8♦︎ for a second, weaker detection of the 9♣︎ and removes it (faded): a real corner is lost.In this demo, boxes overlapping by more than 25% count as duplicates.
The OBB clean-up compares the true, turned shapes, plus a "same spot" rule for thin boxes that barely overlap when slightly shifted. With no retraining at all, comparing true shapes removed a quarter of the Spotter's wrong detections on our test renders (204 to 153) and recovered missed corners (322 to 306).
Don't-care corners
The training images are mostly Unreal Engine renders of card tables: about 95% of the Spotter's training images and 96% of the Sniper's training corners. (Generating these synthetic images in Unreal Engine will probably be the subject of an upcoming article.) A render knows exactly where every corner is, including corners hidden under other cards, so since November each corner is labelled with how much of its rank and of its suit is visible.
This raises a question: what should the Spotter do with a corner that's only partly visible? Calling it background teaches the model to ignore exactly the stacked corners we want it to find. Calling it a target forces it to fire on corners nobody can read. The answer is neither. Corners too covered to read are marked don't care: the Spotter is neither rewarded nor punished for finding them, and in evaluation a detection there counts as neither right nor wrong. Deciding what such a corner says is left to the Sniper.
On a sample training batch, 17% of the Spotter's "is there a corner here?" error came from being told that partly hidden corners were background, a direct contradiction of what we want. With don't-care training, recall on corners 40–60% visible rose from 77% to 93%.
Technical detail: how don't-care corners enter the loss
Don't-care corners are stored as COCO iscrowd regions, so the standard tools already treat them as "ignore". In the YOLOX head, target assignment sees only real corners, so a grid point assigned to a visible corner stays positive even when it lies inside a don't-care box. Any other point whose predicted centre falls inside a don't-care box is left out of the objectness loss. The box, class and angle losses use positives only, so they're unchanged. That mirrors the evaluation rule exactly.
Evaluation needed care too. Far corners can be 3 px wide in the Spotter's input, where a 1.5 px shift halves any overlap score. A detection now matches a corner when the rotated overlap is large enough or its centre is close relative to the corner's height with a similar size. That alone moved real-photo recall from 99.04% to 99.19% and precision from 99.49% to 99.80%, with no change to the model, because correct finds stopped being counted as both a miss and a false hit.
The whole frame, from far away to close up
The first OBB Spotter took a 960 × 960 square. A phone's 4:3 frame fits in it as 960 × 720, so a quarter of the input was grey padding. It had never seen a corner larger than about 100 px, so a player holding a card up to the phone got nothing: it found 0% of real corners larger than 256 px.
The Spotter now takes the full 4:3 frame at 1280 × 960, 78% more picture, with no padding. Training adds close-up tiles cut from the 4K renders, so it sees corners from about 10 px to 600 px. Later rounds added rendered close-ups of one or two cards.
Corners in one photo are about the same size
One fine woven tablecloth produced a strange result: a neat column of small false detections, the weave lining up with the network's sampling grid. Simple size limits couldn't remove them without losing real distant corners, because the false boxes were the size of ordinary corners far away. What gives them away is their size relative to the other corners in the same photo. All the cards on a table are the same physical size, so a weak detection much smaller than the confident corners around it is dropped. On the photos with that cloth, this size-coherence rule removed 138 of the 140 false detections without losing a single labelled corner.
Real photos
Renders are perfect teachers for geometry but imperfect for appearance: real decks, real lighting and real cameras differ. The last round added 626 real photos (786 images, counting turned copies of top-down close-ups), with about 13,700 corner OBBs, each drawn and checked by hand. They were split into training, validation and test images within each group, so every kind of photo is represented in the held-out sets. On 106 held-out real images, the Spotter's missed corners fell from 36 to 16 and its false detections from 13 to 4, while results on renders stayed the same. Of those 16 misses, 12 are in one steep photo where glare hides the far corners, which a person can hardly read either.
Even so, real photos remain a small share of what the networks learn from. What they decide is how the results are judged:
| From renders | From real photos | |
|---|---|---|
| Spotter training images | 11,471 (95%) | 568 (5%) |
| Sniper training corners | 193,092 (96%) | 8,924 (4%) |
| Held out for validation and testing | validation and test renders | 106 + 112 images |
Stage 2: a Sniper that reads upright
The Sniper is a MobileNetV3-Large classifier with 52 outputs, one per card. What changed most is its input. Instead of a square crop around an AABB, in any orientation, it gets a 64 × 128 upright strip, cut along the Spotter's OBB from the full-resolution camera frame: rank on top, suit below, neighbours left out.
The Spotter outlines the corner's index with an OBB and points an arrow toward the rank. Here the 3♥ lies on its side.
Here are all 18 corners of the photo as the Sniper sees them, with the card it named and how sure it was:
3♠︎91%
K♥︎84%
2♦︎96%
A♣︎91%
7♣︎92%
A♦︎95%
8♥︎94%
10♠︎95%
7♦︎93%
K♣︎95%
8♣︎94%
3♦︎83%
8♠︎95%
10♥︎93%
J♣︎95%
7♠︎92%
3♥︎92%
J♣︎96%
Orientation is information
Because every crop is upright, the Sniper is never trained on rotated or mirrored crops. It reads one canonical view, and an upside-down index is simply not a card. That gives the 6-or-9 question a clean answer:
upright9♠︎94%
turned 180°6♥︎14%
Saying only what you can see
Partly covered corners are now part of the Sniper's training, with honest targets. If the suit is hidden, the target spreads the probability evenly over the four suits of that rank. If the rank is hidden, over the thirteen ranks of that suit. A ramp in between handles corners that are partly readable. The Sniper learns to answer "a 7, suit unknown", which is a low-confidence answer, instead of guessing a suit.
9♠︎94%
7♠︎92%
5♥︎96%
4♦︎94%
A♣︎96%
4♥︎95%
really 3♦︎K♣︎2%
really 9♦︎4♦︎8%
really 10♣︎Q♣︎3%
really 4♣︎9♣︎7%
really 9♥︎5♥︎4%
really 9♣︎9♣︎6%
In the app, this shows up as corners that wait until they can be read:
Expecting the Spotter's small mistakes
The Spotter's angle is very good but not perfect, and a crop cut from a slightly turned box shows a slightly turned index. The first OBB Sniper, trained only on perfect boxes, didn't cope: with the box turned by 10°, it read only 16% of corners, and it swapped aces and 4s with high confidence.
So each training corner also gets turned copies, cut from the source image with the box turned a few degrees each way and shifted slightly, covering the Spotter's measured error. And because a tilted camera skews a card's corner in perspective, each corner also gets skewed copies, cut from the real image with a slanted window, so every pixel is real.
turned −10°3♥︎94%
turned −5°3♥︎94%
turned +5°3♥︎87%
turned +10°3♥︎85%
skewed left3♥︎91%
skewed right3♥︎92%
Technical detail: perspective skew, and choosing the epoch
On a tilted camera, a card's edge and its rank-suit axis are no longer at right angles in the image. In the upright crop, pixel columns shift linearly from left to right, which no rectangle can undo. From the camera geometry, the largest skew is s = (r − 1/r) / 2 for a local foreshortening r, in rows per column:
| Camera tilt from vertical | Centre of frame | Far edge |
|---|---|---|
| 0° (pointing down) | 0 | 0 |
| 20° | 0.06 | 0.27 |
| 40° | 0.27 | 0.90 |
The skewed training copies are cut with a sheared window that grows to hold the whole corner, exactly as the Spotter's box around a skewed corner would. Nothing is invented by warping.
Choosing the epoch. Raw accuracy rewards the wrong thing. After each epoch, validation finds the confidence of the single most confident wrong read: a visible corner read as the wrong card, or a covered corner read as another card. The score is the share of visible corners read correctly with a clear margin above that worst mistake. That picks the model that reads the most cards with room to spare, rather than the one that's right most often but occasionally confidently wrong. The acceptance threshold is fixed on validation, then checked once on the untouched test set.
From renders to real photos
The fully visible corners of the real training photos were added to the Sniper's training. Together with the skewed copies, that was the largest single step:
Results
On the final test split, never used for any choice, with the threshold fixed beforehand:
- No wrong card accepted in 165,222 accepted reads.
- 95.3% of fully visible corners read and accepted overall, and 97.2% on held-out real photos.
- 97.3% of partly covered corners declined. The rest were read as their own card.
- Spotter on held-out real photos: 99.2% recall, 99.8% precision, median angle error about 1.5°.
Each hard case now has a specific answer:
| Hard case | How the OBB pipeline handles it |
|---|---|
| Neighbouring indexes next to the corner | The crop follows the corner's own OBB, so it holds only that index |
| Close tilted corners in a tight fan | Duplicate removal compares OBBs, the true shapes |
| Telling a 6 from a 9 | Crops are always upright, and upside-down crops are never accepted |
| A partly covered corner | Training targets say only what is visible |
| Small errors in the Spotter's angle | Turned training copies |
| Perspective skew on a tilted camera | Skewed training copies, cut from real pixels |
| Far cards, too few pixels to read | The Spotter works on a scaled-down copy, but each crop is cut from the full-resolution frame; corners that are still too small prompt "move closer" |
| Renders don't look like real decks | Hand-labelled real photos in both networks, with a held-out real test |
| False detections on woven cloth | Size coherence |
| Choosing the acceptance threshold | Chosen by margin on validation, then checked once on an untouched test |
A bonus: grouping the table in Ranger
Ranger computes the odds of every hand at a poker table. For that, knowing the cards isn't enough: it needs to know whose they are, which cards make the board and which two belong to each player. OBBs turned out to be just as valuable here:
- A whole card from one corner. An AABB only says where a corner is. An OBB also says which way the card points and how big it is, so the card's centre and outline follow from a single corner. Cards can then be compared centre to centre, in card sizes: two cards close together make a hand, and an evenly spaced row of three to five makes the board.
- Two corners, one card. A card often shows both of its corners. Two corners with the same name, pointing away from each other at the right distance, are one card, not two. The same name twice, pointing the same way, means one of the reads is wrong.
- Cards under cards. From one visible corner, Ranger knows where the card's other corner must be. If that spot lies under another card, the two cards overlap, so they belong together, like a player's hole cards lying one on the other.
- A map of the whole table. As the phone pans, corners are matched from frame to frame by their position and direction and placed on a map of the table, so cards that leave the view are kept.
What's still hard
Each example below is the real pipeline, run on one of our photos.
Occluder reads
Sometimes a corner's suit is completely hidden, and the covering card's own suit symbol sits exactly where the hidden one was. Then the crop really does show another card. Here a J♦ lies over a Q♥, and the jack's diamond sits right where the queen's heart should be:
covered Q♥Q♦︎61%
Q♥︎95%
J♦︎93%
J♦︎92%
Nothing inside the crop can tell this case apart, so the defences have to come from outside it. In the app, a card is only confirmed after several agreeing reads, and a disagreeing read cancels it. The same card can't be on the table twice. A check for a covering card's edge across the index is a candidate for later.
Card faces printed on the felt
Some tables have card designs printed on them. The Spotter finds them, because they are card corners, and the Sniper reads them:
Steep, glare-filled scenes
A low camera angle squashes the far cards, and light from a window can wash them out:
Steep, glare-filled scenes and stylised novelty decks produce most of the remaining misses. More real photos of those is the likely fix.
The broader lesson: much of the gain came from making each network's job simpler and its labels more honest. An OBB gives the Sniper one centred index instead of a crowded square, and labels that say only what can be seen give both networks a consistent job to learn. Together, that's what made zero accepted wrong cards possible.