element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Free Food Camera
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oneleggedredcow
  • Date Created: 14 Jan 2014 1:49 AM Date Created
  • Views 637 views
  • Likes 0 likes
  • Comments 3 comments
Related
Recommended

Free Food Camera

oneleggedredcow
oneleggedredcow
14 Jan 2014

At work, there always seem to be one table where the free food is placed.  The leftovers from catered meals, extra cookies that someone had laying around, or other various goodies are placed here for the lucky first couple of people who walk by to eat.  If you don’t come fast enough, there will be no food left for you.

 

What if you had a way to detect when new food appeared, without walking over to the table> Then (in theory at least) you would never miss any food!  That’s exactly what this Raspberry Pi –based system does.  Every 5 seconds an image is taken of the table.  The image is posted to a website and then it is filtered to only contain the table (to reduce the noise).  Then the image is compared with a previous image to determine if anything new appeared.  If new food is detected, then an email alert is sent, along with a picture of the table, so that you can make sure the food is something good and not some rotten vegetables.  The website also has a place to register your interest for email alerts.

 

Taking Pictures

 

Hooking up the camera to the Raspberry Pi is really easy and there are plenty of great resources to get you up and running:

 

http://www.raspberrypi.org/camera

 

Taking a picture is really easy with the raspistill command:

 

raspistill -o image.jpg

 

For this, we are going to be taking smaller images, so that the processing goes faster.  Here’s the command to do that:

 

raspistill -h 1024 -w 1024 -o image.jpg

 

Filtering and Comparing Images

 

To limit the amount of false alarms, we are going to mount the camera directly above the table in question.

image

Also, since the table at work is round, I’m going to implement a filter to remove all parts of the image that are not the table.  This will help reduce the false positives of people walking by the table. To do the filtering, I’m going to use ImageMagick, so to install that:

 

sudo apt-get install imagemagick

 

So, now we can take our original image of the table:

image

And filter out everything but the table:

 

convert -size 1024x1024 xc:none -fill image.jpg -draw “circle 512,512 512,1” filtered.jpg

 

Which leaves us with:

image

Now, we can use ImageMagick to detect if there are changes in the image:

 

compare -metric PSNR baseline.jpg filtered.jpg diff.jpg

 

This will return a number that we can use to detect whether or not a change has occurred in the image. If the SNR is less than a given threshold, then we say that a change has occurred in the image.

 

E-mailing Detected Food

 

Once we have determine that there was a change in the image, we can send out an email notification with python.  Here’s a good description of how to do that:

 

http://docs.python.org/2/library/email-examples.html

 

Here’s the python code to send an email with an attachment:

 

me = 'breakroom'

 

msg = MIMEMultipart()

msg['Subject'] = 'Food In the Break Room'

msg['From'] = me

                              

with open('tmp.jpg', 'rb') as file:

img = MIMEImage(file.read())

msg.attach(img)

 

server = smtplib.SMTP('smtp.gmail.com:587')

server.ehlo()

server.starttls()

server.login(<email address>, <password>)

                              

for email in self.emails:

print "email sent to: " + email

msg['To'] = email

server.sendmail(me, email, msg.as_string())

                              

server.quit

 

Web Site

 

The last thing that I did was create a web site that displays the current image of the table. This way I can check in on the Raspberry Pi to make sure that everything is working correctly.  I used the tornado web socket library so that I could update the client from the server every time a new image was taken.  Here’s what the web site looks like:

image

The code is attached to the article, in case you are interested about the web site.

 

Summary

 

I created a simple and easy way to monitor the free food table in the break room, so that I will never miss out on cookies again.  When new food is detected, I am sent an email of the image of the food, so that I can sprint over there and reap the rewards.  There is also a website, so that I can check in and make sure that everything looks like it is working correctly.

Attachments:
camera.zip
  • Sign in to reply
  • oneleggedredcow
    oneleggedredcow over 11 years ago in reply to Robert Peter Oakes

    That's awesome!  I had no idea.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Robert Peter Oakes
    Robert Peter Oakes over 11 years ago

    And ill raise you that story, I remember it well, when it first was put online in the early 1990's

     

    http://gizmodo.com/5993583/the-worlds-first-webcam-was-created-to-check-a-coffee-pot-remotely

     

    Enjoy

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelwylie
    michaelwylie over 11 years ago

    Necessity is the mother of invention? This is very reminiscent of the story of the webcam. Nice job.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube