How to do Raspberry Pi Zero Surveillance with Ruby
I've had my 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.
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
source 'https://rubygems.org'
gem 'phashion'
camera.sh
#!/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
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 to send only the changes. Here's what it can capture and upload to Dropbox:
Update: Here's how I mounted it.
Gyah, this reminds me. I really need to quit letting my pi3 rot away on a shelf. I AM ASHAMED OF MYSELF. It just sits there with retropie slapped on it, wasting away.
At least power it up and run
mosh
+tmux
so you have shell sessions with years of uptime.The only reason that pi reboots is because I crash it from running too many blockchain streams. :D
hah dont worry matt, your raspberry pi is just lucky to get to know you
That rasberry pi had an opportunity to hold a few million bitcoin LOL
You once had millions of BTC man, its so col, you could have been a billionaire today :D hah i love it! imagine!
There are many tools out there, just takes a bit of looking. Someone might be wondering how this relates to Raspberry Pi,That's how this relates to Pi.
Good point. I didn't really explain how this was specific to the raspberry pi.
There are a bunch of off-the-shelf solutions, but they are overkill if you're looking to do it yourself. Many of the "turn-key" products send an HD stream with audio to a server, which utilizes a bunch of bandwidth. I don't really like that idea, even if my internet wasn't metered.
These scripts are optimized for the pi zero hardware. Instead of capturing a 4MB image by default, which takes 30 seconds to compare, this solution captures a 150k image. That way I can get it to compare images once every 3 seconds or so.
You just had to post details. I have wanted a camera (or two) around here for ages. We had a shooting about 500 yards from our back door a few months ago while my son was standing outside. You could say the neighborhood is not ideal.
I also like the idea of using one as an ad blocker using pi-hole . Tom was telling me he runs it with great success. Incidentally, he was here to help my brother move...he flew over from England....to help him move. Crazy Brit.
You really can get away with mounting one of these to the side of a wall:
But then you have to wire it with a 5 volt power supply somehow. I got away with just mounting it inside a vent so that the actual pi is inside the garage and the camera its just clipped to the housing.
You can go overboard with a case that costs more than the pi itself:
I kinda like this guy's solution:
I like the last idea. You could probably make an argument that it would be more efficacious as a deterrent (assuming that is part of your end game) if it is clearly visible.
Maybe add a sign that says, "You are on camera. You can smile...or not, I do not give a %&*$."
If I am honest, I am so paranoid I would probably have fifteen of these stupid things inside and out if I was not aware of my neurosis.
You need to figure out how to use a battery strapped to this thing to get an idea of how long it would run before it had to be changed. Make it so.
I think a 10000mah battery will run it for a couple days.
Nicee--- have my vests and your bests!
There are numerous devices out there, just takes a touch of looking. Somebody may consider how this identifies with Raspberry Pi,That's the means by which this identifies with Pi. @inertia
You have simply changed my comment... Lol....
You creating me funny and lough....
Actually, it's pretty obvious you're both spinners.
Hmm. It looks like another reason to buy a raspberry
Thanks for sharing sir
Amazing device Raspberry Pi Zero, I think.
amazing news,,thanks for shareing