Camera

A camera is a new approach for parking sensors. Using image processing and machine learning, we can detect vehicles coming in to/going out of a parking area. A camera is also useful for a vehicle's plate number detection.

If we implement a camera with a Raspberry Pi, we have many options. The Raspberry Pi Foundation makes the official camera for Raspberry Pi. Currently, the recommended camera is the camera module version 2. You can read about and buy it from https://www.raspberrypi.org/products/camera-module-v2/. You can see the the Pi Camera module V2 here:

If you are working in low light conditions, the Pi Camera module V2 is not good at taking photos and recording. The Raspberry Pi Foundation provides the Pi Camera Noire V2. This camera can work in low light. You can find this product at https://www.raspberrypi.org/products/pi-noir-camera-v2/. You can see the Pi Camera Noire V2 here:

This camera module is connected to the Raspberry Pi through the CSI interface. To use this camera, you should activate it in your OS. For instance, if we use the Raspbian OS, we can activate the camera from the command line. You can type this command:

    $ sudo apt-get update
    $ sudo raspi-config

After it is executed, you should get the following menu:

Select 6 Enable Camera to activate the camera on the Raspberry Pi. You'll get a confirmation to enable the camera module, as shown here:

After this, Raspbian will reboot.

Now you can attach the Pi camera on the CSI interface. You can see my Pi camera here:

After it's attached, it's recommended you reboot your Raspberry Pi. If rebooting is done, you can verify whether the camera on the CSI interface is detected or not. You can use vcgencmd to check it. Type this command:

    $ vcgencmd get_camera  

You should see your camera detected in the terminal. For instance, you can see my response from the Pi camera here:

For testing, we'll develop a Python application to take a photo and save it to local storage. We'll use the PiCamera object to access the camera.

Use this script:

from picamera import PiCamera 
from time import sleep 
 
camera = PiCamera() 
 
camera.start_preview() 
sleep(5) 
camera.capture('/home/pi/Documents/image.jpg') 
camera.stop_preview() 
print("capture is done") 

Save it into a file called picamera_still.py. Now you can run this file on your Terminal by typing this command:

    $ python picamera_still.py  

If you succeed, you should see an image file, image.jpg:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.31.209