How to do Raspberry Pi Zero Surveillance with Ruby

avatar
(Edited)

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.

2018-01-28 10.04.03.jpg



0
0
0.000
31 comments
avatar

amazing news,,thanks for shareing

0
0
0.000
avatar

Amazing device Raspberry Pi Zero, I think.

0
0
0.000
avatar

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.

0
0
0.000
avatar

At least power it up and run mosh + tmux so you have shell sessions with years of uptime.

banjo:~ $ uptime
 20:59:49 up 100 days,  1:09,  3 users,  load average: 0.44, 0.35, 0.37

The only reason that pi reboots is because I crash it from running too many blockchain streams. :D

0
0
0.000
avatar

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!

0
0
0.000
avatar

Nicee--- have my vests and your bests!

0
0
0.000
avatar

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.

0
0
0.000
avatar

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.

0
0
0.000
avatar

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

0
0
0.000
avatar
(Edited)

You have simply changed my comment... Lol....
You creating me funny and lough....

tenor.gif

0
0
0.000
avatar

Actually, it's pretty obvious you're both spinners.

0
0
0.000
avatar

There are many tools out there, just takes a bit of looking. Some of you might be wondering how this relates to Raspberry Pi, well I did this installation on my own Pi. That's how this relates to Pi and I though it was necessary to post how I did install Metasploit on my Pi. I would love comments down below and please give me some loving, but alas hack on my fellow hackers. :)

0
0
0.000
avatar

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.

0
0
0.000
avatar

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:

0
0
0.000
avatar

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.

0
0
0.000
avatar

I think a 10000mah battery will run it for a couple days.

0
0
0.000
avatar

Raspberry has been made to tamper completely. If you are a bit interested in Raspberry, you can eat your hours. Raspberry is what I really need. This little computer is excellent. After a little bit of trouble, I have managed to get the job done after I have tackled some minor problems. It's a very nice thing. I came out😊

0
0
0.000
avatar

Hi! Cool project, I love to use Pi Zero and I am a big fan of RPi. I also use it in my home automation system and alarm. One of my Pi Zero works quite nice and smoothly as element of home system with attached motion sensor, temp sensor and the camera. It easily handles one room :) Great job! I'll post some of my project soon. You should post more of your works, I bet you have something :)

0
0
0.000
avatar

thanx for that. Having a Raspi with the wide range cam but just played around with the v4l stuff and connected using VLC

0
0
0.000
avatar

btw. there are quite new infrared-camera (supplier: digikeys) for good price. Unfortunately they need to be connected using i2c (command interface) as well as SPI (video data).
I did not connected it to an Raspberry yet but an homemade Atmel AT32UC3A3256 Controller-Board with color LCD. Might be nice project to make it work for Raspies

0
0
0.000
avatar

WOw so you basically programmed your own trail cam. cool.

Thanks for open sourcing this.

0
0
0.000