Raspberry Pi2 as surveillance cam?
Raspberry Pi2 as surveillance cam?
I've been meaning to get around to rigging up an IP cam at my front door, ideally something that will start recording when it detects motion. I have a Pi2, a Pi camera module and a spare Logitech HD webcam that is supposed to be compatible with Linux. Can anyone give me some pointers? The last time I looked at this there was no graphical GUI for the camera module and the command line inputs looked a bit beyond my capabilities.
-
- Posts: 179
- Joined: Wed Mar 26, 2014 4:44 pm
Re: Raspberry Pi2 as surveillance cam?
There's a good write up on instructables.com for one
I searched pi surveillance camera
I like your sig pic!
I searched pi surveillance camera
I like your sig pic!
Re: Raspberry Pi2 as surveillance cam?
Thanks, I had come up with a few options such as Raspbian, Motion Pie and Zoneminder but was interested in what people thought. Raspbian & ZoneMinder probably look a bit too complex for me.
Re: Raspberry Pi2 as surveillance cam?
Yup here purchased a few Logitech webcams for Joggler playing. They work well with Skype.
I wanted to build a Dick Tracey watch but the Logitech and Joggler wouldn't fit on my wrist.
Their are a few Ubuntu programs out there that see the Logitech web cam from the get go.
Been playing a bit with a time lapse video thing which works well on the Joggler / RPi2.
The compression pieces from mpeg to mp4 are a bit heavy on the CPU.
I have only tested this stuff on my IP cameras. It works well and I share the time lapse videos out to KODI. It is fun to watch.
Been a Zoneminder user here for many years. With the new HD IP cameras you do need more CPU / Memory these days.
There have been some folks running it on the RPi2 these days.
It is a python script.
Here are are my installation Python files. I installed everything in the root drive /timelapse and share the drive out via SAMBA.
Add the font file right to the directory.
1 - sudo apt-get install python-imaging * need this for the imaging pieces
2 - Main python capture script:
4 - Convert to MP4 script:
I wanted to build a Dick Tracey watch but the Logitech and Joggler wouldn't fit on my wrist.
Their are a few Ubuntu programs out there that see the Logitech web cam from the get go.
Been playing a bit with a time lapse video thing which works well on the Joggler / RPi2.
The compression pieces from mpeg to mp4 are a bit heavy on the CPU.
I have only tested this stuff on my IP cameras. It works well and I share the time lapse videos out to KODI. It is fun to watch.
Been a Zoneminder user here for many years. With the new HD IP cameras you do need more CPU / Memory these days.
There have been some folks running it on the RPi2 these days.
It is a python script.
Here are are my installation Python files. I installed everything in the root drive /timelapse and share the drive out via SAMBA.
Add the font file right to the directory.
1 - sudo apt-get install python-imaging * need this for the imaging pieces
2 - Main python capture script:
Code: Select all
#!/usr/bin/python
# Number of seconds between frames:
LAPSE_TIME = 30
# Name of truetype font file to use for timestamps (should be a monospace font!)
FONT_FILENAME = "UbuntuMono-B.ttf"
# Format of timestamp on each frame
TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"
# Command to batch convert mjpeg to mp4 files:
# for f in *.mjpeg; do echo $f ; avconv -r 30000/1001 -i "$f" "${f%mjpeg}mp4" 2>/dev/null ; done
import urllib
import sys, time, datetime
import StringIO
import Image, ImageDraw, ImageFont
class Camera:
def __init__(self, name, url, filename):
self.name = name
self.url = url
self.filename = filename
def CaptureImage(self):
camera = urllib.urlopen(self.url)
image_buffer = StringIO.StringIO()
image_buffer.write(camera.read())
image_buffer.seek(0)
image = Image.open(image_buffer)
camera.close()
return image
def TimestampImage(self, image):
draw_buffer = ImageDraw.Draw(image)
font = ImageFont.truetype(FONT_FILENAME, 16)
timestamp = datetime.datetime.now()
stamptext = "{0} - {1}".format(timestamp.strftime(TIMESTAMP_FORMAT), self.name)
draw_buffer.text((5, 5), stamptext, font=font)
def SaveImage(self, image):
with open(self.filename, "a+b") as video_file:
image.save(video_file, "JPEG")
video_file.flush()
def Update(self):
image = self.CaptureImage()
self.TimestampImage(image)
self.SaveImage(image)
print("Captured image from {0} camera to {1}".format(self.name, self.filename))
if __name__ == "__main__":
cameras = []
cameras.append(Camera("porch", "http://username:[email protected]<script data-cfhash='f9e31' type="text/javascript">
/* */</script>/SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam1.mjpeg"))
cameras.append(Camera("driveway", "http://username:[email protected]
/* *//SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam2.mjpeg"))
cameras.append(Camera("backyard", "http://username:[email protected]
/* *//SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam3.mjpeg"))
cameras.append(Camera("sideyard", "http://10.17.42.176/image/jpeg.cgi", "cam4.mjpeg"))
cameras.append(Camera("stairway", "http://10.17.42.175/image/jpeg.cgi", "cam5.mjpeg"))
print("Capturing images from {0} cameras every {1} seconds...".format(len(cameras), LAPSE_TIME))
try:
while (True):
for camera in cameras:
camera.Update()
time.sleep(LAPSE_TIME)
except KeyboardInterrupt:
print("\nExit requested, terminating normally")
sys.exit(0)
Code: Select all
#!/bin/bash
echo "Removing old files..."
rm -fv *.mp4
echo "Converting files to mp4..."
for f in *.mjpeg ; do
t=${f%mjpeg}mp4
echo " Converting $f to $t"
avconv -r 30000/1001 -i "$f" -q 5 "$t" 2>/dev/null
done
echo "Done!"
- Pete
O2 Jogglers running EFI Ubuntu / Squeezeplayer
OpenPeak Voip Telephony / Zigbee tabletops hardware modded with Seabios / RTC / Ethernet ROM edits / SSD drives running XPe for automation screens
Auto mater
O2 Jogglers running EFI Ubuntu / Squeezeplayer
OpenPeak Voip Telephony / Zigbee tabletops hardware modded with Seabios / RTC / Ethernet ROM edits / SSD drives running XPe for automation screens
Auto mater
Re: Raspberry Pi2 as surveillance cam?
Thanks Pete, this looks a little advanced for me, I'm more in the market for an off-the-peg solution for the hard-of thinking
Re: Raspberry Pi2 as surveillance cam?
Zoneminder should work for you.
Here are the instructions for running it on a n RPi2
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install apache2
sudo apt-get install zoneminder
sudo apt-get install v4l-utils
# Allow www-data to access webcam:
sudo usermod -aG video www-data
# Add CGI ScriptAlias if not present after installing:
sudo nano /etc/zm/apache.conf
# Correct ownership/give write+read+execute dir access to www-data group under /var/cache/zoneminder/*
sudo chown -R root:www-data /var/cache/zoneminder/*
sudo find /var/cache/zoneminder/ -type d -exec chmod 775 {} +
# Correct Perl memory bug in zoneminder code if present:
# REF : http://www.freshports.org/multimedia/zo ... mory.pm.in
sudo nano /usr/share/perl5/ZoneMinder/Memory.pm
# line 130 - Change from:
-our $arch = int(3.2*length(~0));
# To:
+our $arch = 32;
# Find formats of webcam for zoneminder config:
zmu -d /dev/video0 -vqV2
# If that does not work or fails to enumerate, try:
v4l2-ctl --list-formats
4. Kernel shared memory settings:
# Set shared memory for 512MB RPi board:
# 128MB shhmax shared:
sudo su -
echo "kernel.shmmax = 134217728" >> /etc/sysctl.conf
exit
# 2MB shmall pages:
sudo su -
echo "kernel.shmall = 2097152" >> /etc/sysctl.conf
exit
Here are the instructions for running it on a n RPi2
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install apache2
sudo apt-get install zoneminder
sudo apt-get install v4l-utils
# Allow www-data to access webcam:
sudo usermod -aG video www-data
# Add CGI ScriptAlias if not present after installing:
sudo nano /etc/zm/apache.conf
# Correct ownership/give write+read+execute dir access to www-data group under /var/cache/zoneminder/*
sudo chown -R root:www-data /var/cache/zoneminder/*
sudo find /var/cache/zoneminder/ -type d -exec chmod 775 {} +
# Correct Perl memory bug in zoneminder code if present:
# REF : http://www.freshports.org/multimedia/zo ... mory.pm.in
sudo nano /usr/share/perl5/ZoneMinder/Memory.pm
# line 130 - Change from:
-our $arch = int(3.2*length(~0));
# To:
+our $arch = 32;
# Find formats of webcam for zoneminder config:
zmu -d /dev/video0 -vqV2
# If that does not work or fails to enumerate, try:
v4l2-ctl --list-formats
4. Kernel shared memory settings:
# Set shared memory for 512MB RPi board:
# 128MB shhmax shared:
sudo su -
echo "kernel.shmmax = 134217728" >> /etc/sysctl.conf
exit
# 2MB shmall pages:
sudo su -
echo "kernel.shmall = 2097152" >> /etc/sysctl.conf
exit
- Pete
O2 Jogglers running EFI Ubuntu / Squeezeplayer
OpenPeak Voip Telephony / Zigbee tabletops hardware modded with Seabios / RTC / Ethernet ROM edits / SSD drives running XPe for automation screens
Auto mater
O2 Jogglers running EFI Ubuntu / Squeezeplayer
OpenPeak Voip Telephony / Zigbee tabletops hardware modded with Seabios / RTC / Ethernet ROM edits / SSD drives running XPe for automation screens
Auto mater
Re: Raspberry Pi2 as surveillance cam?
Thanks for this - I assume the starting point is Raspian? I'll take a deep breath & give it a go.
Re: Raspberry Pi2 as surveillance cam?
I just googled the above so I am not sure. You cannot break anything writing an RPi2 image to an microSD card.
I currently am using two RPi2 Wheezys. One is running CumulusMX and the other is running Homeseer. Both utilize mono.
While the RPi2 is much nicer than the RPi1; its still rather a bit underpowered. ZM captures jpg stills to make videos; a bit primitive and works well.
Here is a short timelapse video that I uploaded to MS using the RPi2.
http://1drv.ms/1LBTG7h
It is easiest to download it then play it back. It is a few days worth.
I currently am using two RPi2 Wheezys. One is running CumulusMX and the other is running Homeseer. Both utilize mono.
While the RPi2 is much nicer than the RPi1; its still rather a bit underpowered. ZM captures jpg stills to make videos; a bit primitive and works well.
Here is a short timelapse video that I uploaded to MS using the RPi2.
http://1drv.ms/1LBTG7h
It is easiest to download it then play it back. It is a few days worth.
- Pete
O2 Jogglers running EFI Ubuntu / Squeezeplayer
OpenPeak Voip Telephony / Zigbee tabletops hardware modded with Seabios / RTC / Ethernet ROM edits / SSD drives running XPe for automation screens
Auto mater
O2 Jogglers running EFI Ubuntu / Squeezeplayer
OpenPeak Voip Telephony / Zigbee tabletops hardware modded with Seabios / RTC / Ethernet ROM edits / SSD drives running XPe for automation screens
Auto mater