Hacking together a cheap but effective infra-red camera

eyesMany animals annoyingly do things differently in the dark than in the light. This causes problems for both field- and lab-based behavioural biologists, as few are blessed with the power of night vision. However, there are ways around this problem. One old-tech method is to observe them using red light, making the assumption that the beastie you’re observing can’t see at these longer wavelengths, but you can. However, a number of studies suggest that this a flawed assumption (e.g. 1, 2). So, how do you see in the dark?

Using electromagnetic radiation that has wavelengths outside the visual spectrum of the animals is one solution. Night vision and other special cameras are able to detect infrared radiation, which has a longer wavelength than visible light. This IR may be radiated as thermal energy by the animal (this is what heat-detecting cameras register), or could be being reflected by the animals and their environment (which is what many night-vision and CCTV cameras do, using an additional source of IR such as a set of IR-emitting LEDs, like the ones found in TV remote controls).

We and most other animals are unable to see these longer IR wavelengths, so these cameras are essentially detecting ‘invisible’ information that is unavailable to us. Any extra information about the environment that could improve your chances of finding food or avoiding predators is going to be useful if it can be detected, and there are of course some animals that can detect IR3: vampire bats, several families of snake and a range of butterflies, beetles and bugs have well-researched abilities to detect IR. Similarly, some prey species have evolved counteradaptations to confuse species that are able to detect IR, as can be seen4 in the anti-pit viper tail-flagging displays of ground squirrels. However, given that many animals are insensitive to IR wavelengths (we assume – it doesn’t hurt to check and double-check if you’re working with a particular species!), using an IR camera is a good first step for observing their behaviour unobtrusively, and many bits of kit are commercially available that allow you to observe nesting behaviour or remotely capture images of animals in the wild (I have no intention of recommending any of the products out there, but you should be able to find hundreds of commercial types available by running a web search for ‘camera trap’, ‘nest cam’ or ‘trail camera’).

Making your own IR-sensitive webcam

However, commercially available kit ranges in price and can be expensive. If you’re piloting a bit of work and want to test things out before you write the big grant, buying one or multiple specially designed cameras may be that little bit too expensive. It is however extremely easy to build your own IR camera using a little bit of initiative. The sensors on webcams and other digital cameras are sensitive to IR, but usually have some sort of filter between the lens and the sensor that blocks out unwanted non-visible electromagentic radiation: it is easy to remove this in some cameras, but can involve some delicate and potentially destructive scraping in others. A quick hunt online will give you access to loads of text and video tutorials on how to do this (here’s a good one from the Naked Scientists). Once removed, there’s nothing else you need to do – the sensors will be registering IR, and probably displaying it as extra purplish light if you’re able to see the camera’s output.

I’ve played with a few different cheap webcams available, and acknowledge that they do differ in both quality and ease of modification. Because sensor types and the way light is filtered onto them differs from camera to camera, I’d recommend shopping around for a camera that has a bit of depth to it as it is likely to have a separate filter that can be easily chipped out, rather than one that has to be scraped directly off the sensor (which will probably damage teh sensor). Removing the filter will also affect the depth at which incoming visible and IR light is focussed on the sensor, and I’d suggest hunting for a camera where the lens is focussed manually rather than by having to use a software interface.

I ended up settling for the Tecknet® 1080P HD Webcam, which was very cheap, is very easy to take apart and alter, has a decent pixel size and image quality, and is easy and stable to focus. These webcams are extremely easy to modify. After removing the front, the focussing lens can be unscrewed (below, A), revealing the filter (the shiny square bit in B) that blocks IR wavelengths from reaching the sensor. There’s probably a neater way of doing this, but it is easy to carefully chip this out with the end of a screw-driver (CBlue Peter warning: make sure you’re wearing eye-protection and using appropriate safety equipment while you’re doing this, and get an adult to help you). Then, simply reassemble and plug into your favourite operating system. I’m fairly certain this voids the warranty though…

removing the IR filter

Hardware for running your IR camera

It’s not just the camera that’s important if you’re trying to build cheap functional kit – you also need something to run it from. You could technically run it on anything that has the correct webcam driver installed (hint: if you’re a Mac user and can’t find the right driver, try running the camera from within Skype, which may well be able to run it). However, since we’re aiming for budget kit here, I’ll give a quick description of a system I’ve put together that runs from a Raspberry Pi – a tiny, inexpensive (GB£20, €26, US$25) computer that runs open-source LINUX-based software*, which means that the system is incredibly portable and can be altered to run off a battery in the field (useful if you’re building a cheap and effective camera traps for IR and/or visible wavelengths, like those deployed by ZSL for monitoring black rhino). Furthermore, because you’re building it yourself, it doesn’t require system administrators to install things for you (a major time-lagging factor for many researchers working in larger institutions!).

I’m assuming here that you’ve managed to get your Raspberry Pi up and running, formatting your SD card with something like Raspbian, and are happy with using a command-line tool (if you’re running a graphic-based interface, you can get at this using one of the ‘Terminal’ applications such as LXTerminal). I’m also assuming that you have managed to connect your system to the internet, as you’ll need to download some software. If you’re intending to set this up using a monitor rather than remotely, and want to be able to remove the monitor at some point during the camera’s use, it’s worthwhile getting the Model B Raspberry Pi with two USB ports, which means that you don’t need to detach the camera at any point.

Software for running your IR camera

Some bits of easily obtainable software are useful if you’re running this off a Raspberry Pi. Firstly, if you want to have a direct feed from the camera which is visible on a monitor in front of you, try something like Camorama. Assuming you have an internet connection, you can install this on your computer by entering

sudo apt-get install camorama

and answering ‘yes’ at appropriate moments. To run it, simply type ‘camorama’ into the terminal: as well as a direct feed and a point-and-click interface that allows you to play with the visual balances, you can take jpeg images too. If you want to record mpeg-format videos, you could try a program such as LUVCView instead, which you install and run in a similar manner (by replacing the word ‘camorama’ with ‘luvcview’ in the commands described).

If instead you want to either take still photos at regular intervals, or use your camera as a motion-triggered device (useful for camera traps), I recommend starting off with Motion, which you need to initially install using

sudo apt-get install motion

To run this at the default setting (where the camera is triggered by motion), just type ‘motion’ into the terminal once you have installed the software. As this package is run from the command line, you can create a text file that details exactly how you want the camera to be configured. For example, if you want to run the camera so that it doesn’t react to motion, but instead captures an image every quarter of a second, you can set up a configuration file using a word processor such as nano:

sudo nano motion.config

and typing the following:

framerate 4
output_all on

which you then save a the file ‘motion.config’ (using ctrl+x). The first command above sets the maximum number of frames per second that the device captures, and the second tells the system to turn off the motion-detection capability of the software, and instead take continuous images.

Having created the motion.config file, you then run motion by entering

motion -c motion.config

It may take a few seconds to start up, and you should then get a display whenever a file is written. To stop the program when it’s running, open another terminal window and type

killall motion

Motion is relatively simple to use, and has a good list of configurations that you can play with: simply reopen the config file you’ve created using the same commands, and alter the text. There’s the option of creating a timelapse video within this as well, but you are limited to only being able to use images that are a second or more apart.

A final word, and some caveats

A note for the coding purists out there: the description given here is written to enable non-coders to put together something that works with a minimum of poking. I am fully aware that there are other more elegant ways of doing this, and many other forms of software that can be used, but this should give a first step to enable a stressed lab/field scientist to have something functioning quickly. I am not willing to give any advice on this or similar applications, and accept no responsibility or liability if you follow these instructions and end up damaging your equipment or yourselves in any way: you follow them entirely at your own risk.

Having made your IR camera and worked out how to run the software behind it, you can then deploy it – you will need an IR light source too, and there are many available out there designed for CCTV systems (make sure you’re using them safely though). It looks like things may soon be made even easier by with the introduction of a super-cheap (US$25) IR camera specifically designed for the Raspberry Pi, which will hopefully be well supported within the Raspberry Pi user community. I’ve currently got some undergraduate project students trying out this kit in the lab, on a neat system that may be very nice for observing social and group behaviour – some more on this soon!

Further reading

1. Gibson G (1995). A behavioural test of the sensitivity of a nocturnal mosquito, Anopheles gambiae, to dim white, red and infra-red light. Physiological Ecology 20: 224-228. doi:10.1111/j.1365-3032.1995.tb00005.x

2. Heise BA (1992). Sensitivity of mayfly nymphs to red light: implications for behavioural ecology. Freshwater Biology 28: 331-336. doi:10.1111/j.1365-2427.1992.tb00591.x

3. Campbell AL, Naik RR, Sowards L & Stone MO (2002). Biological infrared imaging and sensing. Micron 33: 211-225. doi:10.1016/S0968-4328(01)00010-5

4. Rundus AS, Owings DH, Joshi SS, Chinn E & Giannini N (2007). Ground squirrels use an infrared signal to deter rattlesnake predation. Proceedings of the National Academy of Sciences of the USA 104: 14372-14376. doi:10.1073/pnas.0702599104

Advertisements