Someone sneaks into my cubicle while I’m at lunch and takes candy out of my desk. Petty, but stupid too. I want to set up something so that my webcam on my iMac takes photos every few seconds while I’m away from my desk so I can catch the culprit! How can I do that in a stealthy manner while the computer is otherwise asleep?
This is a great question! The first thing you’ll probably need to do is put a sticker over the tiny green light that illuminates when your webcam is activated. That’s the easy part.
For the rest of this, we’re going to delve into the command line, but before we do that, you’ll need to download a handy utility called ImageSnap, which can be found at an open source archive called SourceForge. I’ll save you the trouble of finding it, though. Just go to ImageSnap on SourceForge and click on the download link at the top.
What you’ll want to do is download the package to a separate directory on your Mac system. I have a directory called “bin” at the topmost level, so that’s where I save my version of ImageSnap.
Then launch Terminal.app (you can find it in the Applications –> Utilities folder) and move to the directory where you saved the compressed archive.
Lost with all of this? You’d be smart to grab a copy of my best-selling book Learning Unix for Mac OS X Mountain Lion to get started with the incredibly powerful Unix command line system hidden within Mac OS X.
Now type this (possibly slightly modified to match the version of ImageSnap you’ve downloaded):
$ gunzip ImageSnap-v0.2.5.tgz
$ tar xf ImageSnap-v0.2.5.tar
$
Everything happens lightening fast and when you’re done, there’s a new directory called “ImageSnap” in that folder. Move into it with “cd” and use the “ls” command to see what’s there:
$ ls -F ImageSnap.h ImageSnap.xcodeproj/ imagesnap* ImageSnap.m ReadMeOrDont.rtf
Great. Now you have the command you want, imagesnap. To use it, just type the program’s name:
$ ./imagesnap
Capturing image from device "FaceTime HD Camera (Built-in)"...snapshot.jpg
Takes about 5 seconds and, yes, the little green light will illuminate for a moment or two during the process (hence the need to cover it with a sticker, post-it or something similar.
The image captured? Here’s one of my typing in this particular blog entry:
That’s pretty cool. Now how to do a series of images over time? The easiest way is to let “imagesnap” do the heavy lifting, as becomes obvious with a quick invocation of the “-h” flag:
$ ./imagesnap -h USAGE: ./imagesnap [options] [filename] Version: 0.2.5 Captures an image from a video device and saves it in a file. If no device is specified, the system default will be used. If no filename is specfied, snapshot.jpg will be used. Supported image types: JPEG, TIFF, PNG, GIF, BMP -h This help message -v Verbose mode -l List available video devices -t x.xx Take a picture every x.xx seconds -q Quiet mode. Do not output any text -w x.xx Warmup. Delay snapshot x.xx seconds after turning on camera -d device Use named video device
To have a snapshot taken every five seconds, for example:
$ ./imagesnap -t 5 Capturing image from device "FaceTime HD Camera (Built-in)"...snapshot-00000-2013-04-17_18-02-09.623.jpg snapshot-00001-2013-04-17_18-02-14.625.jpg snapshot-00002-2013-04-17_18-02-19.629.jpg snapshot-00003-2013-04-17_18-02-24.632.jpg
Even better, you can see that ImageSnap is smart enough to name the files with a timestamp.
Realistically, every five seconds is probably too frequent. Try every 30:
$ ./imagesnap -t 30
With that, you should be good to go as a budding Mac cyber-detective. Come back and let us know how it went, okay!
Thanks a lot for this tutorial. It’s very helpful, though I’m having trouble with the time-lapse option. I can’t seem to figure out where the files are being saved. I notice that the example above doesn’t specify a directory to save the output files, so I’m curious if there is a default location on my computer that I don’t know about where I should look (I doubt this, since I’ve used spotlight search on the filename that is printed in the terminal and I’ve found nothing).
I also tried a modification of the above example where I pass the function a path (to my desktop). Neither seem to work. Here’s a brief list of all the things I’ve tried:
1. ./imagesnap -t 3
2. imagesnap -t 3 /Users/Sidney/Desktop/
3. imagesnap -t 3 /Users/Sidney/Desktop/.
Second, is there a good way to stop the code after a certain number of frames? Thanks in advance!
Do you get the command to work properly from the command line, Sidney? General rule of thumb with shell scripts is that without an output directory specified, it’ll save the files to the same directory you were in when you invoked the program. So if you’re in /Users/sydney/watcher when you start the script, the images will be saved therein. In terms of a “stop after ‘n’ frames, that should be easy to add to the script: just test the iteration count value and “exit” when it matches the desired count.
You mention using the “cd” command, but you don’t show the exact command:
cd ImageSnap
(After “tar” and before “ls”.)
Also, my own preference is to use “xvf” for tar, so I can see the filenames go by. But, that’s just me. 🙂
Very odd, Steven. Try this link:
http://iharder.sourceforge.net/current/macosx/imagesnap/
Something clearly isn’t updating properly on SourceForge. 🙂
At your link I found version 0.2.4 of ImageSnap instead of 0.2.5 and it does not appear to have the -t switch.
While I’m sure that this works well it’s intimidating for anyone that doesn’t have a high comfort level with the terminal and coding. A far simpler – and free – solution is available in the Mac and iTunes stores. You can find iCam in both of those places and set it up so that it takes photos automatically based on motion detection. It’s simple to install, easy to access from any desktop or mobile device and provides exactly the function that this query addresses.