Things used in this project

Parts & Materials:
12994 02
Raspberry Pi Raspberry Pi 1 Model B+
×1
Software apps and online services:
SimpleCV in Python

Schematics

Raspberry Pi and a USB Camera
I used the SimpleCV library to drive the camera
20170310 120042 ldf272zonj

Code

Pi calculator using a camera to take images of a pie.Python
Need SimpleCV installed on Python 2.7.3
from time import sleep
from SimpleCV import *


cam = Camera()
files = []
j=1

#take 5 photos, 2 seconds apart, and same them as jpegs

while j <= 5:
    pie_image = cam.getImage()
    filename="pie_"+str(j)+".jpg"
    pie_image.save(filename)
    files.append(filename)
    j=j+1
    sleep(2)

#find the pie blob in each photo and calculate pi

k=1 
for i in files:        
    img = Image(i)
    segmented = img.hueDistance(Color.BLACK)
    pies = img.invert().findBlobs(minsize=20000)
    
    #Now we print the measurements back on the picture
    for pie in pies:
        pi=pie.area()/pie.radius()**2
        print(round(pi,5))
        text = "Pi:" + str(round(pi,4))
        img.drawText(text, pie.x, pie.y, fontsize=14)
                
    #img.show()
    img.save("pie_pi_w_picalcs_"+str(k)+".jpg")
    k=k+1
    time.sleep(.1)

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login
Community Projects Magazine Maker Faire Shop Share