Raspberry Pi Camera Options and Usage

게시자

Raspberry Pi single-board computers have revolutionized what creators can make and do with electronics, and one of the more interesting features they bring to the table is their ability to take and process images. Pi boards feature a connector for their own Pi camera ― or compatible generic versions ― but it's also possible to use a generic webcam to acquire images or video.

Fortunately, you have a wide variety of cameras to choose from for your Pi setup. To cover the basic camera categories, we'll be looking at: 

1. Raspberry Pi camera version 2

2. C270 webcam from Logitech 

3. Generic Raspberry Pi NoIR camera capable of functioning at night

Testing Raspberry Pi Cameras

For this experiment, I tested out the three cameras on a Raspberry Pi 3A+, loading Raspbian via the NOOBS Lite network installation. The Raspberry Pi Foundation covers the NOOBS installation well, and once you've got your OS set up, you can plug in and try out the webcam. Note that the Pi Camera with its ribbon cable assembly isn't meant to be hot-swapped, so before trying out the Pi camera or generic versions, be sure to shut the system down.

Raspberry Pi Camera V2 Features

Image: Jeremy S. Cook

The original Pi Camera was the Raspberry Pi's first official accessory in 2013, and in 2016, the v2 (or v2.1 to be precise) was released with a new sensor and better specs. The V2's sensor is the Sony IMX219, which features:

Smartphone-like 4.60mm sensor size
Resolution of 3280 x 2464 for still images 
Up to 1080p in video mode at 30 frames per second 
Capability to record frame rates at lower resolutions if needed 
Horizontal field of view of 62.2 degrees 
Vertical field of view of 48.8 degrees

How to set up your Raspberry Pi camera

Image: Jeremy S. Cook

To set up the camera, follow these steps:

1. Type "sudo raspi-config" in the terminal. 

2. Select Interfacing Options.

3. Turn off your Raspberry Pi camera using the text-based menu. You can also do this graphically by clicking on the raspberry icon, selecting Preferences, and Raspberry Pi Configuration. 

4. Under the Interfaces tab, click on "Enabled" for the camera, then hit OK. 

5. The graphical interface will ask if you want to restart to allow the changes to take effect, which is a good opportunity to shut down and plug in the camera if you haven't done so already.

6. Once you shut down, pop open the camera ribbon connector on the Pi, slide the ribbon in with the blue tape facing the black top piece, then push down to connect. Restart, and the Pi camera will be ready to go. 

Well, almost ready.



The Pi camera just needs a couple more steps to get it taking good images. 

1. Remove the protective film from the lens, then place the white circular device (which you can see on the far right-hand side of the image on page one) over it, and adjust thedevice's focus as needed. 

2. Per Raspberry Pi's instructions, open the included Python 3 development environment, open a new file, and save it as camera.py (NOT pycamera.py — apparently that's a different and quite important program). 

3. Enter the following code, save it by hitting ctrl-S, and run it with the F5 key:

from picamera import PiCamera
from time import sleep

camera = PiCamera()

camera.start_preview()
sleep(10)
camera.stop_preview()

You'll be presented with a camera image, which you can adjust as needed. This might seem like an unnecessarily convoluted solution for getting an image preview, but it's not that complicated. If you need more time to set your camera you can always increase the number after sleep to however many seconds you desire.



Once it's time to take photos, you can use the terminal command "raspistill." You can add various modifiers to that command to change different image settings, such as:

"raspistill -o picamtest1.jpg" will save an image named 'picamtest1.jpg' to your home/pi directory — notably overwriting anything else with that name without warning.
"raspivid -o testvid.h264 will record five seconds of video to your home/pi directory. 
If you need more time, you can add a modifier, for something like raspivid -o video.h264 -t 1000, where 1000 is the recording time in milliseconds. 

Notably, these command line options facilitate scripting and offer you more granular control of the device than you could normally expect from traditional webcams.

How to set up a Raspberry Pi webcam

Pairing a webcam with the Raspberry Pi is extremely easy if your goal is to capture an image. Here's how to set it up: 

1. Plug the web camera into a USB port and open the VLC media player.

2. Select Media > Open Capture Device. 

3. Select the webcam, then hit play. Once you select the proper device from the list, an image should appear.

4. Select Video > Take Snapshot to get an image out of the VLC Media player, which will be automatically stored on home/pi/Pictures. 

5. You can also select View > Advanced Controls to add a video record button which allows you to capture video on home/pi/Videos, and adds as a snapshot button to keep that within easy reach. 

One note here: while it seems possible for the Pi camera and webcam to coexist, if you're having issues, you may want to try this with only one camera at a time.

Image: screencap using the VLC media player

Here's how to use the webcam via the terminal: 

1. Install a program called fswebcam by inputting "sudo apt-get install fswebcam". 

2. Once complete, and assuming you don't have any other capture devices connected, enter "fswebcam yourimage.jpg" to capture an image and create a name for the file.

Like the raspistill command, you can add modifiers to change output settings.

Caption: Images stored in /home/pi

If you have more than one camera installed, such as the official Raspberry Pi unit, you'll need to tell the board which camera to use. 

1. In the terminal, first type in ls /dev/ to see what devices are present.

2. Enter a command like "fswebcam --device /dev/video1 yourimage4.jpg," where video1 (or another device) dictates which attached camera you're using.

In the photo below, you'll see an image from the Logitech C270 720p webcam that we used in this experiment with fswebcam. As noted in Raspberry Pi's webcam documentation, "The quality and configurability of the camera module is highly superior to a standard USB webcam." 

But at around $20 per item, this device could be a budget-friendly option depending on your project's specific needs. Some of the higher-end webcams available may have a quality advantage over the Pi's official offering.

Generic Raspberry Pi NoIR Camera

Besides the standard Raspberry Pi V2 camera, there is also a version with no infrared sensor, which gives it the moniker "NoIR." We'd expect roughly the same performance out of this camera as the normal V2, though perhaps with a different tint to the photos. For our last camera review, however, we're testing out a generic NoIR camera that uses the OmniVision OV5647 sensor — the same as what is on the original Pi camera.

As such, the Raspberry Pi NoIR captures images in 5MP and is capable of 1080p video. It also comes with a pair of IR illuminators that straddle the camera and an adjustable lens. Fully assembled, illuminators come on automatically when the lights go dim, and you can use a screwdriver to adjust sensitivity on what appears to be a set of small tuning resistors.

You can expect the same setup as the normal V2 Pi camera, though when shopping for a non-pi product, pay special attention to the sensor and megapixel ratings. We're not sure how the NoIR stacks up against its official cousins as far as official specs, but as you can see in the pictures below, it's capable of capturing sharp images, both under desk lighting and using its illuminator in the second image. Interestingly, the red switch cover appears nearly clear under infrared lighting:



Whether you need high resolution images from the official Pi camera, low-light capture from a NoIR camera or you have an unused webcam you'd like to try out, the Raspberry Pi has much to offer. Once you've selected and installed your device, there is a wide range of use possibilities, from time-lapse photography to security systems, and even image processing via OpenCV.

최신 뉴스

Sorry, your filter selection returned no results.

개인정보 보호정책이 업데이트되었습니다. 잠시 시간을 내어 변경사항을 검토하시기 바랍니다. 동의를 클릭하면 Arrow Electronics 개인정보 보호정책 및 이용 조건에 동의하는 것입니다.

당사의 웹사이트에서는 사용자의 경험 향상과 사이트 개선을 위해 사용자의 기기에 쿠키를 저장합니다. 당사에서 사용하는 쿠키 및 쿠키 비활성화 방법에 대해 자세히 알아보십시오. 쿠키와 추적 기술은 마케팅 목적으로 사용될 수 있습니다. '동의'를 클릭하면 기기에 쿠키를 배치하고 추적 기술을 사용하는 데 동의하는 것입니다. 쿠키 및 추적 기술을 해제하는 방법에 대한 자세한 내용과 지침을 알아보려면 아래의 '자세히 알아보기'를 클릭하십시오. 쿠키 및 추적 기술 수락은 사용자의 자발적 선택이지만, 웹사이트가 제대로 작동하지 않을 수 있으며 사용자와 관련이 적은 광고가 표시될 수 있습니다. Arrow는 사용자의 개인정보를 존중합니다. 여기에서 당사의 개인정보 보호정책을 읽을 수 있습니다.