For Christmas the girls gave me a Raspberry Pi, and for my first project I decided to try recording how bright the sunlight at our window is using an old Webcam.
The basic idea is:
- Capture a photo
- Analyse the brightness of the photo
- Log it (and eventually publish to cosm)
So first of all getting the webcam set up – My webcam is a Logitech Quickcam Express, which proved to work nicely with the Raspberry Pi, after plugging it in, it showed up straight away in the output to lsusb:
ricky@pi ~ $ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 046d:0840 Logitech, Inc. QuickCam Express
To get the photo from the webcam I used fswebcam which was simple to install (sudo apt-get install fswebcam) and use:
fswebcam --no-banner -d /dev/video0 webcam.jpg
The no-banner removes the default date and time at the bottom of the image, /dev/video0 is where the webcam appeared and webcam.jpg is the file to save the image to.
I found a python function to calculate the brightness of the image from StackExchange so put it all together and here is the python script I’m using:
os.system("fswebcam --no-banner --scale 50x50 -d /dev/video0 webcam.jpg")
im = Image.open("webcam.jpg")
stat = ImageStat.Stat(im)
r,g,b = stat.mean
brightness = math.sqrt(0.241*(r**2) + 0.691*(g**2) + 0.068*(b**2))
dt = datetime.datetime.now().strftime("%Y%m%d-%H:%M:%S")
data = '%s,%sn' % (dt, brightness)
It could be tidied up quite a bit and I’m sure there’s a way to capture the image within Python without having to write it to disk first as well. My first days readings taken every 10 minutes look something like this:
This morning I had fun doing the mini great south run with Abi, unfortunately RunKeeper crashed as we went through the start line but I think we did the 1.5k in roughly 11minutes. She had a great time and did it with a mixture of running at a good pace and then walking for a little bit until she saw too many people overtake, then she would pick up pace and dive through gaps in front of her. She enjoyed the stretch on grass much more than the road and path sections and was thrilled with her medal at the end.
This weekend just gone we celebrated our 10th Wedding Anniversary with a weekend in London (with many thanks to my parents for having Abi and Jessica to stay for the weekend. Originally we’d decided to go up to London for a short break and I booked tickets for The Lion, the Witch and the Wardrobe at the ThreeSixty Theatre in Kensington Park as a surprise for Laura for the Saturday evening.Later on we managed to get Paralympics tickets so adjusted our plans so that we could visit the Olympic Park and see some of the athletics on the Saturday morning.
We set off on Friday after work and drove up to stay in Woolwich for the night so that we could then drive in a little further and park, then get the DLR to Stratford for when the park opened. Fortunately when trying to find the Travelodge in Woolwich we took a wrong turning and found that there was a DLR station there as well and it turned out that we could leave the car in the car park there until Sunday, so we saved a lot of hassle by doing that. On Saturday morning we just checked out, walk down the road and hop on the train to Stratford – much simpler! We made it to the park entrance just before it opened and were first in the line for security so we got the park to ourselves for a short time before the crowds gathered. We made use of the time to get some breakfast (mmm waffles) and tickets to go up the Orbit after the athletics. We then had time to explore a bit more before heading into the stadium. The Olympic Park is really nicely set out with beautiful banks of wild flowers, canal-side walks and lots of space between the venues.
After time for exploring and buying a few gifts from the shop we headed to the Stadium to find our seats. Despite going in across the wrong bridge we got round to the stairs to our block easily and started the climb up to the top. At the top of the first flight of stairs we had a fantastic view through to the flame and when we entered the main seating area we saw how amazing a venue it was and the size of the place. The helpful and friendly games maker by the top of the stairs offered to take a photo of us together before we went up to our seats which was great. We made our way up more stairs to our seats, which were in a fantastic spot with a great view of the finish line and the podiums, and enjoyed watching the stadium being set up by more of the games makers.
The athletics session was fantastic and we really enjoyed watching the different events going on. I hadn’t appreciated before just how much was going on at any time from the TV as you only see one thing, but being there we could see racing on the track, the blind triple-jump final, javelin and shot put all at the same time!
After seeing the bagel making on “The Great British Bake Off” the other night, I decided it would be fun to give it a go myself. So this evening using this recipe I did…
Not quite as exciting as the ones they made on the programme, but they seemed to go well for a first attempt!