Chapter 8. Computer Vision
Computer vision (CV) allows your Raspberry Pi to âsee things.â In practical terms, this means that your Raspberry Pi can analyze an image, looking for items of interest, and can even recognize faces and text.
If you link this with a camera to supply the images, all sorts of possibilities open up.
8.1 Installing OpenCV
You want to install OpenCV 3 computer vision software on your Raspberry Pi.
To install OpenCV, first install the prerequisite packages using these commands:
$ sudo apt-get update $ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103 $ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
You may also need to update pip using:
$ wget https://bootstrap.pypa.io/get-pip.py $ sudo python3 get-pip.py
Then install OpenCV itself and Python image utilities using these commands:
$ sudo pip install opencv-contrib-python==220.127.116.11 $ pip install imutils
After installation is complete, you can check that everything is working by starting Python 3, importing cv2 and checking the version:
pi@raspberrypi:~ $ python3 Python 3.7.3 (default, AprÂ 3 2019, 05:39:12)Â [GCC 8.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> cv2.__version__ '4.1.0' >>> exit()
Computer vision is both processor and memory intensive, so although OpenCV will work on an older Raspberry Pi, they can be slow on anything earlier than a Raspberry ...