Make a Spycam

From SingletonMillerWiki
Revision as of 15:28, 5 July 2012 by Martin (Talk | contribs) (References)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Heavily inspired by using a Webcam to monitor wildlife


Get your web cam working

Follow this guide Monitor a Webcam, make sure you can view and record video files, make a not of the frame rate you can achieve.

remote access

note if you’re using ssh don’t forget the -X option to enable X forwarding so you can see the camera output

install Motion

Motion [1] is an awesome bit of software that monitors a video stream for changes. assuming your using a debian based system

sudo apt-get install motion

after the install I got a warning Not starting motion daemon, disabled via /etc/default/motion ... (warning).

call the motion help page using

motion -h

gives

motion Version 3.2.12, Copyright 2000-2005 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen

usage:	motion [options]


Possible options:

-n			Run in non-daemon mode.
-s			Run in setup mode.
-c config		Full path and filename of config file.
-d level		Debug mode.
-p process_id_file	Full path and filename of process id file (pid file).
-h			Show this screen.

Motion is configured using a config file only. If none is supplied,
it will read motion.conf from current directory, ~/.motion or /etc/motion.

We need to edit the config file get this thing going.

Motion config file

Detailed instructions are here MotionGuideGettingItRunning but i just read through the config file /etc/motion/motion.conf reading the descriptions and changing anything i thought was necessary (which wasn't much).

changed target_dir /tmp/motion target_dir /media/nfsshares/jack/motion

run in setup mode

motion -s

run motion in the terminal and give useful messages. I hit ctrl-c after a second or so to get

[0] could not open configfile /etc/motion/motion.conf: Permission denied
[0] Not config file to process using default values
[0] Motion 3.2.12 Started
[0] ffmpeg LIBAVCODEC_BUILD 3412993 LIBAVFORMAT_BUILD 3415808

the rather obvious error say i can't access the conf file.

ls -l /etc/motion

confirm my user doesn't have the privs to open the default config file.

total 64
-rw-r----- 1 root motion 24012 Jul  1 22:09 motion.conf
-rw-r----- 1 root root   23993 Aug 10  2010 motion.conf~
-rw-r--r-- 1 root root    2107 Aug 10  2010 thread1.conf
-rw-r--r-- 1 root root    2107 Aug 10  2010 thread2.conf
-rw-r--r-- 1 root root    2110 Aug 10  2010 thread3.conf
-rw-r--r-- 1 root root    2625 Aug 10  2010 thread4.conf

add your user to the motion group

sudo gpasswd -a jack motion
[sudo] password for jack: 
Adding user jack to group motion

you will need to logout and login again for the new permissions to apply, then try the setup mode again, this time your user can access the config file with errors.

A few seconds of operation with me waving my arms in front of the webcam gave this output to the terminal. Force terminated with ctrl-c.

and the target_dir defined in the config file contained some output

01-20120701223509-01.jpg  01-20120701223510-01.jpg
01-20120701223509.swf     01-20120701223513-01.jpg

So it looks like my arm waving stimulated some data capture, but it looks like this

01-20120701223509-01.jpg

The other thing to notice is that there's also a flash *.swf file created too.

That doesn't seem right, lets switch off video capture as thats got to be a resource hog. Modify the config file setting from ffmpeg_cap_new on to ffmpeg_cap_new off

I also noticed this

# v4l2_palette allows to choose preferable palette to be use by motion
# to capture from those supported by your videodevice. (default: 8)
# E.g. if your videodevice supports both V4L2_PIX_FMT_SBGGR8 and
# V4L2_PIX_FMT_MJPEG then motion will by default use V4L2_PIX_FMT_MJPEG.
# Setting v4l2_palette to 1 forces motion to use V4L2_PIX_FMT_SBGGR8
# instead.
#
# Values :
# V4L2_PIX_FMT_SN9C10X : 0  'S910' 
# V4L2_PIX_FMT_SBGGR8  : 1  'BA81' 
# V4L2_PIX_FMT_MJPEG   : 2  'MJPEG'
# V4L2_PIX_FMT_JPEG    : 3  'JPEG'
# V4L2_PIX_FMT_RGB24   : 4  'RGB3'
# V4L2_PIX_FMT_UYVY    : 5  'UYVY'
# V4L2_PIX_FMT_YUYV    : 6  'YUYV'
# V4L2_PIX_FMT_YUV422P : 7  '422P'
# V4L2_PIX_FMT_YUV420  : 8  'YU12'
v4l2_palette 8

This looks a likely candidate for why the data captured is garbage, perhap the palette is wrong?

I used the terminal output from mplayer to find the correct setting for my video device, see Monitor_a_Webcam

mplayer tv:///dev/video0

The output shows detection of the colour palettes for the video device.

Selected device: USB Camera-B4.04.27.1
 Capabilites:  video capture  read/write  streaming
 supported norms:
 inputs: 0 = ov534;
 Current input: 0
 Current format: YUYV

It looks like we need v4l2_palette 6

This produced valid pictures although it seems difficult to stimulate a capture.

Experimentation with the detection criteria is next, I ended up disabling the filters by commenting out ;despeckle EedDl

In setup mode this simulated captures but i noticed that occationally things would go haywire and bad frame similar to the above would cause lots of captures. This may be a problem with my set-up or the camera.

More testing is needed to discover the cause of the very high number of false alarms / garbage frames captured. But the fundametals seems to be working.

To Do

  1. Get your web cam working
  2. Enable Motion detection
  3. Decide what to do with the video you've just captured.
    1. email yourself notifcation of the event
    2. take a snapshot image
    3. upload the data
  4. Going Cordless
  1. Battery
  2. Wifi

Wifi

Edimax EW-7811UN http://www.cianmcgovern.com/getting-the-edimax-ew-7811un-working-on-linux/

Related Pages

Monitor a Webcam

References

  1. Motion Homepage
  2. http://jeremyblythe.blogspot.co.uk/2012/06/battery-powered-wireless-motion.html
  3. http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionGuideGettingItRunning
  4. http://www.debian-administration.org/articles/347