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

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.

主站蜘蛛池模板: 宜春市| 道孚县| 龙南县| 志丹县| 四子王旗| 巫溪县| 白水县| 临猗县| 台州市| 金塔县| 昌吉市| 香河县| 五大连池市| 扬州市| 平江县| 安岳县| 成都市| 大洼县| 东乌| 太谷县| 绍兴市| 定襄县| 郎溪县| 东海县| 蒲城县| 新龙县| 延边| 桃园县| 胶南市| 乌拉特前旗| 工布江达县| 镇江市| 浦城县| 萨嘎县| 页游| 苍山县| 申扎县| 霍林郭勒市| 吴川市| 大荔县| 遵义县|