Skip to content

chrismeyersfsu/python-card_scan

Repository files navigation

Table of Contents

Credit

Code mostly taken from card_scan by YenTheFirst. Chose not fork because of the amount of code change.

Overview

Magic the Gathering card recognition for purposes of quickly digitizing your inventory.

Features

  • Uses image recognition software opencv to quickly identify Magic the Gathering Cards
  • Outputs recognized cards in Magic Workstation csv format
  • Says the name of the card using Text-to-Speech festival
  • Runs in real-time

Screenshots

Dependency

  • a camera
  • python, opencv, numpy, SQLAlchemy, Flask, elixer
sudo apt-get install python-opencv
sudo pip install -r requirements.txt
  • festival
sudo apt-get install festival

MTG Set Images

apt-get install wine
unzip GathererDownloader*.zip

Setup

One variable is required to be set that denotes the location of the Magic the Gathering cards you wish to index against.

BASE_SET_DIR/
variable in test.py root directory of the images.

MTG Set Images

The matching algorithm is designed to find a matching card of a taken image. Thus, we need a database of cards to match against.

File Structure

BASE_SET_DIR/
variable in test.py root directory of the images.
BASE_SET_DIR/<set_name_abbreviation>
where set_name_abbreviation is a unique identifier for the set comprised of letters and numbers.
BASE_SET_DIR/<set_name_abbreviation>/<card_name>.full.jpg
where card_name is unique within a given set. Note that all the cards end in full.jpg

Gatherer Downloader

Automates downloading of full Magic the Gathering sets, both card listings and card images.


Start it

wine ./GathererDownloader.exe

Download the card database for the sets you wish to recognize/inventory. Note the "And all Sets After" option box for easily downloading multiple sets.

Now we will get the images associated with the cards but first, because we have a particular file directory structure, we need to ensure the naming convention is correct.

Click on Options -> Image Formats. Select Magic Workstation from the dropdown box and click Load Defaults. Then click Ok to save.

Click Download Card Images and select the directory you have set BASE_SET_DIR.

Running

./test.py
Note that matches cards are appended to the csv file configured via CSV_FILE in the file test.py

Controls

Note that the background should be a solid color. I used a piece of white printer paper.

  • r
    refresh the background
  • b
    save found match to csv database

Common Problems

test.py invalid camera.

OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 1238
Traceback (most recent call last):
  File "./test.py", line 87, in <module>
    capture = scanCard.check_for_card()
  File "/home/meyers/Dropbox/Code/python_card_scan/scan_card.py", line 173, in check_for_card
    self.grab_frame()
  File "/home/meyers/Dropbox/Code/python_card_scan/scan_card.py", line 119, in grab_frame
    frame_gray = to_gray_image(frame)
  File "/home/meyers/Dropbox/Code/python_card_scan/cv_utils.py", line 73, in to_gray_image
    gray = create_dummy_image(img)
  File "/home/meyers/Dropbox/Code/python_card_scan/cv_utils.py", line 65, in create_dummy_image
    return cv.CreateImage(cv.GetSize(img), 8,1)
cv2.error: Array should be CvMat or IplImage

Adding new magic sets and cards to the database to match against may require deleting the analyzed cache SET_CACHE_FILE in test.py

About

Playing card scanner and matcher, image recognition, opencv

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published