Your shopping cart is empty!
Raspberry Pi Zero W and Pi Camera Application
Last Updated on 4 Febuary 2018 This article is written by internship student Ezyan Roshdi
Previously, we have introduced you to the Raspberry Pi Zero W. You may refer to this tutorial for the introduction of the Raspberry Pi Zero W. In this tutorial, we are going to learn about how to use Raspberry Pi Zero W together with Pi Camera and OpenCV applications.OpenCV stands for Open Source Computer Vision. It is a library of programming functions mainly for real-time computer vision. This library is open-source under the open-source BSD license.
HARDWARE REQUIREMENT
SOFTWARE REQUIREMENT
- Python.
- OpenCV
STEPS
1. Update and upgrade the raspberry pi before installing anything else.
In the terminal, run these commands:- sudo apt-get update
- sudo apt-get upgrade
- sudo rpi-update
2. Enable the camera interface.
Run the command sudo raspi-config . Then go to interfacing option, camera and enable the camera. You need to reboot your Pi after doing this.3. Test the camera by running the command raspistill -o image.jpg
Where the "image" is your picture's name. If the red LED on the camera turns on and your image is saved, it means your camera is functioning well.4. Install the necessary packages to use OpenCv inside Raspberry Pi.
OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real-time computer vision. To do so, run all these necessary commands :Install python 2.7.9 version using command:sudo apt-get install python2.7-devInstall the python wrapper for OpenCV (imutils is a set of convenience functions to make basic image processing tasks easier):
sudo apt-get install python-opencv sudo pip install imutilsOpenCV process images:
sudo apt-get install libtiff5-dev libjasper-dev libpng12-devOpenCv process video:
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-devGTK library for some GUI (graphical user interface) stuffs like viewing images:
sudo apt-get install libgtk2.0-devfor various operations in OpenCV:
sudo apt-get install libatlas-base-dev gfortraninstall pip (tool for installing and managing Python packages):
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.pyinstall numpy (fundamental package for scientific computing with Python):
sudo pip install numpyinstall this file to get the latest opencv:
wget "https://github.com/jabelone/OpenCV-for-Pi/raw/master/latest-OpenCV.deb" sudo dpkg -i latest-OpenCV.debTest if it has been installed correctly by running the command:
python import cv2 cv2.__version__(this command should return the version of OpenCV you are using)
5. Now that we have OpenCV installed, lets try some simple code to try the Pi Camera with OpenCV. But first, you need to run this command :
sudo pip install "picamera[array]"We need the "array" sub-module so that we can utilize OpenCV since OpenCV represents images as NumPy arrays and the "array" sub-module allows us to obtain NumPy arrays from the Raspberry Pi camera module.