Tuesday, 19 August 2025

AI: How May AI Tools Impact Our Thinking

I've spent some time on reading and summarizing a couple of papers that are discussing how AI is impacting our thinking. After that, I've also had an AI agent summarizing the papers and discussing my conclusions.

Your Brain on ChatGPT

This paper from MIT compared three small groups of students that were to write essays with different levels of assistance:  No assistance at all, Search Engines and Large Language Models. 

The term self-efficacy reflects the student's confidence in his/her own ability to learn. The report mentioned that students low in self-efficacy may use LLM's to a larger extents than self-confident students. Cognitive Load versus Engagement

There is a difference between high-competence use of LLM and low-competence use. Higher competence uses LLM strategically for active learning, revisiting and synthesizing information to create coherent knowledge structures. This reduced cognitive strain while remaining engaged with material.

LLM bots as Instructor Bot and Emotional Support Bot can improve performance and reduce stress

Con's from LLM's: Laziness, one single answer compared with web searches, no person-person discussions, more superficial and effort-less learning.

The Illusion of Thinking

Large Reasoning Models are LLM's that can perform some kind of "reasoning" in different steps. Apple has investigated some models for simple puzzles. Depending on the task complexity, either LLM's are better (simple tasks), LRM are better (moderate complex tasks) and both collapse (complex tasks).

Put differently, will future employers allow employees to spend several hours reading and understanding complex topics by actually reading about it, or will employees be expected to use LLM's to quickly generate convincing TL;DR results that are more or less factual. The latter option may make employees lazy, worse in problem solving and independent thinking. 

Thursday, 17 July 2025

Exploring AI Tools for Coding

As I work in tech, the developments in AI will have a serious impact on my work, even if I'm not a software developer. 

My summer project (on the rare occassions when I'm not focusing on my family, house and geopolitics) will be to investigate tools for coding and working in tech using AI tools that are available today. Maybe I'll reboot my train project.

Initial Youtube videos for exploring AI

Of the tools below, I'll focus on GitHub Copilot, Gemini and Cursor. I have some experience of the two former tools. I'll have an open mindset and try to avoid the inevitable flamewars that comes with any new technologies. Many of the cool tools will vanish when the AI world enters the next AI winter so it rill be hard I'll avoid focusing on a few tools.

This is an overview of some current tools for developers.
Tools to check: React, Express, Tailwind, Reddus and Dino for web development.

Vibe coding fundamentals

Vibe coding is kinda like having a junior developer available that can help with some basic non-perfect coding. Still, there will be need for coding, design thinking and debugging. 

This one summarizes the Google AI Essentials course.

Break down complex problems into specific tasks.

Four levels of thinking for vibe coding: Logical, Analytical, Computational and Procedural

Tools to check: Replit -Windsurf - Cursor

Fundamental skills: The Friendly Cat Dances Constantly.

  • Thinking - have a clear description of problem. PRD - Product Requirement Document
  • Framework -  Help the AI help you to find framework that is solving your problem
  • Checkpoints - use GIT
  • Debugging
  • Context 

Gemini has some support for advanced research. To be added to my backlog

Prompt engineering Tiny Crabs Ride Enormous Iguanas

  • Task
  • Context
  • References
  • Examples
  • Iterations
    • Revisit prompting framework
    • Separate prompts into shorter sentences
    • Try different phrasing or switch to analogous task
    • Introduce constraints
    • Check following from prompt responses
      • Is output accurate and unbiased?
      • Is output containing sufficient information?
      • Is output relevant?
      • Is output consistent when using it several times?

Glossary:

Shot = Example
Persona -  Ask AI to act an an expert on a specific field
Context
Task

Links

https://aistudio.google.com/prompts/new_chat

https://github.com/i-am-bee    Bee agent framework

Brilliant.org

https://grow.google/prompting-essentials/


Wednesday, 22 May 2024

RPI: Setting up Raspberry Pi 3B+ to be accessible from anywhere

I have a simple trading bot that I currently run from a WSL Ubuntu session in my home computer. In this post, I'll set up a headless Raspberry Pi that can host that session. I still want to be able to control it from my mobile, so I need to do the following:

Set up RPI headless, Install and Disable screen saver

After installation, the board became unresponsive after some 10 minutes. I found

https://forums.raspberrypi.com/viewtopic.php?t=286000

Now, the RPI works fine for at least a couple of days.

Install app for accessing RPI from mobile

I found RaspController that is available for both Android and Iphone that gives a good interface to the RPI. 

Set up Dynamic DNS using NoIP

I activated a Dynamic DNS session using NoIP with both a host name and ipv4 IP.

As my router was too old, I decided to configure my RPI instead using the instructions below

https://www.noip.com/support/knowledgebase/install-linux-3-x-dynamic-update-client-duc

Make NoIP start automatically when booting

https://www.noip.com/support/knowledgebase/running-linux-duc-v3-0-startup-2

Configure Python and setup venv

There is plenty of documentation online

Nohup to run detached
Finally, since I need the program to run in the background, I used the nohup command to start the script,

https://www.digitalocean.com/community/tutorials/nohup-command-in-linux


Saturday, 15 April 2023

TrafficControl: Bind Python into Program, or Port Scripts to Code?

Currently my program expects the user to have python installed on his/her computer. This will be a severe blocker for any portability and I will need to handle this, either by binding Python into C++ or porting the scripts into C++ code. 

Binding:

Advantages: I would be able to use the existing code

Disadvantages: The binaries may be bigger and that will be a disadvantage when deploying on web assembly

Porting:

Advantages with porting to C++: Everything will be in C++

Disadvantage: Porting the application to C++ may be time consuming.

For now, I'll try porting the code to C++/Qt/Regular expressions.

Legacy Code:

The program creates a shell process that starts python.exe (hard coded for Windows), with a hard coded path to the script. 

In my last commit, I added code to src/networkDesigner.cpp. For the XML/QML handling, I used some code that I found at stack overflow.

This change isn't visible but it is a big step towards Web Assembly.


Friday, 30 December 2022

TrafficControl: Exploring Qt WebAssembly

I've seen that it is possible to create executables that can be run from within a web browser. This is very interesting for my pet project Traffic Control and I'll spend some time exploring this.

What is web assembly and why bother?


Desktop applications are a bit inconvenient for the end user. He/she needs to find an installation package that goes with the particular operating system - that requires some competence and also some administrator rights. Further, there is a risk of viruses. After using the software, the software lies on the computer until removed. It will take quite a bit of persuation to make people install my software. 

With a Web Assembly app, it is different. The program will be linked from a simple web page that loads the executable to a sandboxed environment inside the web browser the user is using. This will be independent on the hardware architecture and operating system. No installation and no cleanup.

Qt supports web assembly - this is the key point of Qt: that it is a programming framework that can be used for different platforms. If I'm able to port TrafficControl to web assembly and deploy on a web server, the program will be able to run from any connected device with one of the bigger web browsers.

What would that mean for me? 

For me, the program would be deployable to any unit that runs one of the major web browsers. To deploy the software, I would need to set up a web server, or use an existing platform that hosts the binary. 

Traffic Control would need some refactoring:

  • The program depends on python for converting files. That needs to be in C++
  • I need to consider how to access local files and examples
  • I need to look into the user interface - should I migrate to QML for all user interface?

Step-by-step

  1. Install an updated Python version and Emscripten 
  2. Setup environment for Qt Web Assembly
    1. Specify C and C++ compiler
    2. Other settings?
  3.  Configure for simple C++/QML application - QML Demo
    1. Download from GitHub
    2. Compile for desktop
    3. Compile for Qt Web Assembly
    4. Open in Web Assembly
  4. Adopt TrafficControl to WebAssembly
    1. Find out how to store the TNF/TNM/TNO files when using webAssembly? Initially, use read-only and disable the conversion features?
    2. Handle loading of traffic network files
    3. Port the conversion from KML to Traffic Map File/Traffic Network file to either
      1. Python in-project code, or
      2. C++ Code
  5. Deploy application on web server

Emscripten is used for compiling to webAssembly and it is based on Python and needs a late Python version. Installing Python is straight forward. 

I installed Emscripten from the git repo:

Yes, I'm using a screen shot.
If you're copying commands, you'd better copy from the formal documentation.
As I'm using Qt 5.15.2, I need to install the corresponding Emscripten version (1.39.8) and activate it permanently (use the same version for each instance:


However, after activating emsdk, the python path is missing. I found out that I need to run the shell as an administrator.

In Qt, I currently use the auto-detected "Local PC" as a target for the binaries. I added a web assembly device where I pointed to the Emscripten folder.


Once the device is configured, I need to set up a kit for the compilation. 

Finally, I specified that the project should have the web assembly option in the "Projects" tab.

This time, I used an old QML demo project that I have on my Github account. In that project, I explored some basic QML features and how to interact from C++. 

During the build process, I saw a warning - my installation of Qt was actually built with Emscripten 1.39.7, not 1.39.8 as the documentation said. The build was still successful.

After the build was completed, I started it by loading the local web site:
There it is! A C++/QML application that is running inside a web browser. The html page can be embedded into another web page on a web server. For my simple QML application, the binary used ~20 MB for the release build and ~27 MB for the debug build.

In the next blog post, I'll explore if it is possible to port TrafficControl to web assembly. For Qt 5.15.2, Qt Location seems not to be supported for web assembly. For Qt6, QtLocation and QtPositioning didn't work out of the box, maybe it is possible to find a workaround.












Friday, 23 December 2022

TrafficControl: Doxygen

In order to get a better understanding of the code structure of my project TrafficControl, I need to use Doxygen.

Doxygen is one of the most popular tools for documenting source code. The developer adds Doxygen-style comments to the source. When Doxygen analyses the code, it uses the structure along with the comments to generate a set of files with an overview of the program, and the relations.

Step 1 - Select how to use Doxygen

At first, I wanted to integrate Doxygen into Qt Creator. After digging into how to do it, it seemed to be quite difficult. I would either need to find pre-compiled binaries that matches my system and my Qt installation, or recompile Qt Creator. I tried to follow the video below, but the URL they used was broken.


I'm not the only one to pay too little attention to my pet projects.

Instead, I installed the program on my computer from the Doxygen web site. I also installed GraphViz for creating graphs - that will be useful for getting an overview of my code.

Step 2 - Configuring Doxygen

The next step was to use an appropriate set of parameters for my project. The most important ones are listed below:
  • QT_AUTOBRIEF           = YES - Assume that the first line of the class descriptor to be the brief description.
  • EXTRACT_ALL            = YES - Assume all entities to be documented. Maybe not needed?
  • EXTRACT_PRIVATE    = YES
  • EXTRACT_PRIV_VIRTUAL = YES
  • EXTRACT_STATIC      = YES
  • EXTRACT_LOCAL_METHODS = YES 
  • INPUT          = C:/Users/gusta/GIT/trafficControl-dev/src \ - All folders to be documented. IMPORTANT!
  •                          C:/Users/gusta/GIT/trafficControl-dev/inc \
  •                          C:/Users/gusta/GIT/trafficControl-dev/test
  • RECURSIVE                  = YES - Include sub directories
  • HAVE_DOT                    = YES - Use Dot tool from GraphVix to generate graphs - IMPORTANT!
  • UML_LOOK                   = YES - Make graphs look more like UML
  • DOT_UML_DETAILS    = YES - Add bytes and info to UML graphs
  • CALL_GRAPH               = YES
  • CALLER_GRAPH          = YES
  • DOT_PATH                     = C:/Program Files/Graphviz/bin

Step 3 - Insights from Doxygen

My first insight is that there is lot's of more to learn about Doxygen, and that it will be useful to check the relations between different parts of my program. Listing everything will be too exhaustive for a blog post, and I don't know yet know how to publish Doxygen output in a reasonable way. 

I'll show some examples of the graphs below:
Train::move() will call different functions depending on the current state.


A lot of functions are calling NetworkControl::parseCmd()
A lot of functions are calling parseCmd. This means that bugs that are introduced hwere will have a huge impact - extensive testing will be needed.

Saturday, 17 December 2022

TrafficControl: Migrating Back to QtTest

After seeing new strange issues with all test cases, (compilation issues, I guess that it was a mismatch in compilation for the test files), I've decided to try moving back to QtTest for my project. 

I had some issues with Qt's Meta Object Compiler, but after a while I got that working (the name of the moc file must match the source file).

It took me several hours to refine the test cases, and I saw that I could merge several test cases to one. For example, some test cases check parameters after initialization, and there is no reason to have several test cases for that. I was also able to simplify the syntax and use the command parser.


The next step will be to use Doxygen for my code. I need to get a better overview of the structure, and I think Doxygen will be the best tool for it. 

Saturday, 1 October 2022

Qt: Upgrading from Qt 5.12.2 to Qt 6.3

After a couple of years exploring Machine Learning, IoT and Python, I'll return to TrafficControl. The current version of my project is Qt 5.12 - more than three years old. 

Upgrading from Qt 5.12 to Qt 6.3.2 seems to be easier said than done. It is recommended to start upgrading to Qt 5.15 and after that upgrading to Qt 6.3.2.

The steps for this project are:

Build and test the program as it is, with the installed version of Qt. 

There are sometimes changes to external services, such as map provider. I may also have done changes that I forgot about several years ago. 

Further, my antivirus program scans the binary that I compile, and that takes some time.

https://forum.qt.io/topic/90617/avast-alarm-to-qt-5-10-1-static-build/4

I solved the issue by adding an exception to the anti virus program. 

Push the current version of the program to GitHub. 

I saw that I had some staged changes that I had to check. After generating an access token, I was finally able to push the changes to GitHub.

Test program for Qt 5.15

The recommended way to port an application from Qt5 to Qt6 is to upgrade to/compile for the latest Qt5 version (Qt 5.15) first, and resolve any issues. After that, one can upgrade to Qt6.

I started with disabling any Qt modules that was deprecated between Qt 5.15 by adding the following line to the pro file:

DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00

After some minor fixes, I got the program to run and almost all tests to pass.

Upgrade Qt 5.12 to Qt 6.3.2

I used the online installer and I found some strange issues when trying to run the program. 



The issue was that the module QtLocation (a module that is enabling maps on Qt applications) hasn't yet been ported to Qt 6. The work is ongoing and can be tracked here.




This means that I need to postpone the migration to Qt 6 and use Qt 5.15 instead.

Using Qt 5.15 - a new crash

After installing Qt 5.15, I got a software crash when running the application. 

The program worked fine in Qt 5.12 so I assume there are changes in Qt between 5.12 and 5.15 that made my code fail.

My classes trainListModel, stationListModel and trackListModel are Model/View implementations for the network and are used to simplify the data presentation. They all inherit the trafficDataModel, which in turn inherits the QAbstractTableModel, which inherits QAbstractItemModel, which inherits QObject.


There is a flaw when I call the insertRows() function, where the position where I want to add rows is calculated as a number that I just incremented. When changing the position to the actual list of the train/track/stationListModel, the program works fine. 

The next step will be to review the code and push it to GitHub. After that, I'll investigate what to implement next.

Saturday, 18 June 2022

Hiding Information in Repos

When adding my codebase to Github, I want to avoid telling the world about my login credentials. To do this, I'll save the information in separate files that will be imported during runtime. I won't push those files to my Github repos and my credentials will remain secret.

I'll focus on Python and Bash in this blog post.

Bash scripts:

Create a file, for example "secrets.cfg" with the content:

password=testa123
In the bash script, source the file. Now, the parameters will be available as $password:
$ source settings.cfg

$ echo $password

testa123

Python scripts:

I'll use dotenv to set environment variables from a .env file that is ignored by Git.

I'll create a file ".env" with the content

DOMAIN=fatsug.example.org

The python script will use dotenv, so you need to install it using pip.

pip install python-dotenv

I'll make the python script look for a .env file in the users home folder. This is how the python script looks like:

import os
from os.path import expanduser
from dotenv import load_dotenv

load_dotenv(expanduser("~")+'\.env')
print(os.getenv('DOMAIN'))
For convenience, I can merge the secrets.cfg and .env files to one. Thus, I'll have all my user credentials at one location. 

Saturday, 21 May 2022

New Repos to GitHub

 After some months of inactivity, I've been looking into my codebase again, with some challenges: 

  • It is easy to forget where I've placed the code on my computer. Sometimes, there are different versions of the scripts at different locations. I want to have the code at one location. 
  • It is easy to forget the syntax and order of the scripts. I want to document the projects at the same location as the code itself.
  • I need to centralize the API keys, instead of having them directly in the code.

The solution is to add everything to different GitHub repositories. The repositories worth mentioning are:

cutetrains/hiddenProjects - Projects that I won't share with others at all. These projects include web scrapers and tools for price prediction for financial assets. None of these projects are illegal (this goes for all my repos). No link for obvious reasons.

cutetrains/IOTProjects - Projects for home automation, facial recognition and robotics. I'll use this repo for downloading code into my Raspberry PI. Some of the projects communicate with Arduino boards. For the Arduino part, I'll have the code at my Arduino.cc account.

cutetrains/trafficControl-dev - TrafficControl, a C++/QML train network simulator.

cutetrains/TravelTimeCalculator (Discontinued) - A small Android App that I wrote to get some understanding on Android App development. I'm working in the 4G/5G base station industry with experience from 2G/3G/4G mobile phone verification. I wanted to have some clue about what app development is about.

cuteTrains/StockToDatabase (Discontinued) - A web scraper that collects key numbers for stocks, converting data into a database and performs some machine learning on the data.

I will add instructions and documentation for the non-discontinued public repos.

I'll spend some time on the IOT projects in the near future. 

Saturday, 9 April 2022

IOT: First Steps for the Robot Project

One important part of my IOT project will be to have a small robot that can move around in my house and stream video/pictures with an acceptable delay.

I spotted a platform/robot car that I can start with at a Swedish electronics store and I've spent a couple of evenings with my four year old son building the basic design. In the original setup, the robot uses an ultrasound sensor to determine in what direction it will move.

The robot car consists of:

  • An Arduino board (a very limited computer)
  • A H bridge that controls the engines
  • A pair of simple analog engines that takes 5-10 volts as input.
  • An ultra sound sensor
  • A servo motor that moves the sensor in different directions.
  • A battery pack of 6 AA/LR6 batteries that gives 9 volts.

I've disconnected the original battery pack and replaced it with a power bank.
Later, I've removed the battery pack.



Connecting a Raspberry PI Computer.

The original setup feeds 9 volts both to the engines and to the Arduino board via the DC jack. However, I want to use a Raspberry PI computer with a camera module. 

With the Raspberry PI computer, I can connect to the internet over Wi-Fi, setup a video stream or a web server and do some imaging. An USB/Serial connection can handle the interface between the Arduino and the Raspberry PI.

However, it is not that straightforward to connect a Raspberry PI to the Arduino in this setup. The manufacturer recommends that the battery pack is disconnected before connecting to the USB port on the Arduino. There are two options to communicate between the Arduino and another computer:

  1. Keep the batteries and connect a cable to GPIO pins on the Arduino and Raspberry PI. Since the boards are operating on different voltages (5 V and 3.3 V respectively), I would need a level shifter in between.
  2. Remove the battery pack and connect the Arduino to the Raspberry PI. That would mean that the motors will get only 5 V. This is the easiest solution, I'll maybe explore the other solution later. Another advantage is that I'll reduce the weight of the vehicle.

I've replaced the battery pack with a LEGO rig for the Raspberry PI computer. 

In the next blog post, I'll modify the code of the Arduino so that I can send commands to it via the Raspberry PI.

Saturday, 11 September 2021

IOT: Designing the Arduino Part of the Face Recognition System

After finalizing the Stock Analyzer project, installing Solar Panels to my house and exploring Quantum Computers, I will continue with my IOT project. 

I am currently able to detect a face using OpenCV on a laptop. The next step will be to migrate that functionality to a headless Raspberry PI that is connected to an Arduino. In this blog post, I will design the Arduino board.

The person in the picture is more similar to James Dean than to Marlon Brando and Audrey Hepburn.
 Training data is very limited, with only 20 pictures of three celebrities, and that causes the identifier to perform poorly

The Arduino Panel
When a user is pressing a button on Arduino, the RPI will take pictures every x seconds. It will try to identify the faces on the last picture. If a face is identified, it will send the corresponding name back to the Arduino. The names will show on the LCD and corresponding LED's will activate. If faces are detected but not identified, an alarm will activate. 

The Piezo element and the red LED to the left are used for alarms.
The button sends a start/stop signal to the connected Raspberry PI computer.
The four LEDs to the right identifies four persons. 


There are three cases:
  • No face is detected on the last picture
  • At least one familiar faces - disable the alarm, if active.
  • No familiar faces - start an alarm.


Saturday, 21 August 2021

Using a Quantum Computer to Roll a Dice

There has been some buzz about Quantum Computers (QC) over the last years. The QC's that are in use today are very limited but the capacity is growing rapidly. QC advocates hope to see computers that can solve problems much faster than classical computers can do. Other fear that some of the current cryptography systems may be broken with Quantum algorithms, such as Shoor's algorithm.

In this post, I will show how easy it is for a random blogger to create a simple Quantum algorithm and run on a Quantum computer.

Really Cool.
Coolness level: 15 mK ( -273.13 degrees Celsius)


Why a Dice?

There are tons of electronical dices out there. But they are made for classical computers and classical computers are built to be predictable. So if you know the random seed and the algorithm for the random generator, it is possible to predict the outcome of a dice. 

For a physical dice, it is also possible (in theory) to predict the outcome, given the rotation, position and thetranslational movement of the dice, combined with the surface and athmospheric conditions of the environment. 

For Quantum Computers, the outcome is by it's very nature random. The randomness comes from a superpositon of two equal states that collapses into one state.

Step 0: Foundations

I strongly recommend taking a university level course in quantum mechanics to get familiar with the basic concepts. 

I enjoyed reading Jack Hidary's book Quantum Computing: An Applied Approach



Anastasia Marchenkova has an interesting Youtube channel where she covers up-to date material about Quantum Computing.

If you're really short on time, you can see Wired's five levels of difficulty introduction to Quantum Computing


Step 1: Accessing IBM Quantum (Web)

The second step is to create an account on IBM Quantum. IBM Quantum allows the general public to upload programs to QC's and run for free.

Once I've got an account, I can create programs to run, either on a simulated or physical Quantum computer. There is an online Development Editor that is useful for learning. 


Step 2: Create and Run a Simple Program:
It is quite easy to add elements to the program - click and drag elements to the proper places.


In the program above, I use two Qubits. One is set to a superposition of |0> and |1>. The other Qubit is entangled with the first Qubit. Finally, both Qubits are measured, one by one.

To run the program on a QC, I select "Setup and Run", where I can select the QC or simulator to use
After the completion, I explore the result:

Theory says that both Qubits shall have the same value. This happens most of the times, but sometimes the Quantum Computer fails. This means that there should be some caution when looking into the results of these kinds of QC's.


Step 3: Creating the Dice from Python

I prefer to write the program in Python and it is easy to do it using the API key

The Python program is using qiskit (one of the more popular syntaxes for Quantum Computing).


The program sets up three Qubits that are set into a superposition of |0> and |1> (50% likelihood each). It is measuring the three qbits individually and the result is saved to a binary bitmask of size 3 ("000" -> "111"). To map the bitmask to a six sided dice, I repeat the circuit until I get "001"/1 up to "110"/6. This is the output from the dice.
The red text is a hardcoded warning that I 
wasn't able to supress. 
The dice repeated once, but the final value was 1.

That's it. There are no excuses. YOU can program a quantum computer and YOU can run the program on a physical quantum computer.

Saturday, 31 July 2021

Silence Doesn't Mean Inaction

My blog has been silent for a couple of months. This often happens when I focus on other projects - and I think it should be that way. 

Children: Spending time with a baby and a pre-school infant is sometimes challenging, always rewarding.

Work: In my new position (same company), I have more challenging and interesting tasks than before. I create reports, make changes in the test framework and work closer to the hardware. As I've had a steep learning curve at work, I've had a much slower pace for my pet projects.

Home: We have had a major renovation project in our house, including:

  • A new roof
  • Solar panels on the new roof (not yet connected to the power grid). More details on my other blog.
  • Wood floor for the attic
  • Replacing the side panels
  • Installing a skylight window
  • Installing a wood stove

The project took two months of time and I didn't have time to focus on pet projects. 

As I've entered a long parental leave and we have no (major) projects in the house in a near future, I hope to have more time for pet projects. 

Saturday, 1 May 2021

Python: Learning OpenCV and Detecting Faces from a Live Camera

The next step for my IOT project is to use facial recognition so that the Raspberry P can decide whether or not to alert the home owner.

I'll use OpenCV for this part. OpenCV is a very capable free package for computer vision and imaging.

OpenCV can be installed for Python and comes in four different options:

  1. Main modules: opencv-python
  2. Main modules with extra modules such as contributions from the opencv community: opencv-contrib-python
  3. Headless mode (no GUI modules): opencv-python-headless
  4. Headless mode with extra modules: opencv-contrib-python-headless

As I want to use it in a headless Raspberry Pi later, I'll go for the first option for development and the fourth option for deployment.

Detecting a face using openCv is a two step process:

1. Detect the faces in a picture

2. Identify a face from step 1. That will require a training set of some images of the person that shall be identified.

Face Detecton

OpenCV is using Haar Cascades to detect various objects such as faces, eyes, mouths and license plates for example. The models are available as xml files at the OpenCV Github repository and no machine learning training will be necessary for this step. 

After downloading the file haarcascade_frontalcatface to a local folder, my script will apply the Haar cascade model to a webcam session:


The Haar cascade algorithm is quite sensitive to noise. In the image below, five faces were detected, but only one face was authentic.

In the right region, some false faces were detected.


It is possible to reduce the risk of false faces by tweaking some parameters, but then the risk of missing authentic faces increases. Below are some faces of Hollywood celebrities that weren't detected by the algorithm:

It seems that the algorithm fails detecting faces that are tilting too much. Shadows in the faces can also confuse the algorithm.

In the next blog post. I'll try to train an existing algorithm to identify faces.