Wednesday, 15 July 2015

PiCam: replacing the RaspiCam lens

I wanted to get a closer view of the robins nesting in my garden shed.

So I decided to replace the standard RaspiCam lens on my PiCam with an M12 threaded lens.

This is the third time I've carried out this modification, and I still have a 100% success rating!

As mentioned earlier, I have deployed my portable PiCam inside our 6' x 4' shed where a pair of robins are currenlty nesting and feeding an unknown number of chicks (probably 4 or 5).

I was hoping for 2 potential benefits by carrying out this mod; 1) the ability to select a lens with a longer focal length, 2) maybe the image quality would be better.

The longer focal length means that the robins would fill more of the image frame without the need to move the camera any closer to the box. Currently the camera is about 21" from the face of the nest box.

I modified the RaspiCam board basically using the same procedure as before but with a couple of variations. I used a metal M12 lens mount from Sourcingmap. On the previous 2 occasions I've used one metal mount and a hard plastic mount from StockOptics.

The plastic mounts are slightly easier to modify than the metal bodied ones, and there is no risk of short-circuiting anything on the RaspiCam board. However the metal mounts have 2.5mm threaded holes, which I used this time around to attach the lens assembly to the box.

Attaching the camera to the box

The mount hole pitch (20mm) was not quite right for the pcb, so I applied some gentle persuasion on the pcb holes with a circular needle file (don't try this at home!) which allowed the fixing screws to poke through the pcb holes and align the mount to the board.

Rather than use hot-melt glue, I used a layer of Araldite (twin pack) to fix the metal mount to the RaspiCam pcb, then left it to cure for 12 hours.

The following day I connected the camera module back to my PiCam and a 12V battery, then worked my way through a small bag of lenses looking for the longest focal length lens.

The image with the new lens still looks "pastey" or "washed-out", so once I had the focus about right I took some pictures using RaspiStill.

I also took a picture with my Pentax K30 for comparison (...I know, that's just not fair!).

RaspiStill Vs. Pentax K30

Opening them both in Gimp and looking at the histogram, reveals the reason for the washed-out look.

RaspiStill Histogram (left) shows limited range of pixel values

For the RaspiStill image, the histogram is not spread over the full available range. Therefore the contrast is poor compared to the Pentax image.

Just by using the Gimp Auto-Level feature on the RaspiStill image, the picture looks much better.

I now wish I'd taken some still images for comparison before removing the standard Pi lens!

When I've finished using PiCam to snoop on the robins, I will investigate this further. I know this problem is not due to lens flare (i.e. light entering the lens outside the field of the picture) as I made a simple lens hood from a piece of black tubing.

The starting point will be to upgrade Raspbian as this is now over 12 months old, so there may have been some camera software improvements during the last year or so.

I may also need to play around with the RaspiStill (and RaspiVid) contrast (to spread the pixels across the histogram) and brightness (to centre the histogram).

It has been a bit of a grey afternoon so the shed has been in darknest, but this shot at least shows that I get closer to the birds with this longer focal length lens.

No comments:

Post a Comment