- Raspberry Pi By Example
- Ashwin Pajankar Arush Kakkar
- 839字
- 2021-07-16 11:24:22
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:

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

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

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:

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:

The following is the image with only the backlight:

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

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 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.
- Reporting with Visual Studio and Crystal Reports
- Python數據分析入門與實戰
- C語言程序設計習題解析與上機指導(第4版)
- HTML5+CSS3基礎開發教程(第2版)
- FreeSWITCH 1.6 Cookbook
- 移動增值應用開發技術導論
- 從零開始:UI圖標設計與制作(第3版)
- TypeScript 2.x By Example
- 深入解析Java編譯器:源碼剖析與實例詳解
- 玩轉.NET Micro Framework移植:基于STM32F10x處理器
- Visual C++開發寶典
- JavaScript前端開發基礎教程
- Java多線程并發體系實戰(微課視頻版)
- Head First Kotlin程序設計
- Visual C++程序設計全程指南