https://github.com/leoraclet/playing-cards-identification
๐๏ธ Playing card identification sytem using MATLAB / Octave scripting language.
https://github.com/leoraclet/playing-cards-identification
cards identification image-processing image-recognition matlab matlab-script octave octave-scripts
Last synced: about 1 month ago
JSON representation
๐๏ธ Playing card identification sytem using MATLAB / Octave scripting language.
- Host: GitHub
- URL: https://github.com/leoraclet/playing-cards-identification
- Owner: leoraclet
- License: mit
- Created: 2026-01-11T00:08:20.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-01-12T03:32:44.000Z (5 months ago)
- Last Synced: 2026-05-02T23:48:58.076Z (about 1 month ago)
- Topics: cards, identification, image-processing, image-recognition, matlab, matlab-script, octave, octave-scripts
- Language: MATLAB
- Homepage:
- Size: 953 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Playing Card Identification
This project implements a **playing card identification system** using **MATLAB/Octave**. It leverages standard image processing techniques and algorithms to extract key information, including:
- Number of cards
- Card values
- Card positions (*used to display their value at the end*)
## ๐ฆ Project Structure
```text
โโโ assets/ # Illustrations of the process
โโโ src/ # Functions and main program
| โโโ samples # Sample images
โโโ flake.nix # Nix environment
```
> [!important]
> Currently, the code is extensively commented **only in French**.
>
> English translations will be added in the future.
## โ๏ธ How It Works
The playing card identification process follows these steps:
1. **Image Loading and Grayscale Conversion**
The input image is loaded and converted to grayscale.
2. **Thresholding**
A threshold is applied to create a binary (black and white) image, distinguishing the cards from the background.
3. **Dilation**
Successive dilation operations are applied to fill the cards completely.
4. **Card Segmentation**
A 3-pass segmentation process identifies the number of cards and their positions, assigning unique pixel values to each card.
5. **Design Extraction**
The inverse of the thresholded image is taken to isolate the card designs. Refining this image with dilation and erosion operations preserves only the interior designs of the cards.
6. **Symbol Segmentation**
The designs are segmented to isolate individual symbols.
7. **Symbol-to-Card Association**
The barycenter (center of mass) of each symbol is calculated. Using the segmented card image (from step 4), each symbol is associated with its respective card based on the barycenter's location.
8. **Card Value Determination**
The number of symbols per card is counted, determining the card values.
9. **Result Visualization**
The barycenter of each card (from step 4) is used to overlay text on the image, displaying the card values and producing the final result.
### Steps Summary
Below are the steps illustrated with images from each stage of the image processing pipeline.
| Step 1 - Grey image | Step 2 - Black and White image |
| :---------------------------------: | :-------------------------------------: |
|  |  |
| **Step 3 - Dilated cards** | **Step 4 - Segmented cards** |
|  |  |
| **Step 5 - Dilated designs** | **Step 6 - Segmented designs** |
|  |  |
| **Result** | **Original image** |
|  |  |
## ๐ง Limits
This image processing approach is designed to work only for cards with values from **1 (Ace) to 10**. High-rank cards (King, Queen, Jack) have more complex designs that do not directly correspond to their numerical value, so they are not supported by this method.
## ๐งช Testing the Project
Begin by cloning the repository and navigating into the project directory:
```bash
git clone https://github.com/leoraclet/playing-cards-identification
cd playing-cards-identification
```
### ๐ฅ Installation
Ensure [Octave](https://octave.org/download) is installed on your system.
#### Nix Users
If you use the Nix package manager with `direnv`, enable the environment by running:
```bash
direnv allow
```
### โ
Running the Pipeline
1. Launch Octave:
```bash
octave
```
2. Install the required `image` package and execute the main script:
```bash
pkg install image
run src/Traitement.m
```
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.