Michael Portera
Published © GPL3+

Trading Card Scanner/Organizer

Create a digital inventory of your trading/collectible cards using Lego and a Raspberry Pi.

IntermediateFull instructions provided4 hours6,475
Trading Card Scanner/Organizer

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Capacitor 100 µF
Capacitor 100 µF
Optional
×1
Servo (generic)
×1
SparkFun Breadboard Power Supply 5V/3.3V
SparkFun Breadboard Power Supply 5V/3.3V
×1
Lego Medium Creative Brick Box
×1
Camera Module
Raspberry Pi Camera Module
×1

Software apps and online services

Amazon Web Services Rekognition
AWS S3
Amazon Web Services AWS S3

Story

Read more

Schematics

Close Up of Breadboard

Img 0050 a669sbaiiy

Code

MTG_Servo

Python
from PIL import Image
from picamera import PiCamera
import RPi.GPIO as GPIO
import time
import sys

servoPin=18
miniServoPin=24
camera = PiCamera()
set_name = sys.argv[1]

def camera_setup(camera):
	camera.color_effects = (128,128)
	camera.rotation = 90
	camera.resolution = (300,100)


def setup():
	GPIO.setwarnings(False)
	GPIO.setmode(GPIO.BCM)
	GPIO.setup(servoPin,GPIO.OUT)
	GPIO.setup(miniServoPin,GPIO.OUT)

setup()
camera_setup(camera)

servo=GPIO.PWM(servoPin,50)
miniServo=GPIO.PWM(miniServoPin,50)
miniServo.start(2.5)
time.sleep(1)

while True:
	servo.start(2.5)
	time.sleep(1.5)
	servo.stop()
	timestamp=time.strftime("%Y%m%d%H%M%S")
	camera.capture(set_name+"/"+set_name+"_"+timestamp+".jpg")
	print "Picture Taken! See {0}_{1}.jpg!".format(set_name,timestamp)
	miniServo.ChangeDutyCycle(7.5)
	time.sleep(1)
	miniServo.ChangeDutyCycle(2.5)

GPIO.cleanup()

Rekognize_S3

Python
This should be run AFTER we've uploaded our cards to our S3 bucket. The script is looking for a file path containing the images we took, mine being organized by set. It creates an array of the .jpg names and then queries the AWS bucket to get the DetectedText and write it to a file.
import boto3
import sys
import os

card_set = sys.argv[1]
BUCKET = "YOUR_BUCKET_NAME"
card_list = []
oFile=open('OUTPUT_FILE.txt','a')

def get_cards(card_set):
	for i in os.listdir("/YOUR/FILE/PATH/"+card_set):
		card_list.append(i)
	return card_list
		
def detect_labels(bucket, key, region="us-east-1"):
	rekognition = boto3.client("rekognition", region)
	response = rekognition.detect_text(
		Image={
			"S3Object": {
				"Bucket": bucket,
				"Name": key,
			}
		},
		
	)
	return response['TextDetections']


get_cards(card_set)

for i in card_list:
	KEY="{0}/{1}".format(card_set,i)
	rek_response = detect_labels(BUCKET,KEY)
	ftext = rek_response[0]['DetectedText']
	oFile.write("{0},{1},{2}\n".format(i,card_set,ftext))

Credits

Michael Portera

Michael Portera

2 projects • 2 followers
Contact

Comments