Trading Card Scanner/Organiser

By Lucy Hattersley. Posted

For his next trick, Michael Portera created a system out of LEGO to recognise, organise, and value his vast collection of Magic: The Gathering trading cards. David Crookes investigates

When Michael Portera came across a few boxes packed with trading cards – “everything from football, baseball, and basketball to Magic: The Gathering (MTG)” – one of his first thoughts was how much the collection might be worth. As someone who had dabbled with MTG by buying booster packs and playing the occasional game with friends, he knew there was a large secondary market and that he had cards worth investigating.

“But looking up the cards manually would have taken a while, even using online scanners or apps,” he muses. “So I wanted to develop an automated process using a card feeder and a scanner for image processing.”

Motivated by the potential time saved, he quickly got to work. The spell-binding result was a Trading Card scanner made of LEGO, servo motors, a camera, and a Raspberry Pi 3.

Trading Card Scanner: using AI to count cards

Right from the start, Michael envisaged a simple system that would spin and push preloaded cards forward to be photographed and uploaded for digital storage and processing. The idea was to make light work of organising and valuing even the largest of collections. Building it, however, was largely a process of trial and error.

“I had a cheap card shuffler lying around,” recalls Michael. “After taking it apart, I found the simple cog system powered by a DC motor that moves the hammer and pushes one card forward into a slot, creating a new stack of cards. This would be the inspiration for the servo and wheels needed to accomplish the automation.”

Trading Card Scanner

Use LEGO to build a card scanner

Michael turned to LEGO for the main structure due to its versatility. It allowed him to easily build, modify, and tear down his project. He placed servos in the back of the build and had them spin continuously. Carefully positioned LEGO tyres then move forward in a cog-like setup to get the cards into position.

Once the device was built and he was happy, Michael could then start coding, which he says was the easiest part of the build. He used Python 2.7 to program a script to power both the servos and take a picture via a Raspberry Pi Camera Module. He then wrote another script to send the images to Amazon’s cloud computing web service S3, for storage and to tackle image processing.

“I originally tried Tesseract and OpenCV for optical character recognition, but I spent a lot of time trying to get so many variables perfect and I couldn’t get consistency,” he explains. To fix this, he turned to Amazon’s deep learning-based image analyser, Rekognition, which extracts text and indexes a collection. “It works well. I did not have to worry about getting the angle just right, making sure the lighting was perfect, or performing any machine learning – it worked despite all of those factors.”

Apart from issues deciphering some fonts, it performed well: 619 of the 920 cards scanned perfectly and he was able to feed the data through’s price data API to determine the value of each card and, therefore, his MTG collection. “I had about $275 worth of commons, uncommons, and rares,” he says, pleased as punch. “And through trial and error, I also learned a lot along the way.”

Step-01 Insert the cards

Load your cards into the LEGO device and run a script on the Raspberry Pi to move the rear servos and allow a single card to get into position. A front wheel stops the other cards slipping.

Step 1: Trading Card Scanner

Step-02 Snap an image

Once the card is in the scanning area, a Raspberry Pi Camera Module – carefully angled and sitting on a stack of bricks mere inches away – captures the top part of the card. Stop the script.

Step 2: Trading Card Scanner

Step-03 Performing the action

Drag and drop the scanned card files into Amazon S3’s online interface via the Pi. Run another script to get Rekognition to analyse the images and look up the market price.

Step 3: Trading Card Scanner

From The MagPi store