Sean Kelly
Sean Kelly

Reputation: 143

Template Matching in Playing Cards

I'm attempting to take images of playing cards and extract information about them using some form of template matching. To start off I've been using Gaussian blurring, gray scale conversion and then thresholding to create a binarised image, and they've been pretty effective at isolating the card as the only real details in the images:

https://i.sstatic.net/cjtym.jpg

However before proceeding to the next step (hopefully using OpenCV's template matching stuff) I was struggling with two things: firstly, do these images need more processing before template matching? For instance, do I need to be looking into accounting for the scale and orientation of the cards? Quick note: the template I was intending to use was the corner of the card with the rank and suit (it's in the link above). I conceptually understand that you can potentially select the entire area by finding the four corner with the internal angles, but I'm pretty clueless on how to implement that. Secondly: is there a particular template matching algorithm that would be best for this type of work? I'd rather do some more processing prior to template matching rather than brute force matching with multiple types of the same image (rotated and scaled to account for the differences in each photo).

So summary: do I need to do some more processing for scale and orientation before matching (and if so, suggested algorithms?), and what template matching algorithm would be the best approach for this problem?

I think the ideal solution is finding the entire card and forming a separate image where it is scaled and positioned for template matching and then using a matching algorithm, but I'm not sure that's even possible! Any help is most appreciated.

Upvotes: 1

Views: 1354

Answers (1)

Photon
Photon

Reputation: 3222

If you're working with a specific set of cards, then all you need to do (assuming the cards do not overlap), is to find the contours (http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html) of the cards, map the inverse perspective transform to get a straight card image, and then use your template matching.

If, however, you want to be more robust to deck changes, you may also need to detect the inner contours of the numbers / letters / suit shapes, and recognize those to classify the card.

Upvotes: 1

Related Questions