Playing card scanner and matcher, image recognition, opencv
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
data blank inventory file Jul 19, 2013
doc/screenshots/gatherer_downloader screenshots Jul 19, 2013
misc/magic_assistant_format misc things, might remove them Jul 19, 2013
.gitignore Initial commit Jul 19, 2013
LICENSE Initial commit Jul 19, 2013
README.mediawiki changed Run to Runnning in readme Jul 19, 2013 init Jul 19, 2013 init Jul 19, 2013 init Jul 19, 2013
requirements.txt init Jul 19, 2013 init Jul 19, 2013 init Jul 19, 2013


Table of Contents


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


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


  • 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



  • 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


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

variable in 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

variable in root directory of the images.
where set_name_abbreviation is a unique identifier for the set comprised of letters and numbers.
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.


Note that matches cards are appended to the csv file configured via CSV_FILE in the file


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 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 "./", line 87, in <module>
    capture = scanCard.check_for_card()
  File "/home/meyers/Dropbox/Code/python_card_scan/", line 173, in check_for_card
  File "/home/meyers/Dropbox/Code/python_card_scan/", line 119, in grab_frame
    frame_gray = to_gray_image(frame)
  File "/home/meyers/Dropbox/Code/python_card_scan/", line 73, in to_gray_image
    gray = create_dummy_image(img)
  File "/home/meyers/Dropbox/Code/python_card_scan/", 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