Pokemon TCG Card Recognizer
Project description
Pokemon Card Recognizer
Recognize a Pokémon Card in an image or video.
from pokemon_card_recognizer.api.card_recognizer import CardRecognizer, OperatingMode
# init and set output paths
recognizer = CardRecognizer(
mode=OperatingMode.PULLS_VIDEO
)
recognizer.set_summary_file(summary_file="summary.txt")
recognizer.set_output_path(output_path="out_figs")
# run recognizer on video and visualize results
pulls = recognizer.exec("/path/to/video")
recognizer.vis()
Example analysis of a booster pack opening video:
Benchmarks: https://docs.google.com/presentation/d/1Q6PzJpqyyLFvtkLGoCFeXaHYOauOzeF_umx8V3w4fV8/edit?usp=sharing
Installation:
make conda_dev
conda activate card_rec_env
pip install pokemon-card-recognizer
Note that the CardRecognizer works MUCH (~5x-10x) faster on NVIDIA GPU, so it is highly recommended that you have CUDA. If CUDA is available, the CardRecognizer will automatically use it. Otherwise, the CardRecognizer will default to CPU which is substantially slower and not recommended for batch processing.
If processing video files, you may also need to download and install FFMPEG (https://ffmpeg.org/) which is used to uncompress videos into image frames.
On linux:
sudo apt update
sudo apt install ffmpeg
Optional: The default OCR backend used by CardRecognizer is easy_ocr which is installed via the conda, but if you choose to use PyTesseract instead, you will need to install it:
sudo apt install tesseract-ocr
sudo apt install libtesseract-dev
Example Usage to Recognize a Card in a Single Image:
from pokemon_card_recognizer.api.card_recognizer import CardRecognizer, OperatingMode
recognizer = CardRecognizer(
mode=OperatingMode.SINGLE_IMAGE,
set_name="master"
)
pred_result = recognizer.exec("/path/to/image")
detected_card = recognizer.classifier.reference.lookup_card_prediction(
card_prediction=pred_result[0]
)
print(detected_card.set)
print(detected_card.name)
print(detected_card.number)
Useful Operating Modes for CardRecognizer:
# process a single image
OperatingMode.SINGLE_IMAGE
# process a directory of images
OperatingMode.IMAGE_DIR
# process a video file
OperatingMode.VIDEO
# process a video file where cards are being shown ("pulled") sequentially
(no assumption on # of cards shown in the video)
OperatingMode.PULLS_VIDEO
# process a video file where cards are being shown sequentially,
# coming from a booster pack (assumes 11 cards are being shown in the video and
# finds the best statistical estimation of at most 11 most likely shown cards).
OperatingMode.BOOSTER_PULLS_VIDEO
Card Reference Sets
Note that you can change "set_name" in the CardRecognizer constructor to whatever specific set reference (e.g. "base1", "jungle", etc) you want. For list of supported reference sets, view
from pokemon_card_recognizer.reference.core.build import ReferenceBuild
print(ReferenceBuild.supported_card_sets())
Building Card Reference:
The pypi package and GitHub source for pokemon-card-recognizer comes bundled with pre-rebuilt references for all major Pokémon card sets. It is recommended to use the pre-built references. If however, you want to rebuild the reference for some reason, you can do:
python pokemon_card_recognizer/reference/core/build.py [PTCGSDK_API_KEY]
where PTCGSDK_API_KEY
is your PTCGSDK API key. You can get one here: https://pokemontcg.io/.
Note that building and evaluating the reference can take an hour or more, depending on your system configuration. It is recommended to use the prebuilt card references that come pre-bundled.
*This API is unofficial, open-source, in development, and not affiliated with the Pokémon Company.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pokemon_card_recognizer-0.0.1.3.8.6.tar.gz
.
File metadata
- Download URL: pokemon_card_recognizer-0.0.1.3.8.6.tar.gz
- Upload date:
- Size: 18.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b43b696075f09ad984b1610d62a74009c2aa6b4302a6d33ecc8a7fd99da7101 |
|
MD5 | ffe9c93c4727b062c1510105fce96675 |
|
BLAKE2b-256 | fe8ef50eac52cdb735bb09fd6f01240412c19c89a771f7c2b29a9083bcfb5934 |
File details
Details for the file pokemon_card_recognizer-0.0.1.3.8.6-py3-none-any.whl
.
File metadata
- Download URL: pokemon_card_recognizer-0.0.1.3.8.6-py3-none-any.whl
- Upload date:
- Size: 18.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.26.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1fe0ba3b91fc171430fcf51fcfbd7c875867cde276f3f6f8a5fca0a3757c6d4 |
|
MD5 | eafa2871cefad26d6558ef665317903c |
|
BLAKE2b-256 | 0f068ca8723d1a0e84e7d558b808e938a2de7435544966214ad84b99b0b62c1d |