← writing

Detecting playing cards without a neural net

Contours, perspective warps and ORB features — how far classic computer vision gets you before deep learning.

Recognizing playing cards from a webcam sounds like a job for a trained model. It isn’t — at least not at first. Classic computer vision handles it cleanly, and the exercise is a great reminder of how much you can do before reaching for a GPU.

Detection before recognition

The pipeline splits in two. First, find card-shaped quadrilaterals with contour analysis and warp each one flat with a perspective transform. Only then do you ask what card it is — matching the flattened image against a template set with ORB features, which are rotation-tolerant and license-free.

# flatten the card, then match it
warped = cv2.warpPerspective(frame, M, (W, H))
kp, des = orb.detectAndCompute(warped, None)
matches = bf.match(des, template_des)

Almost all the accuracy is won in preprocessing. Get the contour and warp stages right and recognition becomes easy; get them wrong and no clever matcher saves you.

Why bother

Because understanding the classic pipeline makes you better at the modern one. You learn what the hard parts actually are — lighting, occlusion, perspective — instead of hoping a model absorbs them for you.