官术网_书友最值得收藏!

Working with the Pi Camera and NoIR Camera modules

These camera modules are specially manufactured for Raspberry Pi and work with all the available models. You will need to connect the camera module to the CSI port, located behind the Ethernet port, and activate the camera using the raspi-config utility if you haven't already.

Note

You can find the video instructions to connect the camera module to Raspberry Pi at http://www.raspberrypi.org/help/camera-module-setup/.

This page lists the types of camera modules available: http://www.raspberrypi.org/products/.

Two types of camera modules are available for the Pi. These are Pi Camera and Pi NoIR camera, and they can be found at https://www.raspberrypi.org/products/camera-module/ and https://www.raspberrypi.org/products/pi-noir-camera/, respectively.

The following image shows Pi Camera and Pi NoIR Camera boards side by side:

Working with the Pi Camera and NoIR Camera modules

The following image shows the Pi Camera board connected to the Pi:

Working with the Pi Camera and NoIR Camera modules

The following is an image of the Pi Camera board placed in the camera case:

Working with the Pi Camera and NoIR Camera modules

The main difference between Pi Camera and Pi NoIR Camera is that Pi Camera gives better results in good lighting conditions, whereas Pi NoIR (NoIR stands for No-Infra Red) is used for low light photography. To use NoIR Camera in complete darkness, we need to flood the object to be photographed with infrared light.

Note

This is a good time to take a look at the various enclosures for Raspberry Pi Models. You can find various cases available online at https://www.adafruit.com/categories/289.

An example of a Raspberry Pi case is as follows:

Working with the Pi Camera and NoIR Camera modules

Using raspistill and raspivid

To capture images and videos using the Raspberry Pi Camera module, we need to use raspistill and raspivid utilities.

To capture an image, run the following command:

raspistill -o cam_module_pic.jpg

This will capture and save the image with name cam_module_pic.jpg in the current directory.

To capture a 20 second video with the camera module, run the following command:

raspivid –o test.avi –t 20000

This will capture and save the video with name test.avi in the current directory. Unlike fswebcam and avconv, raspistill and raspivid do not write anything to the console. So, you need to check the current directory for the output. Also, one can run the echo $? command to check whether these commands executed successfully. We can also mention the complete location of the file to be saved in these command, as shown in the following example:

raspistill -o /home/pi/book/output/cam_module_pic.jpg

Just like fswebcam, raspistill can be used to record the timelapse sequence. In our timelapse shell script, replace the line that contains fswebcam with the appropriate raspistill command to capture the timelapse sequence and use mencoder again to create the video. This is left as an exercise for the readers.

Now, let's take a look at the images taken with the Pi Camera under different lighting conditions.

The following is the image with normal lighting and the backlight:

Using raspistill and raspivid

The following is the image with only the backlight:

Using raspistill and raspivid

The following is the image with normal lighting and no backlight:

Using raspistill and raspivid

For NoIR camera usage in the night under low light conditions, use IR illuminator light for better results. You can get it online. A typical off-the-shelf LED IR illuminator suitable for our purpose will look like the one shown here:

Using raspistill and raspivid

Using picamera in Python with the Pi Camera module

The picamera is a Python package that provides a programming interface to the Pi Camera module. The most recent version of raspbian has picamera preinstalled. If you do not have it installed, you can install it using:

sudo apt-get install python-picamera

The following program quickly demonstrates the basic usage of the picamera module to capture an image:

import picamera
import time

with picamera.PiCamera() as cam:
    cam.resolution=(1024,768)
    cam.start_preview()
    time.sleep(5)
    cam.capture('/home/pi/book/output/still.jpg')

We have to import time and picamera modules first. cam.start_preview() will start the preview, and time.sleep(5) will wait for 5 seconds before cam.capture() captures and saves image in the specified file.

There is a built-in function in picamera for timelapse photography. The following program demonstrates its usage:

import picamera
import time

with picamera.PiCamera() as cam:
    cam.resolution=(1024,768)
    cam.start_preview()
    time.sleep(3)
    for count, imagefile in enumerate(cam.capture_continuous('/home/pi/book/output/image{counter:02d}.jpg')):
        print 'Capturing and saving ' + imagefile
        time.sleep(1)
        if count == 10:
            break

In the preceding code, cam.capture_continuous() is used to capture the timelapse sequence using the Pi camera module.

Note

Checkout more examples and API references for the picamera module at http://picamera.readthedocs.org/.

The Pi camera versus the webcam

Now, after using the webcam and the Pi Camera, it's a good time to understand the differences, the pros, and the cons of using these.

The Pi camera board does not use a USB port and is directly interfaced to the Pi. So, it provides better performance than a webcam in terms of the frame rate and resolution. We can directly use the picamera module in Python to work on images and videos. However, the Pi camera cannot be used with any other computer.

A webcam uses an USB port for interface, and because of that, it can be used with any computer. However, compared to the Pi Camera its performance, it is lower in terms of the frame rate and resolution.

主站蜘蛛池模板: 将乐县| 安多县| 峡江县| 金川县| 富锦市| 河北省| 西充县| 黄浦区| 改则县| 南城县| 武山县| 西和县| 克山县| 平乐县| 吉木萨尔县| 嵩明县| 永顺县| 郑州市| 喀喇沁旗| 庆云县| 清新县| 长白| 香港 | 黄骅市| 新邵县| 南宁市| 磐安县| 巴林右旗| 西乡县| 苍溪县| 保靖县| 卓资县| 遂溪县| 扶余县| 九龙城区| 三穗县| 平谷区| 宝鸡市| 松潘县| 浑源县| 沂水县|