Make sure that you have a working, wired Internet connection with reasonable speed for this activity. Now, let's prepare our Pi for computer vision:
sudo service networking restart
ping –c4 www.google.com
If the command fails, then check the Internet connection with some other device and resolve the issue. After that, repeat the preceding steps again.
sudo apt-get update sudo apt-get upgrade sudo rpi-update sudo reboot –h now
sudo apt-get install <package-name> -y
Here, <package-name>
is one of the following packages:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For example, you have to install x264, then you will need to to type the following:
sudo apt-get install x264 -y
This will install the necessary package. Similarly, install all the previously mentioned packages. If a package is already installed on your Pi, then it will show the following message:
Reading package lists... Done Building dependency tree Reading state information... Done x264 is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
In this case, don't worry. This package is already installed and comes with its newest version. Just proceed with installing all the other packages in the list one by one.
sudo apt-get install python-opencv -y
This is the easiest way to install OpenCV for Python; however, there is a problem with this. Raspbian repositories may not always contain the latest version of OpenCV. For example, at the time of writing this, Raspbian repository contains 2.4.1, while the latest OpenCV version is 2.4.10. With respect to the Python API, the latest version will always contain much better support and more functionality.
For the convenience of the readers, all these commands are included in an executable shell script, chapter07.sh
, in the code bundle. Just run the script with the following command:
./chapter07.sh
This will install all the required packages and dependencies to get started with OpenCV on Pi.
In Python, it's very easy to code for OpenCV. It requires very few lines of code compared to C/C++, and powerful libraries such as NumPy can be exploited for multidimensional data structures required for image processing.
Open a terminal and type python
, and then type the following lines:
>>> import cv2 >>> print cv2.__version__
This will show us the version of OpenCV installed on the Pi, which is 2.4.1 in our case.