#RaspberryPi – Performance differences in #FaceRecognition using #OpenVino (code with @code!)

Buy Me A Coffee

Hi !

I’ve been looking to use the amazing Intel Neural Stick 2 for a while, and one of the 1st ideas that I have was to check how fast my Raspberry Pi 4 can run using this device.

The Intel team released a nice step by step process installation for Raspberry Pi. And it works great, there are a couple of minor glitches that you need to figure out, like the latest package version, everything else works great.

Note: I downloaded my openvino toolkit from here (https://download.01.org/opencv/2019/openvinotoolkit/R3/), and the downloaded file is (l_openvino_toolkit_runtime_raspbian_p_2019.3.334.tgz).

Once installed, the 1st python sample is a face recognition one. This sample analyzes a image file using OpenCV to detect faces, and creates a new output file with the detected images. As I said, is very straight forward.

So, I decided to create a new python sample to run live face detection using the camera feed and also display the FPS. This is the output code:

The code is very straight forward and the main matters are

  • It uses 2 models from the Intel Zoo to perform the face detection: face-detection-adas-0001.xml and face-detection-adas-0001.bin
  • Lines 22 and 23 are key to define that OpenCV will load and use the models in the Intel device
  • I use imutils to resize the image to 640×480. Feel free to use any other library for this, even OpenCV
  • Also, it works also with smaller resolutions, however 640×480 is good for this demo

And the final app running analyzing almost 8 frames per second (8 FPS).

Which is almost 10 times faster that the 0.7 FPS without Intel NCS2

And, I already wrote about running Visual Studio Code in the Raspberry Pi (see references) is an amazing experience. I did all my Python in VSCode coding remote accesing my device via VNC. Python runs like a charm!

You can download the code from https://github.com/elbruno/rpiopenvino/tree/master/facedetection

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – How to solve the SSH warning: WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

Buy Me A Coffee

Hi !

When you test and play around with your Raspberry Pi, you may need to format again your Raspbian SD Card, and then start everything from scratch. This is a trivial process, and is usual to setup the device to connect automatically to a Wifi network and also enable SSH (I wrote about this, see references).

And then, when you try to connect via SSH you may get this warning

 C:\Users\bruno> ssh pi@192.168.1.247
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256: Not here ! 
Please contact your system administrator.
Add correct host key in C:\\Users\\bruno/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in C:\\Users\\bruno/.ssh/known_hosts:10
ECDSA host key for 192.168.1.247 has changed and you have requested strict checking.
Host key verification failed.

This is a very common scenario, and because I forgot how to fix it, I’ll write the simple command remove all keys belonging to the IP / hostname from the known_hosts file.

# ssh-keygen -R <host>
ssh-keygen -R 192.168.1.247

And that’s it, keys removed and now I can connect via SSH

Happy coding!

Greetings

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – How to install #docker (Updated 2020-01-24)

Buy Me A Coffee

Hi

I wrote a couple of times about this, however this is the updated version on how to install docker in a Raspberry Pi. Updated to Jan 24 2020.

The information is available from the Official Docker Documentation

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

And then, a simple check for the docker version with the command

docker version

And that’s it ! Docker installed in the device 😀

Happy coding!

Greetings

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – Install OpenCV

Buy Me A Coffee

Hi!

After some posts about how to setup a Raspberry Pi, today I’ll share the steps I follow to install OpenCV.

Disclaimer: if you are looking for a detailed step by step on how to install or even build OpenCV in a Raspberry Pi, I strongly recommend to read the post “Install OpenCV on Raspberry Pi 4” by Adrian Rosebrock.

Ok, so let’s start. I assume that you read my posts and your Raspbian image is up and running.

Install Python 3 and Update device

1st step will be to install Python 3 with the following command

sudo apt-get install python3-dev

And run and update for all the installed software

sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'
Install and use Virtual Environments

This will give us the base image to start working. And, in case we need to install different versions or different apps, I’ll use virtual environments to work with Python.

Let’s install VirtualEnv with the command

#create virtual environment
sudo pip3 install virtualenv

Now let’s create a new virtual environment named “venv” with the command

virtualenv -p python3 .venv

And let’s activate the environment with the command

source .venv/bin/activate

At this moment, the terminal should change and add a prefix (venv) in the bash.

raspberry pi install and activate a virtual environment
Install prerequisites

Let’s update again

sudo apt-get update

And install prerequisites with the commands

sudo apt-get install gfortran 
sudo apt-get install libopenblas-dev 
sudo apt-get install liblapack-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install python3-pyqt5
sudo apt-get install libqt4-test

or in a single command

sudo apt-get install gfortran libopenblas-dev liblapack-dev libatlas-base-dev libjasper-dev libqtgui4 python3-pyqt5 libqt4-test -y

This process will take some minutes, so this is time 1 to get a coffee!

Install OpenCV and switch to right Raspberry Pi version!

And now the magic command to install OpenCV

sudo apt-get install libopencv-dev

And this process is the one who take most of the time, so coffee number 2. Take a look at all the dependencies for this

And after a couple of minutes the process is done. We can test the OpenCV version running 2 simple python commands. First let’s start python with the command

python

And then run the following lines

import cv2
cv2.__version__

This should display the current OpenCV version.

However, with the latest version we have an error: ModuleNotFoundError: No module named ‘cv2’

The current installed version have some issues running in the raspberry py, so we need to make a downgrade to the version 4.1.0.25 with the command. We first uninstall the installed version (4.1.0.26) and install the specific version.

pip uninstall opencv-contrib
pip install opencv-contrib-python==4.1.0.25

Now, we launch python again, run our 2 lines, and we got OpenCV up and running!

Bonus: Installed Packages

Finally, this is the current list of packages installed in the virtual environments and the version of each package

(.venv) pi@rpidev5:~ $ pip3 list
Package               Version
--------------------- --------
numpy                 1.18.1
opencv-contrib-python 4.1.0.25
pip                   20.0.1
setuptools            45.1.0
wheel                 0.33.6
(.venv) pi@rpidev5:~ $

Happy coding!

Greetings

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – setup without monitor: enable VNC

Buy Me A Coffee

Hi!

In my previous post I shared a series of steps to:

  • Configure and SD Card with Raspbian
  • Automatically connect to a WiFi network
  • Enable SSH
  • Expand the file system
  • Rename the device
  • Update the default Raspbian software

In this post I’ll share the necessary steps to enable the VNC service, so you can connect to the Raspbian Desktop via VNC.

Enable VNC

In order to activate the VNC service we need to access to the device configuration with the command

sudo raspi-config

Then we select the options

  • Interfacing Options
  • VNC

Select YES

And that’s it, the VNC Server is enabled.

Now we can connect to the device with a VNC client app. Like in example, VNC Viewer

Conclusion

And that’s it, we have our device updated and running with the latest software versions and we didn’t use a monitor! I’ll update this post frequently to make it relevant with my personal best practices.

Happy coding!

Greetings

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – 1st setup without monitor: auto connect to WiFi, enable SSH, rename, update and more!

Buy Me A Coffee

Hi!

Ok, let’s assume you did the tutorial and installed the latest raspbian image in an SD card. If you want to access and control remotely your device you may want to follow this steps.

Configure Wireless connection

In the SD Card, you need to create a file named [wpa_supplicant.conf] in the root of the SD card with the following information:

country=ca
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid=" Your WiFi SSID"
 psk="You amazing password"
}

The file content is very straight forward to understand. Main values to complete are [ssid] and [psk].

Once you put the SD card in the device and start the device, it will automatically connect to the configured WiFi.

Enable SSH

If you also want to enable SSH, you need to create a blank file named [ssh] to the main partition.

Once you put the SD card in the device and start the device, it will automatically enable the SSH service.

Find the IP address in your network

And that’s it, your Raspberry Pi will be connected to the Wifi and with SSH enabled. At this moment we can use a tool like AngryIp (see references) to detect the new device in the network

My new device IP is: 192.168.1.246

Access via SSH

I used to like Putty to connect to my device, however during the past months I’ve been using Windows Terminal and Powershell. In order to access the device I need to execute the command

ssh user@deviceaddress

and my data is

  • user: pi
  • ip: 192.168.1.246
  • password: raspberry

You can now start working with your Raspberry Pi !

Change Password

The default password for the device is “raspberry”, and as usual, it’s recommended to change it. In order to do this, in the ssh terminal, let’s access to the device configuration

sudo raspi-config

This will open the configuration for the device.

Option number 1 will allow us to change the password.

Rename the device

In the same Raspberry configuration tool, we can rename the hostname that our device will use for network operations.

Select the options

  • Network Options
  • Hostname

And define the new name for the Raspberry Pi device.

Expand FileSystem

Another important option in the configuration is to expand the SD disk.In the same configuration screen, select

  • 7. Advanced Options
  • Expand File System

Now we need to reboot and after the reboot the file system should have been expanded to include all available space on your micro-SD card. Reboot with the command

sudo reboot

Update the device

Of course, at this moment you should change your default password and update everything with a command like this one

sudo -- sh -c 'apt-get update; apt-get upgrade -y; apt-get dist-upgrade -y; apt-get autoremove -y; apt-get autoclean -y'

Conclusion

And that’s it, we have our device updated and running with the latest software versions and we didn’t use a monitor! I’ll update this post frequently to make it relevant with my personal best practices.

Happy coding!

Greetings

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#Ebook – Code the Classics, amazing book for programming games in #Python. From the #RaspberryPi library.

Buy Me A Coffee

Hi!

My son is a crack and he already passed the Scratch stage. He is part of an amazing Code Ninja programming program and he is asking for some new challenges.

Last month, when I see the release of the Code the Classics – Volume 1 book, I get one for us. And it’s amazing. I mean, he needs to understand Python now, so it’s another challenge. But you know me, any excuse to keep him away from JavaScript!

Code The Classic - Volume 1

By the way, all the code is available in GitHub, and it will take just 5 minutes to set everything up to test the games. And, most important, the book is also available FOR FREE IN EBOOK FORMAT.

So kudos to the publisher, and let’s go with the formal book description.

This stunning 224-page hardback book not only tells the stories of some of the seminal video games of the 1970s and 1980s, but shows you how to create your own games inspired by them using Python and Pygame Zero, following examples programmed by Raspberry Pi founder Eben Upton.

In the first of two volumes, we remake five classic video games – ranging from Pong to Sensible Soccer, each represents a different genre. We interview the games’ original creators and learn from their example, as well as utilise the art and audio engineering skills of two of the 1980s’ most prolific games developers for our recreated versions of the games.

Get game design tips and tricks from the masters

– Explore the code listings and find out how they work

-Download and play game examples by Eben Upton

– Learn how to code your own games with Pygame Zero

– Read interviews with expert graphics and audio creators

Happy coding!

Greetings

El Bruno

References

#RaspberryPi – Where is my Add/Remove programs? let's use Synaptic

Buy Me A Coffee

Hi!

When I wrote about the latest version of Visual Studio Code working on the Raspberry Pi, I realize that I used a couple of commands to find an installed application.

The following command will list all the installed apps

sudo apt list --installed

Which is great, but hard to read in bash mode. So that’s why I use grep to filter for the app I want.

sudo apt list --installed | grep -i code-oss

So far, so good. The command did the trick, and I got my result: app name, version and details. However, as a long time Windows user, I was wondering if Linux users have a visual interface for this. And then I found: Synaptic.

The command to install Synaptic is maybe the last command we will use to install or uninstall an app

sudo apt install synaptic -y

And then we can launch the app using this command, and it’s need to be with sudo permissions (learned in the hard way)

sudo synaptic

At this moment, I can browse in the all list of apps. And I can quickly perform a search for my installed Visual Studio Code.

I get the result, with details, version and more.

And if you are wondering what’s the main difference with the bash command? So, I didn’t need to search and learn a command, the universal visual clue of the magnifier, or the search button were good enough for me.

Playing around with the app, I found I can display much more information for each installed app. Which is great, because I start to understand the idea and concepts of dependencies, where Linux install software, etc.

Happy coding!

Greetings

El Bruno

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – Visual Studio Code blank screen is fixed on version 1.42. Thanks @headmelted! @code

Buy Me A Coffee

Hi!

When I wrote about how to install Visual Studio Code on a Raspberry Pi, there was an error on the app running on the device: the tool opened and display a black window.

We needed to manually go back to version 1.29 to avoid this problem. And we also forgot to apply any updates, each new version still have the black window error.

I was following the issue on GitHub, and I was happy when a few days ago, it was solved by headmelted (link https://github.com/headmelted/codebuilds/issues/67#issuecomment-563335451).

I’ve updated the app to the latest version (1.42.0), and it was working fine.

raspberry pi 4 visual studio code version 1.42 running fine

If we check the apt list, we can find a specific detail of the running version with the command

sudo apt list --installed | grep -i code-oss
raspberry pi 4 apt list for code -oss return 1.42

So, please go and thank headmelted by the amazing work he is doing!

Happy coding!

Greetings

El Bruno

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware

#RaspberryPi – Ice Tower: The best cooler for your device! From 70C to <40C in a 60 minutes process running at 100% in all 4 cores

Buy Me A Coffee

Hi!

The Raspberry Pi 4 is an amazing device, and if you have been tracking the different usage scenarios for the device, you probably noticed that heat is an issue. I’ve using some Aluminum Heatsink, however still in some heavy scenarios the device temperature can be up to 70C or more.

I found out that when the device get’s to certain temperature (>80C), the device lowers its operational speed to prevent damage.

Officially, the Raspberry Pi Foundation recommends that the temperature of your Raspberry Pi device should be below 85 degrees Celsius for it to work properly. That’s the maximum limit. But it would start throttling at 82 degrees Celsius.

Raspberry Pi Temperature Monitor

While I was digging on this topic, the SeeedStudio team approached me to suggest me to test one of the best fans for Raspberri Pi 4: Blink Blink ICE Tower CPU Cooling Fan for Raspberry Pi (Support Pi 4).

This fan is massive and amazing. Look at these photos, to have a sense of the size of the fan.

raspberry pi 4 massive fan 1
raspberry pi 4 massive fan side by side with a raspberry pi

And, because I’m a programmer, I decided to test the device temperature with a long heavy process, to see how this affect the temperature.

Build OpenCV

Initially I was planning to share a machine learning training model process, but then I realized that there is something else that we can do which is very resource consuming: Compile OpenCV.

And, I know, you can install OpenCV with a simple pip install command, but let’s built it. Is much more fun. As usual, I’ll rely on one of the amazing Adrian Rosebrock Tutorials: Install OpenCV 4 on Raspberry Pi 4 and Raspbian Buster (see references)

Build OpenCV using 4 cores with a bare naked Raspberry Pi: >75C

In this 1st scenario, I built OpenCV using the 4 cores with a bare-naked Raspberry Pi. This process took almost an hour, and as you can see in the following animation:

  • The 4 cores where working at 100%
  • The temperature was around 75 degrees all the time
  • And, of course, this animation is at 300X speed.
build opencv on raspberry pi 4 no fan 300x

Build OpenCV using 4 cores with ICE Tower Cooler fan in a Raspberry Pi: <40C

In the 2nd scenario, I built OpenCV using 4 cores with the ICE Tower Cooler fan in the Raspberry Pi. As the previous one, this process also took almost an hour, and as you can see in the following animation:

  • The 4 cores where also working at 100%
  • The temperature was less than 40C degrees all the time
  • Again, this animation is at 300X speed.
build opencv on raspberry pi 4 with Ice tower fan

Differences running an App: Face Recognition

My next question was how about a normal process, like some face recognition demos. I used and changed some of Adrian Rosebrock’s face recognition demos, and here are the results.

Face Recognition app in a Raspberry Pi bare-naked, runs at 67C degrees
Face Recognition app in a Raspberry Pi with ICE Tower Cooler fan, runs at 38C degrees

Conclusion

If you are concerned about the temperature of your device, this is my top 1 option. And, if you are wondering if the fan is noisy? not at all! I have it right next to me, and I don’t even notice the fan.

About Seeed Studio

Seeed is the IoT hardware enabler providing services over 10 years that empower makers to realize their projects and products. Seeed offers a wide array of hardware platforms and sensor modules ready to be integrated with existing IoT platforms and one-stop PCB fabrication and PCB assembly service. Seeed Studio provides a wide selection of electronic parts including Arduino  Raspberry Pi and many different development board platforms  Especially the Grove Sytsem help engineers and makers to avoid jumper wires problems. Seeed Studio has developed more than 280 Grove modules covering a wide range of applications that can fulfill a variety of needs. 

Bonus: this video also analyzes the cooler in other scenarios.

Happy coding!

Greetings @ Burlington

El Bruno

References

My posts on Raspberry Pi

Dev posts for Raspberry Pi
Tools and Apps for Raspberry Pi
Setup the device
Hardware