Skip to main content

Convert an image of Magic cards to decklist

Project description

MTGScan

License: MIT CodeFactor

mtgscan

MTGScan uses OCR recognition to list Magic cards from an image.
After OCR, cards are looked up in a dictionnary provided by MTGJSON (https://mtgjson.com), using fuzzy search with SymSpell (https://github.com/wolfgarbe/SymSpell).

Prerequisites

Installation

poetry install

OCR

Currently, only Azure OCR is supported. To add an OCR, inherit mtgscan.ocr.OCR.

Azure

API subscription key and endpoint must be stored in environment variables AZURE_VISION_KEY and AZURE_VISION_ENDPOINT respectively.
Steps:

(Non-regression) Tests

Every test case is stored in a separated folder in tests/samples/ containing:

  • image.*: image of Magic cards
  • deck.txt: decklist of the cards on the image

To run every test:

poetry run python tests/test.py

This produces the following outputs, for each sample and OCR:

  • statistics about number of cards found, number of errors...
  • test.log: informations about the run
  • errors.txt: history of the number of errors made by the OCR
  • box_texts.txt: output of the OCR

Basic usage

Let's compute the decklist from the following image: alt text

from mtgscan.text import MagicRecognition
from mtgscan.ocr import Azure

azure = Azure()
rec = MagicRecognition()
box_texts = azure.image_to_box_texts("https://pbs.twimg.com/media/ElGwm4bXgAAr7zp?format=jpg&name=large")
deck = rec.box_texts_to_deck(box_texts)
print(deck)

Output:

4 Ancient Tomb
4 Mishra's Factory
4 Mishra's Workshop
1 Strip Mine
1 Tolarian Academy
4 Wasteland
1 Sacrifice
1 Mox Ruby
1 Mox Emerald
1 Mox Jet
1 Mox Pearl
1 Mox Sapphire
1 Black Lotus
1 Mana Crypt
1 Sol Ring
4 Phyrexian Revoker
4 Arcbound Ravager
1 Thorn of Amethyst
4 Sphere of Resistance
4 Foundry Inspector
3 Chief of the Foundry
1 Trinisphere
1 Lodestone Golem
1 Mystic Forge
2 Fleetwheel Cruiser
1 Traxos, Scourge of Kroog
4 Walking Ballista
3 Stonecoil Serpent
1 Chalice of the Void

3 Mindbreak Trap
4 Leyline of the Void
2 Crucible of Worlds
4 Pithing Needle

Features

  • Tested on MTGO, Arena and IRL (simple) images
  • Handle sideboard (only on the right side)
  • Support for stacked cards

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mtgscan-1.0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

mtgscan-1.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mtgscan-1.0.1.tar.gz.

File metadata

  • Download URL: mtgscan-1.0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.4.0-58-generic

File hashes

Hashes for mtgscan-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4d133345b3e027e54a84c9dfd9980debc3161d32de4b25468e9eb6d19c6e33c1
MD5 1a6f9c59040515bb146a95bec502c08f
BLAKE2b-256 ae6b28cc562f00cf31a332261523a9fc53627ad01f17457a820c5fcdeff67d60

See more details on using hashes here.

File details

Details for the file mtgscan-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mtgscan-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Linux/5.4.0-58-generic

File hashes

Hashes for mtgscan-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c1a6faced900c02a36b44474e008e47dc4efbb88186dda7370744183f97012d2
MD5 555fdfa1a84b89064f1a443852164b91
BLAKE2b-256 2857b9f7b704a775c3e73c1d4bd0723407899f70b2b57aa935c77c17a4cdeb77

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page