The MagPi - July 2018

(Steven Felgate) #1

raspberrypi.org/magpi July 2018 35


Michael used the free
tier of Amazon’s object
storage service S3
(aws.amazon.com/s3),
which allows 2000 images
to be uploaded each month

TRADING CARD SCANNER/ORGANISER Projects


>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-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-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.

TRADING TIME


FOR CREATIVITY


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.”


Box of bricks
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 (magpi.cc/sfLJLE),
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 TCGPlayer.com’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.”

The idea was to make light


work of organising and valuing


even the largest of collections

Free download pdf