Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

match a specific cropped image to a hearthstone card id

Project Description

To use (with caution), simply do:

>>> from hearthstonecarddetector import image_to_card_id
>>> from PIL import Image
>>> with Image.open("test_image_here.ext") as img:
>>>     # if image is not cropped, perform the crop now
>>>     img = img.crop(bbox=(x1, y1, x2, y2))
>>>     card_id = image_to_card_id(img)
>>>     print(card_id)

It’s that simple!

db

The most interesting part of this module is the hashing of all the cards. The hashes are taken of only a certain crop of the card image, a good portion of the artwork. This is explained in “crop_explained.png” and you can see the examples in the tests folder for more help.

Each card was hashed in the four ways provided by the imagehash library. These are average_hash, dhash, phash, and whash. phash is the default algorithm used in this module.

Tests and Examples

Please take a look at the tests directory. You will find several images that are cropped appropriately, in order to match. The TestDetector.py file also contains a working code example.

Please examine the file “crop_explained.png” for information about specific areas to crop. For even more information, you can find the entire collection of cropped images that were used to create these hashes online at https://s3.amazonaws.com/draftwithme/hashed_images/ + CARD_ID .png. For example, the first card is linked at “https://s3.amazonaws.com/draftwithme/hashed_images/AT_001.png”.

Future Work

Ideally, this library should support working with full card images. The problem was that the bottom half of cards are all too similar, so hashing the full image ended up with lots of errors. Focusing on the card artwork has provided a lot of success.

One idea for improvement is to organize the cards by mana (and subsequently by attack / health). Then, parse each of these individually and compare some region to the region previously hashed and indexed.

License

The MIT License (MIT)

Copyright (c) 2016 Tristan Kernan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release History

Release History

This version
History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
hearthstonecarddetector-0.1.4.zip (301.8 kB) Copy SHA256 Checksum SHA256 Source Aug 18, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting