Image

Slice It:

Description:

Our final testing for Slice It! took place last week to great success. After receiving feedback from our prototype stage, we aimed at implementing a new design and new features into our toy. For the final product, we managed to create a box that would image process the pieces placed on the game pad and then check to see if it correct. The focus of our product was to create a game that would help enrich the learning experience of elementary school kids in learning and experiencing fractions.

The actual game is a direct program python scrip on the raspberry pi that an individual would need to run. Inside the hardware is the rasperry pi which is connected to the camera. The camera lies below the game pad and allows it to take a picture when commanded to do so. We also have a button actuation for the camera to snap a photo when the user is ready to place answer from the game pad.

Image Image Image Image Image

Code for Level II:

from SimpleCV import *
from time import sleep
import os
from random import shuffle
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(15,GPIO.OUT)
GPIO.output(15,0)

center = [385,325]

mainScreen = Image("Title Screen.jpg")
mainScreen.show()

try:
    while not GPIO.input(11):
        sleep(0.01)
except KeyboardInterrupt:
    GPIO.cleanup()

sleep(2)
piCam = Camera()
disp = Display((640,480))
fracFiles = [os.path.abspath('JPGS/' + x) for x in os.listdir('JPGS')]
fracFiles.sort()
fracVals = [0.5, 0.33, 0.25, 0.125]

fracIndex = range(0,len(fracVals))
shuffle(fracIndex)

for i in fracIndex:
    fraction = Image(fracFiles[i])
    fraction = fraction.scale(1.2)
    fraction.show()
    try:
        while not GPIO.input(11):
            sleep(0.01)
    except KeyboardInterrupt:
        GPIO.cleanup()

    fracPic = piCam.getImage()
    cropPic = fracPic.crop(385,325,400,400,centered=True)
    blobs = cropPic.findBlobs()
    blobs.draw(width=-1,color=Color.RED)
    area = blobs.area()
    maxArea = max(area)
    print(maxArea)
    totalArea = 139000
    areaCovered =1-(maxArea/totalArea)
    print(areaCovered)

    takeClosest = lambda num, collection:min(collection,key=lambda x:abs(x-num))
    estVal = takeClosest(areaCovered,fracVals)
    print(estVal)

    if estVal == fracVals[i]:
        print("Congrats!")
    else:
        print("Sorry!")
        

Code for Level II:

from SimpleCV import *
from time import sleep
import os
from random import shuffle
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
center = [385,325]

mainScreen = Image("Title Screen.jpg")
mainScreen.show()
sleep(5)
piCam = Camera()
disp = Display((640,480))
fracFiles = [os.path.abspath('Mode2/' + x) for x in os.listdir('Mode2')]
fracFiles.sort()
fracVals = [0.5, 0.33, 0.25, 0.125, 0.66, 0.25, 0.75, 0.5]

fracIndex = range(0,len(fracVals))
shuffle(fracIndex)

for i in fracIndex:
    fraction = Image(fracFiles[i])
    fraction = fraction.scale(0.5)
    fraction.show()
    try:
        while not GPIO.input(11):
            sleep(0.01)
    except KeyboardInterrupt:
        GPIO.cleanup()

    fracPic = piCam.getImage().binarize()
    cropPic = fracPic.crop(385,325,400,400,centered=True)
    blobs = cropPic.findBlobs()
    blobs.draw(width=-1,color=Color.RED)
    area = blobs.area()
    maxArea = max(area)
    print(maxArea)
    totalArea = 139000
    areaCovered =1-(maxArea/totalArea)
    print(areaCovered)
    takeClosest = lambda num, collection:min(collection,key=lambda x:abs(x-num))
    estVal = takeClosest(areaCovered,fracVals)
    print(estVal)

    if estVal == fracVals[i]:
        print("Cool!")
    else:
        print("Sorry")