{"id":7181,"date":"2020-07-11T15:02:46","date_gmt":"2020-07-11T19:02:46","guid":{"rendered":"https:\/\/dronebotworkshop.com\/?p=7181"},"modified":"2023-04-12T10:29:59","modified_gmt":"2023-04-12T14:29:59","slug":"pi-cameras","status":"publish","type":"post","link":"https:\/\/dronebotworkshop.com\/pi-cameras\/","title":{"rendered":"Raspberry Pi Cameras – the BIG Picture"},"content":{"rendered":"\n
<\/a> <\/a> <\/p>\n If you\u2019ve ever wanted to know anything about the Raspberry Pi Camera then you\u2019re in the right place!\u00a0 We\u2019ll see what cameras are available, how they work, and how to use them with the Raspberry Pi.<\/span><\/p>\n With a camera CSI connector available on every Raspberry Pi, including the 5-dollar Raspberry Pi Zero, incorporating a camera into your next project couldn\u2019t be simpler.<\/span><\/p>\n In 2013 the Raspberry Pi Organization released its first Raspberry Pi camera.\u00a0 Unlike USB cameras this camera had a connection direct;ly to the board’s GPU, providing improved performance while reducing costs.<\/span><\/p>\n <\/p>\n Since then the camera has become a standard fixture on the Raspberry Pi and thousands of projects have been built with them.<\/span><\/p>\n The Raspberry Pi Organization has released a couple of other cameras, the latest one just recently. In addition several manufacturers also make cameras for the Raspberry Pi, and they range in cost from about 5 dollars upwards.<\/span><\/p>\n The history of the camera is a long one, with some of the essential principles dating back to around 400 BC.\u00a0 The first photographic cameras were developed in the 18th century, and the first motion picture cameras were created in the late 1800s.\u00a0<\/span><\/p>\n <\/p>\n Digital cameras replaced traditional photographic film with digital sensors, arranged in an array. The individual elements of this array are called \u201cpixels\u201d, and they represent a red-green-blue value of the light level falling upon them.<\/span><\/p>\n <\/p>\n The more of these pixels in the array, which is mounted on a substrate called the \u201cframe, the better the quality the picture will be. A larger frame also adds to the quality.<\/span><\/p>\n Unlike conventional cameras, there is no need for an actual mechanical shutter on a digital camera. And most are capable of being used for both still images and video.<\/span><\/p>\n The sensors used for the Raspberry Pi cameras are common devices manufactured for phones and tablets, so they are very inexpensive.<\/span><\/p>\n The folks at Raspberry Pi have released three cameras so far.<\/span><\/p>\n The first Raspberry Pi Camera was the version 1 camera. It used an OmniVision OV5647 sensor and had a resolution of 5 megapixels.<\/span><\/p>\n <\/p>\n The camera is available in two versions.<\/span><\/p>\n This camera is no longer sold by Raspberry Pi, however, it is still readily available from other manufacturers, often for as little as 5 US dollars. Look on Amazon or eBay and you\u2019ll have no trouble finding them.<\/span><\/p>\n This 8-megapixel camera uses the popular Sony IMX219 sensor.\u00a0 As with its predecessor, it is available with or without an infrared filter.<\/span><\/p>\n <\/p>\n This is still available from Raspberry Pi as of this writing. Again there are several similar and improved products from other manufacturers.<\/span><\/p>\n The Raspberry Pi High-Quality (HQ) Camera is a different design than previous modules. Unlike its predecessors, this camera comes as a base sensor unit capable of using type C or type CS lenses.\u00a0<\/span><\/p>\n <\/p>\n The camera module is very rugged and it is mounted on a frame that accepts a standard \u00bc-inch tripod thread.\u00a0 It uses the same flat film cable that the other Raspberry Pi cameras use.<\/span><\/p>\n As of this writing, Raspberry Pi offers two lenses for the camera.<\/span><\/p>\n As the camera can accept type C or type CS lenses you may also use lenses manufactured by third parties, in fact the two lenses offered by Raspberry Pi are actually manufactured by CGL Electronics.<\/span><\/p>\n Lenses with compatible threads are often used in the Scientific and Surveillance industries.<\/span><\/p>\n I purchased an HQ Camera and a 16mm C-mount lens when they were first released, at the time I was not able to obtain a 6mm CS\u2011mount lens.<\/span><\/p>\n This camera uses a 12.3 megapixel Sony IMX477 sensor, whose 1.55\u03bcm \u00d7 1.55\u03bcm pixel size is double the pixel area of IMX219 used in the V2 Cameras.<\/span><\/p>\n The design of this camera will provide superior low-light performance over its predecessor, and by using an external lens you can drastically improve upon the optics.<\/span><\/p>\n This camera can find uses in photography, surveillance, astronomy, AI, and a wealth of other applications where high-quality images are required.<\/span><\/p>\n The Raspberry Pi High-Quality Camera retails for 50 US dollars, which is double the retail price of the official V2 Camera.\u00a0 And on top of that, you need to factor in the cost of the lens, adding the 62-dollar 16mm C-mount lens more than doubles the camera price again.<\/span><\/p>\n So is the camera worth its relatively high price? Only one way to find out, let\u2019s hook one up and compare it to a few other cameras.\u00a0 We\u2019ll be doing that shortly.<\/span><\/p>\n Unlike the previous Raspberry Pi cameras, this new camera requires some assembly before you can use it.<\/span><\/p>\n The first step is to install a lens.<\/span><\/p>\n The camera is packed in a tiny box that includes a tiny screwdriver for locking the lens assembly in place. The module has a type C-mount thread, and it includes a type CS adapter ring as well as a threaded cap.<\/span><\/p>\n <\/p>\n I am pairing the module with the 16mm C-mount telephoto lens, an impressive-looking device that is well-packaged and has covers for both ends.<\/span><\/p>\n The lens threads securely on to the camera module. Tighten everything securely by hand, but don\u2019t overtighten.<\/span><\/p>\n You\u2019ll want to be sure that everything is clean when you put it all together, a photographer’s dust blower bulb and lens brush can come in handy. Be sure to save all of the camera and lens covers.<\/span><\/p>\n As a finishing touch, you can use the \u00bc-inch thread to mount everything on a small desktop tripod.<\/span><\/p>\n Of course, there are many other manufacturers producing cameras for the Raspberry Pi, and some of them are pretty innovative.<\/span><\/p>\n <\/p>\n Most of these cameras use the same 5 and 8-megapixel sensors used on the original Raspberry Pi cameras, this ensures complete compatibility.<\/span><\/p>\n Some of the 3rd party cameras are essentially clones of the original designs, usually priced much more competitively. Version 1 cameras (5 megapixels) can often be obtained for around 5 US dollars, making them ideal for a number of exciting projects and applications.<\/span><\/p>\n Other models use external lenses, often M12 or CS-mount designs, for improved performance or for special applications.\u00a0 M12 lenses are particularly popular and you can obtain kits of these lenses to allow you to select the perfect one.<\/span><\/p>\n Some other enhancements include IR light sources for night vision applications.<\/span><\/p>\n One camera I added to the test was the Arducam 8-MP Sony IMX219 camera with a CS-mount lens.\u00a0<\/span><\/p>\n This camera uses the same sensor as used by the Raspberry Pi camera version 2, with the addition of a CS-mount lens.\u00a0 The module itself is substantially larger than the original Raspberry Pi cameras.<\/span><\/p>\n This is a way of \u201cupdating\u201d an existing Raspberry Pi V2 camera, it can also be used to repair a camera whose module was damaged.<\/span><\/p>\n This is NOT a complete Raspberry Pi camera, rather it is a replacement for the Sony IMX219 module on the camera.\u00a0 It\u2019s the same sensor with improved optics, in this case, a 160-degree field of video lens is supplied. As the lens uses the M12 thread you can substitute other lenses.<\/span><\/p>\n I used this to resurrect a Version 2 module whose lens had been scratched.<\/span><\/p>\n All of the Raspberry Pi cameras use a 15-pin flat ribbon cable to attach the camera to the microcomputer.\u00a0<\/span><\/p>\n The Camera port on your Raspberry Pi board will vary in location depending upon which model you are using. Raspberry Pi Zero users will require an adapter cable, as these microcomputer boards use smaller camera connectors.<\/span><\/p>\n Of course, it probably goes without saying that you should power off the Raspberry Pi before connecting or disconnecting the camera!<\/span><\/p>\n The cable can be connected and disconnected on both ends, and you can replace the cable supplied with the camera with a longer or shorter one if you wish. Camera cables are available in a variety of lengths.<\/span><\/p>\n <\/p>\n The cable has conductors on only one side. On the camera end these conductors should face the camera module circuit board.\u00a0 On the Raspberry Pi side you\u2019ll need to observe the correct orientation of the cable, on the Model 4 the non-conductive side faces the USB and Ethernet connectors.<\/span><\/p>\n The connectors are tiny but quite easy to use, you pull up on the mounting tab to open them and snap it down to secure the cable.\u00a0 Make sure you orient your cable properly before snapping it down and don\u2019t pull on the mounting tab too hard as it breaks easily.<\/span><\/p>\n If you haven\u2019t used a camera with your Raspberry Pi before then you\u2019ll need to enable it first in the operating system.<\/span><\/p>\n Power up the Pi with the camera attached, it should boot normally.<\/span><\/p>\n Now click on the \u201cRaspberry\u201d icon on the top left menu bar to open the main menu. From this menu select \u201c<\/span>Preferences<\/span><\/i>\u201d and from the resulting sub-menu select \u201c<\/span>Raspberry Pi Configuration<\/span><\/i>\u201d.<\/span><\/p>\n In the Configuration box select the Interfaces tab. You\u2019ll observe a list of interfaces along with radio buttons to enable or disable them.<\/span><\/p>\n <\/p>\n One of the first items is Camera<\/em>. If it is disabled click the radio button to enable it.\u00a0 After doing this click the OK button to save your selection.<\/span><\/p>\n You\u2019ll need to reboot your Raspberry Pi to have the change take effect, so go ahead and do that now.<\/span><\/p>\n After rebooting, open a Terminal session by clicking on the Terminal icon on the top menu bar.<\/span><\/p>\n At the command prompt type the following:<\/span><\/p>\n If all is working you\u2019ll see a camera preview that will cover most of your desktop. You can move the camera around or adjust its focus. After five seconds the Raspberry Pi will capture an image and then shut the preview off.<\/span><\/p>\n <\/p>\n After you capture an image, open up your File Manager. You should be in your Home directory, and as that’s the same directory you were using in the Terminal window you should now see a <\/span>test.jpg<\/span><\/i> file.<\/span><\/p>\n Click on the <\/span>test.jpg<\/span><\/i> file to open it, and you’ll view a picture taken by your Raspberry Pi camera.<\/span><\/p>\n If you run the command again without editing it you’ll overwrite the existing picture, without warning.\u00a0 In order to prevent this change \u201ctest.jpg\u201d to \u201ctest2.jpg\u201d or something else that is unique.<\/span><\/p>\n Now that we have determined that we have a working camera let\u2019s explore a bit more how to use it.<\/span><\/p>\n Note that all of the commands and instructions here will work with any Raspberry Pi Camera, they aren’t limited to the High Quality Camera.<\/span><\/p>\n You should already have a Terminal window open, if not then open one now by clicking the icon on the top menu bar. You’ll be at a command prompt in your Home directory when it opens.\u00a0 This is called the CLI, or Command Line Interface.<\/span><\/p>\n We have already used the raspistill utility in the CLI to take a picture with our camera.\u00a0 We did it by issuing the following command:<\/span><\/p>\n We essentially told raspistill to produce an output (<\/span>-o<\/span><\/i>) named <\/span>test.jpg<\/span><\/i>. It gave us a five second preview and then did exactly that.<\/span><\/p>\n If five seconds wasn\u2019t enough time to get everything in focus we can extend it as long as we want using a \u201c<\/span>-t\u201d<\/span><\/i> parameter. Something like this:<\/span><\/p>\n The \u201c<\/span>-t<\/span><\/i>\u201d parameter is the preview time in milliseconds, so the above command should give us 20 seconds to get the perfect picture.<\/span><\/p>\n Another common issue is that our camera may be upside down or sideways. We can rotate it with the \u201c<\/span>-rot<\/span><\/i>\u201d parameter:<\/span><\/p>\n This turns the image upside down, as \u201c<\/span>-rot<\/span><\/i>\u201d is the rotation in degrees.<\/span><\/p>\n You can also do a horizontal or vertical flip with the \u201c-hf\u201d and \u201c-vf\u201d parameters. Useful when requiring a mirror image. Here are both in one command:<\/span><\/p>\n You may also specify the size parameters of the output image as follows:<\/span><\/p>\n An example is this:<\/span><\/p>\n These are just some of the many parameters you can pass to raspistill. For a full list just type:<\/span><\/p>\n The raspivid utility is another CLI utility for working with the camera. This utility, as its name implies, works with video.<\/span><\/p>\n Try this out at the command line:<\/span><\/p>\n This should record a video about three seconds long. To change the length of the video recording you may use the \u201c<\/span>-t<\/span><\/i>Introduction<\/span><\/h2>\n
How Cameras Work<\/span><\/h2>\n
Original Raspberry Pi Cameras<\/span><\/h2>\n
Camera v1<\/span><\/h3>\n
\n
Camera v2<\/span><\/h3>\n
Raspberry Pi High-Quality (HQ) Camera<\/span><\/h2>\n
\n
Adding a Lens<\/span><\/h3>\n
Other Raspberry Pi Cameras<\/span><\/h2>\n
Arducam 8-MP Sony IMX219<\/span><\/h3>\n
SainSmart IMX219 Camera Module with Lens<\/span><\/h3>\n
Raspberry Pi Hookup<\/span><\/h2>\n
Raspberry Pi Configuration<\/span><\/h2>\n
Testing the Camera<\/span><\/h3>\n
raspistill -o test.jpg<\/pre>\n
Using the Camera<\/span><\/h2>\n
Using the Camera from the Command Line<\/span><\/h3>\n
The raspistill Utility<\/span><\/h4>\n
raspistill -o test.jpg<\/pre>\n
raspistill -t 20000 -o test-time.jpg<\/pre>\n
raspistill -rot 180 -o test180.jpg<\/pre>\n
raspistill -hf -vf -o testflip.jpg<\/pre>\n
\n
raspistill -w 1920 -h 1080 -o testHD.jpg<\/pre>\n
raspistill --help<\/pre>\n
The raspivid Utility<\/span><\/h4>\n
raspivid -o testvideo.h264<\/pre>\n