You're reading from Raspberry Pi Computer Vision Programming. - Second Edition
Technical requirements
The code files of this chapter can be found on GitHub at https://github.com/PacktPublishing/raspberry-pi-computer-vision-programming/tree/master/Appendix/programs.
Check out the following video to see the Code in Action at https://bit.ly/3ewQwHs.
Performance measurement and the management of OpenCV
OpenCV has a lot of optimized and unoptimized code. The optimized code uses features of modern microprocessors, such as instruction pipelining and AVX.
We can check whether the optimization of OpenCV is enabled on the computer we are currently using with the cv2.useOptimized()
function. We can also use the cv2.setUseOptimized()
function to toggle the optimization. The cv2.getTickCount()
function returns the number of clock ticks (also known as clock cycles) from the time that the computer was turned on. This function is called before and after the execution of the code snippet that we are interested in.
Then, we compute the difference between the clock cycles and it returns the number of clock cycles needed to execute the code snippet. The cv2.getTickFrequency()
function returns the frequency of the clock cycles. Then, we can divide the difference between the clock cycles by the frequency of the clock cycles to obtain the...
Reusing a Raspbian OS microSD card
We have learned to write the Raspbian OS to a microSD card using Win32 Disk Imager. Now, we are going to see how to reuse that microSD card for any other purpose. Insert the microSD card into the microSD card reader and connect it to a Windows PC. It will show two partitions. Only one of these is readable and it will be labeled boot
. It should also have the config.txt
file, which has a size of around 250 MB. The other partition is unreadable. We cannot use this microSD card as it is used for another purpose. So, we need to use a few tools to format this card before we can reuse it again for any other purpose.
Formatting the SD card using the SD card formatter
There is a free tool for formatting SD cards. We can download it from https://www.sdcard.org/downloads/formatter/. Install this tool and open it, and it will show the following window. The drive letters could be different depending on the number of drives on your computer. The following...
Tour of the raspi-config command-line utility
We can configure Raspberry Pi by using one of the following three methods:
- The Raspberry Pi configuration tool in the Raspbian OS menu
- By altering the content of
/boot/config.txt
- With the
raspi-config
command-line utility
We will provide a detailed tour of the raspi-config
tool in detail in this section. Open the Raspberry Pi command prompt and run the following command:
sudo raspi-config
This will open the Raspberry Pi configuration tool in Command Prompt, as in the following screenshot:
The first option is used to change the password for the pi
user. The second option in the main menu, Network Options, has the facility to change the way the Raspberry Pi board is connected to the network:
The third option in the main menu (Boot Options) details the booting options...
Installation and the environment setup on Windows, Debian, and Ubuntu
We can demonstrate all the areas we have learned on other desktop computers with the Windows and Linux OSes. Only the part related to the Raspberry Pi camera module will not work with the other computers as desktop motherboards usually do not come with DSI ports. We can also run the code examples on other single-board computers that run Debian or Ubuntu.
The process to install the packages is the same on Ubuntu, Debian, and their derivatives. All the modern Linux distributions come with Python 3. We just need to use the apt
and pip3
tools for installation.
For a Windows PC, we need to install everything from scratch. Let's get started with understanding how to install Python 3 by taking the following steps:
- Visit www.python.org and download the installation file for the latest Python 3 release:
Run the downloaded setup file. It will open an installation...
Python implementations and Python distributions
A Python implementation is a program that acts as the Python programming language interpreter. The interpreter provided by https://www.python.org/ and the one that comes with Linux is known as CPython. Other popular implementations include (but are not limited to) the following:
- MicroPython
- IronPython
- Stackless Python
- Jython
- PyPy
- CircuitPython
We can find a list of alternative implementations and their project URLs at https://www.python.org/download/alternatives/.
A Python distribution is a Python interpreter implementation and an additional set of packages bundled together. A few Python implementations are distributions themselves. Actually, there is no clear distinction between the terms implementation and distribution. We can find more information about distributions at https://wiki.python.org/moin/PythonDistributions.