How to do Raspberry Pi Zero Surveillance with Ruby

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@inertia·
0.000 HBD
How to do Raspberry Pi Zero Surveillance with Ruby
I've had my [Raspberry Pi Zero](https://www.raspberrypi.org/products/raspberry-pi-zero/) for over a month, all powered and connected with its camera ready to go, but I had a problem positioning the camera because the ribbon cable I had was too short.  So I finally got the extended ribbon cable and mounted it properly today.  Prior to this, I was able to capture stills and also do broadcasts on YouTube (private feed).  This was helpful to get it focused and pointing where I wanted it.

![](https://steemitimages.com/DQmYrXhQ1deftW5EaJurSrbS8UNyjQMvLSGVcNt13k5MbYq/image.png)

But what I really wanted was a way to capture an image and compare it to the previous image so that it could send it off to Dropbox only when there was a significant change.  Here are the scripts I'm using:

`Gemfile`

```ruby
source 'https://rubygems.org'

gem 'phashion'
```

`camera.sh`

```bash
#!/bin/bash

DATE=$(date +"%Y-%m-%d_%H%M%S")

raspistill --rotation 90 -q 10 -w 640 -h 480 -o $HOME/stills/$DATE.jpg
echo $DATE
```

`find_non_dupe.rb`

```ruby
require 'rubygems'
require 'bundler/setup'

Bundler.require

now = Time.now
one_minute_ago = now - 60
pattern1 = one_minute_ago.strftime('%Y-%m-%d_%H%M')
pattern2 = now.strftime('%Y-%m-%d_%H%M')
files = Dir.glob("~/stills/#{pattern1}*.jpg")
files += Dir.glob("~/stills/#{pattern2}*.jpg")
last_img = nil
unique_dir = '~/unique'

files.each do |f|
  if File.exist?(File.join(unique_dir, File.basename(f)))
    puts "Skipping: #{f}"
    next
  end

  this_img = Phashion::Image.new f

  if !!last_img &&
    if this_img.duplicate? last_img
      puts "Duplicate: #{f}"
    else
      puts "Non duplicate: #{f}"
      FileUtils.cp f, unique_dir
    end
  end

  last_img = this_img
end
```

Then I use [Dropbox-Uploader](https://github.com/andreafabrizi/Dropbox-Uploader) to send only the changes.  Here's what it can capture and upload to Dropbox:

![](https://steemitimages.com/DQmQgDUDmFmZCAcaXDxvDJzc4MJHfovhywUY38NYdyNRzrV/image.png)

---

**Update:** Here's how I mounted it.

![2018-01-28 10.04.03.jpg](https://steemitimages.com/DQmWcvCj1CGtv42ZpCwaGzdVgm8oNGLhEhJEi4AxZaJSpXr/2018-01-28%2010.04.03.jpg)
![](https://steemitimages.com/DQmUzFv2wYMFexUMF9moQjC8HNUeWp466MwcemRtTpNn7f9/image.png)<div class="chainbb-footer"><hr><em><small><a href="https://chainbb.com/ruby/@inertia/how-to-do-raspberry-pi-zero-surveillance-with-ruby">Originally posted</a> in the <a href="https://chainbb.com/f/ruby">/f/ruby</a> forum on <a href="https://chainbb.com">chainBB.com</a> (<a href="https://chainbb.com/chainbb/@jesta/chainbb-frequently-asked-questions-faq">learn more</a>).</small></em></div>
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,