This script processes images of Pokémon and Magic: The Gathering trading cards, utilizing OCR technology to recognize and rename the cards accordingly. It is designed to work with two separate folders (Pokemon and Magic) and processes images found within their subdirectories, moving processed images to a Processed directory and handling errors by moving problematic images to an Error directory.
- EasyOCR Integration: Uses EasyOCR to extract text from Magic: The Gathering cards.
- OpenAI GPT Integration: Utilizes OpenAI's GPT-4o to identify Pokémon cards based on image input.
- Subdirectory Processing: Processes images in subdirectories, ignoring
ProcessedandErrordirectories. - Error Handling: Logs errors and moves problematic files to an
Errordirectory. - File Preprocessing: Sanitizes filenames to ensure compatibility.
- Python 3.x
- Required Python libraries:
os,cv2(OpenCV),easyocr,requests,logging,re,unicodedata,shutil,base64,json,sys,pathlib
Install the required libraries using pip:
pip install easyocr requests opencv-python-
Create a
tcg.cfgconfiguration file in the root directory with your OpenAI API key:api_key=YOUR_OPENAI_API_KEY
-
Ensure you have the following folder structure:
. ├── tcg.cfg ├── Auto-TCG-Renamer.py ├── Pokemon │ ├── Subfolder1 │ ├── Subfolder2 │ └── ... └── Magic ├── Subfolder1 ├── Subfolder2 └── ... -
Place your Pokémon card images in the appropriate subfolders under the
Pokemondirectory. -
Place your Magic: The Gathering card images in the appropriate subfolders under the
Magicdirectory.
-
Run the script:
python Auto-TCG-Renamer.py
-
The script will start with a "Script is starting up..." message.
-
It will process images found in the
PokemonandMagicsubdirectories. -
Processed images will be moved to a
Processeddirectory under each subfolder. -
If any errors occur, the problematic images will be moved to an
Errordirectory under each subfolder. -
If no new files are detected, the script will display "No new files detected." and exit gracefully.
- The script logs its actions and any errors to
log.txt.
EasyOCR, used to recognize the Magic the Gathering cards in this utility, is vastly sped up by using your GPU if it's supported. Here's how if you're using a recent Nvidia card. This has only been tested on Windows.
- Download and install CUDA Toolkit 11.8
- Downlaod and install cuDNN
-
- Set your PATH directories correctly with the following commands
setx PATH "%PATH%;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp;C:\tools\cuda\bin" setx CUDA_HOME "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8" - Verify that your paths are correct by using the following command on the command line:
nvcc --version - Install the correct version of Torch using the following command:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
If everything is set up correctly, open up a python console and execute the following command:
import torch
print(torch.cuda.is_available())
If this returns True, you can use CUDA now!
- Ensure your API key is correctly set in the
tcg.cfgfile. - Check
log.txtfor any error messages if the script does not behave as expected. - Verify that your images are in the correct subfolders under
PokemonandMagic.
This project is licensed under the MIT License.