User avatar
jbeale
Posts: 3512
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

making a true day/night camera for RPi

Mon Feb 08, 2016 5:05 pm

In case of interest. With the RPi camera you have a choice: normal camera (with good color response) or Pi No-IR that can work at night with IR lights, but has poor color rendition and a bit less sharp / contrasty overall. Typical "security camera" models use an IR filter that can be physically switched out at night and in during the day, for the best of both worlds.

I was thinking about making my own IR-filter-switcher using a hobby servo, but then found another way. I used these parts:

http://www.ebay.com/itm/291404350105 "OV5647 NoIR Camera Board /w M12x0.5 mount" ($30)
http://www.ebay.com/itm/400938137287 "IR CUT M12 Mount Lens 8Mp HP Dual Filter Switcher" ($4)
http://www.m12lenses.com/8-0mm-F1-8-Meg ... 0818mp.htm "PT-0818MP 8.0mm, F1.8 Mega Pixel CCTV Board Lens" ($15)
http://www.mcmelectronics.com/product/83-16530 "Raspberry Pi 2" ($35 + shipping)
H-bridge driver for bipolar 100 mA pulse at 5 V ($?)

The ebay M12-lens-mount NoIR camera board comes with its own lens, but that one has a short "back-focus" distance so it is not compatible with the IR CUT switcher/ lens holder that slides the filter in between the lens and sensor. You need a lens with more clearance between sensor and rear element. The 8mm lens I chose from m12lenses.com works, but some others (especially wide-angle types) may not. You have to unscrew the lens mount that comes on the camera board and replace it with the IR CUT switcher mount. I've assembled this and confirmed it does work (haven't yet built the H-bridge driver for auto-switching the filter).

Just FYI, this assemble-it-yourself idea is not an amazing value. So far I have not found a M12 lens that is as good (eg resolution / contrast / distortion) as the tiny built-in lens the official RPi camera comes with, although they are usually brighter (like f/1.8 instead of f/2.9). I add up a cost of $84 including the $35 Pi without shipping or memory card (and not including the H-bridge driver) and just for comparison, you can get a working day/night IP camera board module with 1/2.5'' Aptina 9P006 5MP sensor and lens, listing for $82. http://www.securitycamera2000.com/produ ... -View.html
(but of course an IP camera still needs a separate external computer to actually record the video.)

On the plus side for the Pi approach, the camera part by itself is somewhat smaller, and with something like PiKrellCam software for motion detection and the whole Pi software & hardware environment you have much more flexibility on configuring a system.

User avatar
rleyden
Posts: 71
Joined: Thu Jun 14, 2012 2:17 am

Re: making a true day/night camera for RPi

Tue Feb 09, 2016 4:15 pm

jbeale- Nice concise post on this topic..
I went through a similar process which I previously posted ( output examples: https://goo.gl/photos/kPNWrZ3C56eqL7Ug9 )
I agree with all of your conclusions. I am bothered by the seemingly poor relative value of my Rpi creations. I get satisfaction from understanding and building custom solutions, so I'm not at all driven by cost. Yet it's "fun" to drive the cost as low as possible. I have 4 Rpi critter/security cams which serve me well. Yet I also have a IP cam purchased on eBay for $40 including shipping that takes remarkably clear, crisp, color correct day images and useful IR illuminated night images (better low light sensitivity than the noir cam). Auto IR cut-in filter is included as well as tilt-pan, local storage on micro SD, wifi, built-in IR-LED's, web interface -w/motion detection a mount and a housing (packaged more compactly and attractive than I could ever hope to do). To recreate those features on the RPi probably costs close to $200.
Despite all the wonderful hardware the motion detection on the commercial IP-cam is brain dead compared with PiKrellCam software so I rarely even check it. So, what's my point? Not sure. I guess welcome to ala carte electronics.

User avatar
jbeale
Posts: 3512
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: making a true day/night camera for RPi

Tue Feb 09, 2016 5:48 pm

True, the commercial security cam is pretty impressive with what they fit into a relatively small and cheap package. The modern 5 MPixel type is good; I also tried a 1.2 Mpixel type supposedly good for low light but the image quality was dismal. One thing I don't like is the built-in IR LEDs, in many cases they are not powerful enough, and besides they can attract insects near the lens. I like using separate lights such as this kind http://www.amazon.com/gp/product/B00M3O5ERK
If you use two lights a good distance apart with the camera right in between them, you get much more even lighting, then you can see detail both near and far instead of close-by objects going saturated-full white.

With the RPi camera you are always struggling for low-light sensitivity, so with a 360 degree shutter angle at 24 fps any motion becomes blurred due to the 43 msec exposure on each frame. I modified the above-mentioned IR lights with an Arduino mini + power FET each to be strobe lights with 3 msec long pulses at 23.04 Hz (which turns out to be the actual frame rate that PiKrellCam calls "24 fps") and in this way I get much better stop-motion detail on moving objects at night. You might say, why not leave the lights as-is and just specify a 3 msec shutter, yes true but "other things are not equal". Specifically, I can drive the IR LED array (6x LEDs wired 3S2P) using 3 A pulses instead of the normal 1 A DC current for more useful light, but since they are now running at 7% duty cycle, they use only (3*0.07) or 1/5 of the original power, and are not as bright visually. It would be perfect if I could synchronize my light to the RPi camera frame start, but I haven't figured out that part yet. It works OK as-is, there is just one region of most frames that has a double-exposure appearance where one rolling-shutter frame starts and another one is ending at the moment the IR strobe goes on.

User avatar
jbeale
Posts: 3512
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: making a true day/night camera for RPi

Sun Feb 21, 2016 8:30 pm

I added a circuit to auto-switch the filter using an Arduino measuring ambient light level with a CdS photoresistor, and a Pololu DRV8835 H-bridge running off the same +5V as the Pi to pulse the solenoid in each direction for day / night mode. This works, but I notice that the focus shifts inward noticably in "night" mode, suggesting that the optical path length through the IR-pass (clear glass) is longer than through the IR-Cut (filter glass).

Example video- look at the relative focus on the more distant roof at lower right, vs. the foreground tree. https://youtu.be/Z4e0AIpzAxY

User avatar
jbeale
Posts: 3512
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: making a true day/night camera for RPi

Thu Mar 03, 2016 7:17 am

For what it's worth, I got the 5Mpixel IP camera. It took a few weeks to get here. http://www.ebay.com/itm/261441929903
Haven't done anything careful to compare but at first glance, I think the IP camera is better in low light, but the RPi image is actually better in daylight, even with a cheap M12 lens on it (the color fringing is less annoying to me than the incompetent debayer algorithm in the IP camera). The IP camera runs about 200 mA at 12 V, so that's 2.4 watts; I think similar to a Pi streaming from a camera. The IP cam can do H.264 with 5 Mpixel (2592 x 1920) at 10 fps or 3 Mpixel at 15 fps, so that's beyond the Pi spec, but as we know mere pixel count isn't the whole story.

UPDATE: with a sufficiently good lens, the IP camera does have a somewhat better image; BUT this was a $240 lens + $100 camera and it still requires another computer to actually record the video, and you don't have as much control over camera settings, or motion detection as good as PiKrellCam. For price/performance I still think the RPi wins big.

User avatar
owntheweb
Posts: 24
Joined: Tue Jun 16, 2015 1:51 am
Location: Colorado, USA
Contact: Website

Re: making a true day/night camera for RPi

Sun Aug 28, 2016 3:03 am

interest = TRUE; :geek:

I was looking into RPi security camera solutions and was kicked in the knees when a friend showed me his cheap live-steaming, motion detecting, IR "night vision" mode, push-to-talk through app network of multiple cameras. I still want to interact with my home security in some way, likely on the software/online storage side. This post gives me hope.

I'm thinking that I will have a single RPi manage photo uploads from IP cameras, stream locations and/or web access. I don't really like the idea of connecting directly to my home, so I'm thinking a socket server solution that acts as a middle man would be "good" (potentially troublesome as well). We'll see.

For now, I think I can focus on a non-RPi camera hunt! Thanks for posting your notes.
Worlds to explore. Worlds to create.

Return to “Camera board”