Page 1 of 2

Raspberry Pi as a webcamera

Posted: Mon 20 Jan 2014 3:10 am
by tumutbound
Not sure if this should be in the Webcam forum, mods feel free to relocate if required.

Not the first to do this* but I thought I'd document my build of a weather camera based on a Raspberry Pi computer.

What you'll need is a Raspberry PI (I'm using a Model B), a Raspberry camera module, a WIFI dongle,, a box to put it in and some spare time.
A bit of programming knowledge would come in handy but there are enough guides out there to get you going using the standard picture taking utilities.
I'll post more once I get some photos organised.

Designing a web site to upload your images to is a whole other subject for which I'll soon be seeking assistance :D


*Thanks Karl from Bridge Lake Weather Station =

Regards
Geoff

Re: Raspberry Pi as a webcamera

Posted: Mon 20 Jan 2014 6:29 am
by tumutbound
Sorry about the size of the images. I would have used thumbnails but didn't see an option to do so.

First step was to source a suitable camera housing. There are quite a few dummy security camera housings available on eBay but most of them seemed to be plastic.
I found this one at a local electronics retailer for about $A40. It has a slide in metal shelf on to which the components can be mounted.
camera_housing.jpg
As the camera will be 3 metres up on the side of my shed which is about 15 metres from the house, I decided to use WIFI dongle ($A9) and to provide 5V for the Pi,a DC-DC converter ($A10), both from eBay.
Power is supplied from an 8V wall wart through 10 metres of outdoor lighting cable. This was choosen as it's a tough, UV stable, weatherproof product with a 1.3mm core so they'll be hardly any voltage drop.

I made a camera bracket from a piece of 60mm aluminium angle into which I cut a slot for the camera flat cable. A couple of holes were drilled for mounting the camera module and it was secured with nylon screws and stand offs.
IMG_3765.JPG
IMG_3766.JPG
A few suitable holes were drilled on the supplied metal shelf to mount the Pi and the DC-DC convertor. Spacing is not critical but the camera cable is quite short so keep the Pi as close to the front as possible.
IMG_3761.JPG
IMG_3760.JPG
The only modification I made to the case was to drill a hole to mount the antenna on the back. To connect the antenna to the WIFI dongle, you need an co-ax extension cable (RP-SMA) which are readily available on eBay.
IMG_3764.JPG
The power cable is a bit stiff and was awkward to connect to the DC-DC converter so I mounted a small piece of screw terminal strip to the shelf to make the connection a bit easier and to provide some strain relief.
Last step was to clean off all the fingerprints off the glass and install the front and back covers..

Now I need to put it in its final location but that required a bit of wood butchery which I'll do tomorrow.

If you want to see a quick snapshot, pop on over to http://www.port-huon.com.au/weather/webcam/weather.jpeg

Re: Raspberry Pi as a webcamera

Posted: Mon 20 Jan 2014 7:49 am
by captzero
Geoff,
Great picture quality and resolution. Well done. :clap:

Re: Raspberry Pi as a webcamera

Posted: Mon 20 Jan 2014 8:37 am
by tumutbound
I still have to decide what software to use to take/process the images.

I used Karl's method of taking three bracketing shots and then processing with enfuse. This gives good definition to the clouds at the expense of foreground detail. That's OK though as it's the clouds we're interested in, not my plants. :D
The software I used for the sample shot is a simple Python script using the picamera module.
If I take a snapshot using motion software, I get a much tighter shot i.e. narrow FOV. Both are taken with the same resolution (1280x768) so I need to find out how to duplicate the motion results with picamera.

As the Pi only has an SD flash drive, writing to it as little as possible is a good idea, so images are stored on a Samba share that is mounted on the Pi from my Linux server. (I'll also change the logging so it goes to the Linux server). I need to update the script to ftp the processed images to the website. I also want to overlay some text e.g. current temperature, humidity etc. which can be done with ImageMagick

EDIT: Seems that the FOV issue is to do with whether the still or video port is used in the Pi camera. Video resolution is lower than for still pictures but a quick test shows it's still more than acceptable.

Sample image via video port is here: http://port-huon.com.au/weather/webcam/latest.jpg

Re: Raspberry Pi as a webcamera

Posted: Tue 21 Jan 2014 6:19 am
by tumutbound
Too windy today to climb a ladder and install the camera so worked on the software a bit instead.
Not having programmed in python before, it's a slow process. At least it's not javascript ...

For anyone who's thinking of installing a camera, here's a detailed costing of my effort (in Australian dollars):
  • Raspberry Pi (Model B) $A42
    Raspberry Pi camera module $A30
    Metal camera case and bracket $A50
    WIFI dongle $A9
    RP-SMA antenna cable extension $A2 (actually 5 off for $A9)
    DC-DC converter $A12
    10 metres of dual core cable $A12
The Raspberry Pi and camera module are available from RS-Components or Element-14 (Farnell). The other parts came from various eBay sellers. The cable I got from the local hardware store.
Total cost was $A157 which is about the price you'd pay for an HD outdoor camera but the Pi based camera can do so much more.
All the photo processing (taking the images, combining multiple shots, making a daily time-lapse video and uploading the results to my website).
Lots of room in the camera housing and lots of spare processing power so I'm thinking about what else I can add ;)

Re: Raspberry Pi as a webcamera

Posted: Mon 24 Mar 2014 11:53 pm
by howesij
Hi Geoff,

Great Work I have been thinking about doing this since the RPi camera was released.

Have you found any good software yet for taking the shots?

My current weathercam takes 16 sec exposures at night which is good for capturing lighting, so I would like to continue to do this.

I was also thinking about powering the RPi by a solar panel and lithium battery pack.

Cheers

Ian
Nomads Weather http://users.tpg.com.au/howesij/weather/index.htm
Nomads WeatherCam http://webcams.bsch.au.com/ferny_grove.html

Re: Raspberry Pi as a webcamera

Posted: Tue 25 Mar 2014 12:55 am
by tumutbound
Hi Ian,
The software is a script written in Python using the picamera library. The software to combine the images is enfuse and the GPS data is added using ExifTool.
The script is run from cron every 1 minute.
I plan to change the script to set the time of the first and last image based on sunrise/sunset times (supplied by Cumulus) as checking the cronjob is a pain and if I forget, results in black images at the end of the day. The script will be run as a daemon.
The Pi camera is not good in low light but I must admit I haven't played around with long exposure times. I've a second camera so might do some tests with it.
Also looking at using ImageMagick to overlay some text on the image

EDIT: A bit of browsing and some testing reveals that the Pi camera can have a maximum shutter speed of 9.7 seconds at ISO 800.

Re: Raspberry Pi as a webcamera

Posted: Tue 01 Apr 2014 4:09 am
by howesij
Hi Geoff,

Thanks for that 9.7 second may just have to do.

why do you combine the images?

That would explain the ghost of a timber truck I noticed earlier today.

You can get imagemagick to detect black images but it is a bit convoluted

Re: Raspberry Pi as a webcamera

Posted: Tue 01 Apr 2014 7:13 am
by tumutbound
Hi Ian,
I started combining three bracketed images to give better cloud definition. The idea came from Karl at Bridge Lake Weather Station. He's posted about his webcam setup in these forums.
Looking at the 'standard' exposure compared to the combined one does show a slight improvement in the combined one. As it's no great problem to have the Pi do the imaging work, I'll keep doing it this way. People will just have to get used to ghost vehicles :D
You can also see something similar when there are yachts in view but in that case, you get three, distinct, overlapping images as they're seldom travelling at the same speed as the cars!

Another bit of Pi software I've just downloaded is RPi Cam Control. This one provides a web interface to the Pi camera that lets you take images, videos or timelapse sequences. You can also change any of the cameras parameters (ISO, shutter speed, AWB, etc) via the interface in real time. I've built a second camera as per the build in this thread so I'm going to run RPi Cam Control on it to see how reliable it is.

Re: Raspberry Pi as a webcamera

Posted: Tue 01 Apr 2014 11:29 am
by marfanuk
This one on Kickstarter might be worth a look if you want the ready made option...

Image

https://www.kickstarter.com/projects/18 ... y-pi-and-c

http://elsondesigns.com/pice

Re: Raspberry Pi as a webcamera

Posted: Tue 01 Apr 2014 2:55 pm
by KarlS
Luckily there are no fast moving objects in my field of view, so no "ghosts" when combining multiple images.

It might be obvious, but I mention it anyway: the default timeout between pictures is 5 seconds! You can reduce this value with the --timeout or -t parameter (in milliseconds). For example setting it to a value of "-t 500" will give you pictures at a 1/2 second interval.

My webcam is installed under a 4 foot roof overhang, so no need for weather protection. Here is my low tech housing, made out of scrap wood and masking tape :lol: :

Image

Re: Raspberry Pi as a webcamera

Posted: Tue 01 Apr 2014 10:23 pm
by tumutbound
Karl,

Thanks for the update and photo - nothing wrong with masking tape!

My camera is controlled with a python program that uses the picamera module. This drives the camera module directly and doesn't use raspitstill to take the images. I find with the settings I'm using, I can take an image in about .4 of a second.

Regards
Geoff

Re: Raspberry Pi as a webcamera

Posted: Sat 05 Apr 2014 10:53 am
by tumutbound
Bugger!
Seems a recent software update to the Pi camera, caused a problem and after a reboot, it won't restart :cry:
This means getting out the ladder and climbing up on the roof to retrieve the camera - all for a software fix! Not fond of ladders so it may be a day or two until this is done.

If nothing else this has taught me I need some way to access the camera (short of the ladder method) in case wifi stops working. As I have a spare camera, I'm currently looking at a way to have a single cable (Cat5) carry both power and a USB console connection.
I might also take the opportunity to fit a small hard disk (USB). Anything that reduces SD card access has to be a good thing.

And if that wasn't enough, my weather station has stopped reporting rain...

LATER: I've made up a 12 metre USB to TTL cable from a length of Cat6 cable and it works like a treat.! Next test is to run the 12V power over the spare pairs.

Re: Raspberry Pi as a webcamera

Posted: Mon 07 Apr 2014 11:53 pm
by howesij
HI Geoff,

Check your rain gauge for spiders,

I have to clean mine out and spray it with a surface spray every 6 months.

they build a web and trap the tipper so it doesn't report rain.

Cheers

Ian

Re: Raspberry Pi as a webcamera

Posted: Tue 08 Apr 2014 1:11 am
by tumutbound
Thanks Ian.
I'm planning a spider eviction for today. They haver started to work on the webcamera too!
I'll also take some measurements of the transmitter unit so I can make up a fan aspirated radiation shield.

Geoff

edit:Several spiders in the rain sensor and in the temperature shield All now looking for a new home :)
New lithium batteries, tested rain, wind speed/direction. Now to clean up those entries in Cumulus.