B4J Question Help Needed: Creating a Program to Recognize Playing Cards

jroriz

Active Member
Licensed User
Longtime User
Hello everyone,

I’m working on a program that can recognize playing cards from an image. The cards will always have the same design, but they can appear in different positions on the screen and may vary in size depending on the window size. The goal is to select a specific area of the screen where the cards will be displayed, and the program should be able to identify between 2 to 6 cards in that area.

I’ve already attempted this using OCR by capturing the text on the card and identifying the suit based on color. However, OCR tends to fail frequently, especially at lower resolutions.

To improve accuracy, I plan to use a template-matching approach, where I have a reference image (template) for each card. The program will compare the captured image with these templates to identify the cards.

Key Points:
- The cards will always have the same design.
- Cards can appear in different positions and sizes within a selected screen area.
- The number of cards can range from 2 to 6.
- OCR has been unreliable, particularly at lower resolutions.
- I will use a template-matching approach with a reference image for each card.

Questions:
1. What would be the best approach to implement template matching in this scenario?
2. Are there any specific libraries or tools (e.g., OpenCV) that you would recommend for this task?
3. How can I handle variations in card size and position effectively?
4. Are there any alternative methods to OCR and template matching that could improve accuracy?

Any advice, code snippets, or resources would be greatly appreciated!

Thank you in advance for your help!

Sample cads will go like this:

1738549039219.png
 

emexes

Expert
Licensed User
Longtime User
I feel like we did this a few years back. Hang on a sec...

Maybe also check out:

 
Upvote 0

emexes

Expert
Licensed User
Longtime User
The cards will always have the same design, but they can appear in different positions on the screen and may vary in size depending on the window size.

Are any cards rotated at all, by any amount other than orthogonal?

Can you always see the whole entire card? (no overlapping)

Any chance of some screen shots of typical scenes and sizes?
(ideally including all associated clutter but no problem if you redact your multimillion poker account balance 😇)
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
The card images that you supplied all have a distinctive three-pixel grey boomerang at their bottom-right corner. If a clue like that is always present, then finding cards on screen should be no problem.

1738564892369.png
 
Upvote 0

emexes

Expert
Licensed User
Longtime User
Any progress?

Still interested to see full screenshots of the cards in play. Ideally as PNG so nothing lost to compression.
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
Any progress?

Still interested to see full screenshots of the cards in play. Ideally as PNG so nothing lost to compression.
Hello, thanks for your interest! I'm spending some time at the hospital, but it's nothing serious. See you soon with the cards...
 
Upvote 0
Top