2

I'm doing a project where the pi sits inside a box, with the camera pointed to the bottom. When there is an object inside this box, the raspberry pi is supposed to post to facebook every 10 minutes. When the object is taken out, the posts should stop.

I'm not exactly sure how I should tackle this. How does one recognise the presence of an object through the camera, and then use this to trigger a python script?

I have the NOIR camera with the PI zero Thank you for the help!

1
  • I would start by doing a web search for similar questions.
    – joan
    Dec 16, 2017 at 17:49

1 Answer 1

1

Here's a simple way using simple tools (nothing fancy):

Setup:

  • Install the imagemagick package.
  • Once your camera is up and running and mounted in the box, have it take a photo of the empty box.
  • Copy that photo to a file named empty.jpg.
  • Create a CRON job that runs at whatever time interval you choose and does the following:

    1. Takes a photo (we'll call it current.jpg)
    2. Runs a compare between photos using imagemagick like this: compare -metric RMSE empty.jpg current.jpg NULL:
    3. The output of that command will be a numeric value. The bigger that number, the more dissimilar the images are.
    4. If that number is bigger than some amount (you will have to experiment to see what it should be) then someone has placed an item into the box.
    5. If we have an item in the box (based on the image comparison in #4 above) then post it to wherever you need it to go.

There are lots of little (and big) tweaks you could do to make this a really solid process optimized for your needs and timings, but this should give you the general idea.

I hope this helps! Good luck! Come back here and let us know if this helps!

2
  • Would it be possible to take 3 or 4 reference pictures for the empty box? To account for natural lighting conditions ie. Btw, thank you for the answer!
    – tharkimaa
    Dec 17, 2017 at 10:28
  • I was assuming you meant it was actually a "box" (with little to no difference in the lighting inside it over time). I'm not 100% sure how I would go about handling changing conditions. Maybe for lighting that changes, you would have to compare each photo against each of the 3 or 4 "empty" photos each time, and average the differences? I might try that, but I have no idea if it will work for you.
    – MrChips
    Dec 18, 2017 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.