Hacking A Pi Camera With A Nikon Lens

Cell phones have killed many industries. It is getting harder and harder to justify buying an ordinary watch, a calculator, or a day planner because your phone does all those things at least as well as the originals. Cell phones have cameras too, so the days of missing a shot because you don’t have a camera with you are over (although we always wonder where the flood of Bigfoot and UFO pictures are). However, you probably still have a dedicated camera tucked away somewhere because, let’s face it, most cell phone cameras are just not that good.

The Raspberry Pi camera is about on par with a cheap cell phone camera. [Martijn Braam] has a Nikon camera, and he noticed that he could get a Raspberry Pi camera with a C-mount for lenses. He picked up a C to F adapter and proceeded to experiment with Nikon DSLR lenses on the Raspberry Pi camera.

You’d think the pictures would be great, right? They are good, but [Martijn] found that the Pi’s sensor actually compensates for color effects found in the little cheap lenses it would usually have. That threw the color of the shots off when used with an expensive DSLR lens. Of course, there’s plenty of color correction software.

The lenses are generally made to hit a bigger sensor, too. That means the Pi camera gets a cropped view of what a DSLR would with the same lens.

Is it practical? We don’t know what we’d use it for. But it certainly is a hack, and we like that. If you want something more practical, maybe use the Pi to control the whole DSLR. Of course, some people want more than one lens, and we know some people would find [Martijn’s] choice of lens just too modern.

66 thoughts on “Hacking A Pi Camera With A Nikon Lens

      1. Avoid? Too late to give that advice, LOL. Clickbait has become pejorative term that is used to describe web content they don’t like. While detail seem somewhat sparse, but the link Martijn’s to taken into account the tile of this post matches content. Not clickbait IMO.

  1. I think the ‘color’ issue is more about light leaks or internal reflection, he should cut out a piece of black carton or some such with an opening just enough for the sensor and put it in the mount and see if it makes a difference.
    Also since only the center of the lens is used due to sensor cropping perhaps a piece of carton with a hole in it in front of the lens might help to avoid the overblown effect?

  2. >” But it certainly is a hack, and we like that.”

    Is it?

    Putting together two store-bought parts with a store-bought adapter built explicitly for the purpose is a hack?

    Using these sensors in hobby astrophotography is quite common, hence the C-mount and the adapters.

      1. Putting together parts that are meant to be put together isn’t a hack. What do you think such a lens adapter is for? Exactly so you could put a small webcam sensor on a huge ass telephoto lens to get crazy zoom.

        Next week we’ll see a new “garden hack”: man attaches a garden hose to the kitchen sink with a purpose built adapter to water his lawn.

        1. Except they aren’t meant to be together. In fact the use of a webcam for astrophotography can be considered one of the greatest hacks of our time given the cost of CCDs at the time. So it is now only a hack the first time someone does it? Or is it only a hack until you make a part for a friend and sell it for a few quid?

          This remains a hack in my book until Nikon themselves start selling C mount adapters.

          1. It -was- a hack.

            But now you can buy kits on ebay and it’s considered business as usual. You can still hack one together yourself, but when you use a purpose made kit it’s no longer a hack. That’s the point.

            If the guy had -hacked- together a C-to-F mount adapter to connect his camera to the lens, that would have been a hack, but instead he used a store-bought adapter built and meant for the purpose, which makes it… not a hack. Connecting a lens to a camera is in itself not a hack – that’s just what lenses are for.

          2. And why would Nikon have to start selling the adapters?

            The whole point of having a standard mount is that one company doesn’t need to make every possible part to fit it. Next thing, you’ll say putting a flashlight on a picatinny rail is a hack because the company that made the gun didn’t make the adapter.

      2. The surefire way to detect if something isn’t a hack is to see if someone is already selling a kit for the purpose. That’s the point where it stops being a hack and starts being a commercially available solution to a particular problem or task. If it comes with a CE label, it’s not a hack any more than a flat pack table or a meccano set is.

        The problem with many of these “hacks” is that they’re being called hacks simply because the article author finds it novel – not because there actually are any novel or unconventional qualities to it.

          1. Then again not everyone was born knowing everything there is to know about everything. Those who suggest such persons exist can be insufferable. Before there was free web content there was not free print media that catered to various interests. They too would publish criticisms after you provided and agreed to publishing your name city and state. That media routinely covered old ground that in all likelihood was new to a portion of their readers. Tips and tricks, regardless they are label as hacks or not, do make people smarter. The hacker dogma, like most dogma (faith or otherwise) can get pretty ridiculous.

    1. Please send to the Hackaday tip line hacks that don’t use any store items or store purchased tools that where used inn construction. My guess it’s your expectation that everything that Hackaday pots be novel, Al certainly didn’t out rightly say this was novel.

  3. The only way cell phone can replace my good camera is if it can take a picture of a squirrel about 500 feet away and still be sharp enough that you can count the number of fleas on that squirrel. Canon + 500mm lens + teleconverter isn’t small enough to fit a cell phone factor while retaining image quality and probably won’t happen for about 100 years.

    1. Also when focus speed is important (sports), when low-light sensitivity is important (night sky photos), when camera speed is important, when narrow depth of field is important … phone cameras are unusable, that’s the job for the SLR camera.

    2. Just what are you after? Image quality or fleas, make up your mind.

      Bolting a Canon 500mm lens onto a Raspberry Pi would produce fleas a good 3 times in size compared to a crappy 5D mkII and it’s incredibly large pixels. Now the image quality may not be as good, but you’re definitely better off with the cellphone for counting fleas due to the small sensor size and small pixel dimensions.

  4. “Is it practical?”

    this really is a stupid comment by the author of the article. I’m working on a solar powered Pi based camera for a wood duck house and grabbing an older nikon or canon MF shorter focal length lens IMHO would work out much better than the $5 lenses that you can get on e-bay for them. This has a lot of uses not just shortsightedness from the author.

        1. It makes the whole setup rather clumsy when you use DSLR lenses which are many times larger than the camera module,and quite expensive, so in many cases it’s just physically not that practical.

          And yes you do need to chill a bit and stop acting like everybody, including the HaD author, lives to mess with you. And I remind you the author even added a question mark and is unlikely to care that you disagree and point out how some do use it in a practical manner. In fact it’s what the comment section is for, just as long as you don’t throw a fit while doing it.

  5. > Pi’s sensor actually compensates for color effects

    No. ov5647 does ZERO color processing. It is only capable of RAW output. De-bayering happens inside Pee GPU(or rather in the hidden cpu inside gpu running BLOB firmware). You can get original bits from the sensor with “raspistill –raw”.

    One of the bullshit reasons Pee/Broadcom gave for closed source MIPI and hardcoded vendor/model camera module was “debayering and color correction algorithms for this module is trade secret(!), we cant break NDA, and besides you plebs are too stupid to do color correction anyway”.
    This is also one of the reasons projects(1) that aimed to use Pee camera input as a HDMI capture failed. Not open source, and hardcoded for RAW (at least video encoder, you could still capture raw stills and decode them by hand) MIPI input :(

    1: http://www.auvidea.com/index.php/theme-styles/2013-06-22-21-23-34/raspberry-pi-hdmi-in

    1. ov5640 OTOH has de-bayering and YUV conversion built-in, as well as JPEG compression and AF control, in such a way that the GPU would only be useful to move the data from MIPI controller to RAM, i.e. as a DMA engine.

      IMHO, there are many (good?) reasons why the GPU sources are not disclosed:
      – they may contain some licensed IPs
      – they are based on a ThreadX OS that is not free, so you will have to buy it to recompile the stuff, not counting for end-user licence issues
      – they probably contain the crypto for the HDMI, something they don’t really want you to look at ;-)
      – AFAICT, only the 3D part of the GPU documentation has been disclosed, not the other stuff, including the HDMI and camera I/F

      Too bad, I would really like to hook up an ov5640 sensor with AF and play with it, but I can’t get my hands on the SCCB (aka I2C) from Linuxland :-(

      1. You could try a Freescale i.MX based board instead of the Pi – I’ve had pretty good success using the OV5640 with a HummingBoard!
        As far as I can tell the whole pipeline between the camera and video4linux is open-source (albeit not very well documented)
        That, along with the OV5640 datasheet means you can do a LOT more than what you could with a Pi!

  6. Been there, done that. I simply removed the screw-in lens from the stock pi-cam and put the module inside an analog camera body with an M42-lens attached. Got the same weird coloring in the corners. To me this looks a lot like the color shift is due to an increased infrared sensitivity, which I explained to me being due to the sensor CFA being optimized for the chief ray angle of the original lens. Nothing to do against that, except for leaving the original lens in place or removing the bayer pattern the hard way. Posted my findings over at raspberrypi.org forum back then: https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=44918&start=75

  7. Grr, I’m annoyed at those complaining “it’s not a hack”
    May I ask, where are YOUR contributions that are?

    This article certainly is very interesting, for me, I didn’t even think to connect an old SLC lens to my pi camera. Now I’m inspired to do so.

    Who cares that it’s using off the shelf components, it’s rarely done, different therfore should be here.

    1. What’s is outrageous and not mentioned is that this site is called hack a day and yet they posted 7 articles in one day!

      The nerve. Let’s just hope we can consider at least 6 of them ‘not a hack’ else we will surely suffer a collective mental collapse I fear.

  8. Snapping lego pieces together is not a hack.
    Attaching a nut designed to go onto a bolt is not a hack.
    Combining lens adapters designed for the purpose is not a hack.
    It can have a Pi or a real pie attached to it, but if the adapters were meant to be used together there is no hack sir.

  9. Two points.

    Firstly most current cameras have a UV filter fitted which will significantly affect the light wavelength distribution between lens and sensor. Then secondly alot of current SLR lenses have their chromatic aberration corrected in the camera software, or in high level software like Adobe Light room. This maybe explain colour shifts.

  10. The thrift stores (Goodwill et al.) often have several models of old camcorders. Some, particularly JVC, tend to have lens assemblies with stepping motor driven focus and zoom. Others use small geared DC motors for the same purpose. These lend themselves to acting as the optics of a Raspberry Pi camera module, for not much expense.

  11. Is it a sign that hackdom has reached its nadir when screwing a F-mount lens to a C-mount camera using an off-the-shelf C-F adapter is considered “hacking”. One can only hope.

    As soon as I hit ‘post comment’ below, I’ll head over to by blog to write a thousand word essay about how I’ve “hacked” the hackaday comments section by proffering this post.


      1. It’s a $15 adapter. this one doesn’t have optics or electronics. The cheapest dslr lens I have is $100 so how are you gonna beat that with a dslr (exept in image quality and usability)

          1. I still have tab open what was said is “he seller I bought the adapter from ony had one” everyone is SOL with that seller. I still have recommended eBay search tab open as well what is available there isn’t substantially higher priced. still looking for bottom dollar flag the search and see what come up later on, but it sound like it could be sellers market if amateur astronomers have been using them as another comment had suggested.

  12. To what degree Al was tongue in cheek I don’t know. Wrist watches are close as the closest Walmart Super Center. People ask why I still wear one. Because I don’t have to dig my phone out of my packet and a watch is readable in sunlight, generally sunny most days in Kansas or a portion of the day. phone cameras might have an affect on snapshot camera sales, not not so much with SLR camera sales. Man that video recording an object being held in one one hand with a camera held in the another hand. What are people thinking when they do that? I understand that used what he had on hand. Would be nice to see articles on contacting lens attachments for the Rapi camera. Of course we would have to grind the lenses ourselves because it or it wouldn’t be a hack you know ;)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.