How-To Add motion detection to our Xbox LIVE cam setup
Yesterday I showed you how to connect and stream an Xbox LIVE vision Camera from an Ubuntu computer to the internet (or your local network). Today we’re going to go a step further and set up a piece of software called Motion to not only stream the video but it will watch for motion and capture still frames when it sees any.
This is a fairly easy process.
What we need
- Our Ubuntu/Xbox LIVE Vision cam setup from yesterday
- An internet connection
Now as with the previous walkthrough we’re going to open up a terminal window
The first command we’ll run is
sudo apt-get install motion
This will fetch and install the Motion software package from the Ubuntu software repositories.
Now that we have Motion installed we need to tweak it’s configuration files to have it stream via webpage
so we type
sudo vi /etc/motion/motion.conf
(Replace “vi” with “gedit” if you want to do this via your gui)
This opens the main motion config file for editing
We need to replace the following lines
- Find
# Image width (pixels). Valid range: Camera dependent, default: 352 width 320
replace with
# Image width (pixels). Valid range: Camera dependent, default: 352 width 640
- Find
# Image height (pixels). Valid range: Camera dependent, default: 288 height 240
replace with
# Image height (pixels). Valid range: Camera dependent, default: 288 height 480
- find
# Quality of the jpeg images produced (default: 50) webcam_quality 50
replace with
# Quality of the jpeg images produced (default: 50) webcam_quality 80
- find
# Restrict webcam connections to localhost only (default: on) webcam_localhost on
replace with
# Restrict webcam connections to localhost only (default: on) webcam_localhost off
Save the file ( “esc” then “:wq” in vi. Just use the menus if you used gedit)
now we can test motion to see if it’s working.
sudo motion
You should get output similar to the following
[0] Processing thread 0 - config file /etc/motion/motion.conf [0] Motion 3.2.9 Started [0] ffmpeg LIBAVCODEC_BUILD 3352064 LIBAVFORMAT_BUILD 3344896 [0] Thread 1 is from /etc/motion/motion.conf [1] Thread 1 started [1] cap.driver: "uvcvideo" [1] cap.card: "Video Camera " [1] cap.bus_info: "0000:00:02.2" [1] cap.capabilities=0x04000001 [1] - VIDEO_CAPTURE [1] - STREAMING [1] Supported palettes: [1] 0: MJPG (MJPEG) [1] 1: YUYV (YUV 4:2:2 (YUYV)) [0] motion-httpd/3.2.9 running, accepting connections [0] motion-httpd: waiting for data on port TCP 8080 [1] Test palette YUYV (640x480) [1] Using palette YUYV (640x480) bytesperlines 1280 sizeimage 614400 colorspace 00000008 [1] found control 0x00980903, "Hue", range -180,180 [1] "Hue", default 0, current 0 [1] found control 0x00980910, "Gamma", range 180,250 [1] "Gamma", default 180, current 180 [1] found control 0x00980913, "Gain", range 0,255 [1] "Gain", default 0, current 24 [1] found control 0x08000000, "Backlight Compensation", range 0,1 [1] "Backlight Compensation", default 0, current 0 [1] found control 0x08000001, "Power Line Frequency", range 0,2 [1] "Power Line Frequency", default 2, current 2 [1] mmap information: [1] frames=4 [1] 0 length=614400 [1] 1 length=614400 [1] 2 length=614400 [1] 3 length=614400 [1] Using V4L2 [1] Started stream webcam server in port 8081
If you do use your web browser to go to http://your.ip.address:8081 (replace your.ip.address with the IP address of the computer Motion is installed on)
you should get a webpage with a view from your webcam. Success!
Now a couple tweaks you can make.
By default motion saves the images of motion to /tmp/motion if you want to change this folder you just need to edit the “target_dir /tmp/motion” entry in the /etc/motion/motion.conf while you’re in there you can increase the fps of the feed by changing the “webcam_maxrate 1″ entry to a higher number as well if you want to run this full time you may want to run it as a daemon which means it will run in the background to do this just set the “daemon” entry in the motion.conf file to “on” instead of “off”.
If you have any questions or suggestions please feel free to leave them in the comments.
If you enjoyed this post, make sure you subscribe to my RSS feed!