Things used in this project
"Make:'s Magically Mathematical Pi Day Contest" inspired me to create my first online maker project. I've attended three Maker Faires, and I'm an avid Maker, so I decided it was time to get more involved.
What better way to celebrate Pi Day and enter the Pi contest than to make a circular Cherry Pie, and then use a Raspberry Pi with connected camera to calculate Pi based on image analysis of the Cherry Pie. The computer vision software recognized the Cherry Pie and figured out its area and radius in pixels. Then I wrote some code to back-calculate Pi using the equation for the area of a circle, i.e. Area=Pi*Radius**2. With Area and Radius obtained by image analysis of the Cherry Pie, the Raspberry Pi then calculated Pi=Area/Radius**2 using Python software.
I made the cherry pie using my "Super Easy No Bake Cherry Pie" recipe! The first step is to buy a graham cracker crust. Then mix one bar of cream cheese with a half tub of cool whip and half a cup of powdered sugar. Put that in the crust and then cover with cherry pie filling. It takes about 15 minutes. See photos below.
The technology portion of this project involves using a Raspberry Pi for computer vision. There's a great package called SimpleCV that does cool stuff like recognize blobs in an image. So I connected a USB Camera to my Raspberry Pi and mounted it on a tripod above the cherry pie. After centering the image, I ran my program which captured some images, pulled out the image blob of the cherry pie, and calculated Pi. By the way, "blobs" is a real technical term in image processing.
My result was Pi=3.12 based on an average over five images. I was hoping for something closer to 3.14, but less than 1% error isn't too bad considering that I didn't work on calculating Pi for hundreds of years like the ancient Greeks did.
Lastly, the cherry pie was a big hit for dessert!
Pi calculator using a camera to take images of a pie.Python
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)
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!