Reader small image

You're reading from  Raspberry Pi Computer Vision Programming. - Second Edition

Product typeBook
Published inJun 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781800207219
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Ashwin Pajankar
Ashwin Pajankar
author image
Ashwin Pajankar

Ashwin Pajankar is an author, a YouTuber, and an instructor. He graduated from the International Institute of Information Technology, Hyderabad, with an MTech in Computer Science and Engineering. He has been writing programs for over two and a half decades. He is proficient in Linux, Unix shell scripting, C, C++, Java, JavaScript, Python, PowerShell, Golang, HTML, and assembly language. He has worked on single-board computers such as Raspberry Pi and Banana Pro. He is also proficient with microcontroller boards such as Arduino and the BBC Micro:bit. He is currently self-employed and teaches on Udemy and YouTube. He also organizes programming boot camps for working professionals and software companies.
Read more about Ashwin Pajankar

Right arrow

Chapter 13: Appendix

All the topics that could not be covered in this book's main chapters are instead covered here. This appendix is largely a collection of useful topics, including tips and tricks. So, let's look at a few tips and tricks relating to Raspberry Pi, Python 3, and OpenCV.

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:

Figure 13.6 – The main menu of the raspi-config utility

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:

Figure 13.7 – Network Options

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:

  1. Visit www.python.org and download the installation file for the latest Python 3 release:

    Figure 13.12 – The Python Foundation home page

    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.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi Computer Vision Programming. - Second Edition
Published in: Jun 2020Publisher: PacktISBN-13: 9781800207219
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ashwin Pajankar

Ashwin Pajankar is an author, a YouTuber, and an instructor. He graduated from the International Institute of Information Technology, Hyderabad, with an MTech in Computer Science and Engineering. He has been writing programs for over two and a half decades. He is proficient in Linux, Unix shell scripting, C, C++, Java, JavaScript, Python, PowerShell, Golang, HTML, and assembly language. He has worked on single-board computers such as Raspberry Pi and Banana Pro. He is also proficient with microcontroller boards such as Arduino and the BBC Micro:bit. He is currently self-employed and teaches on Udemy and YouTube. He also organizes programming boot camps for working professionals and software companies.
Read more about Ashwin Pajankar