Detect red circles in an image using OpenCV
Posted on May 8, 2015 by Paul
The code for this post is on GitHub: https://github.com/sol-prog/OpenCV-red-circle-detection.
A few days ago someone asked me, in an email, if it is possible to detect all red circles in an image that contains circles and rectangles of various colors. I thought this problem could be of certain interest to the readers of this blog, hence the present article.
From the many possible approaches to the problem of red circles detection, two seem straightforward:
- Detect all circles from the input image and keep only the ones that are filled with red.
- Threshold the input image in order to keep only the red pixels, search for circles in the result.
I found the second approach to be slightly better than the first one (less false positives), so I am going to present it in this post.
Raspberry Pi - Building SDL 2 on Raspbian
Posted on January 22, 2015 by Paul
This is a short tutorial on how to get started with SDL 2 programming on a Raspberry Pi device that has Raspbian installed. If you want to write C++, or C, games that are easily portable to other platforms SDL 2 is the way to go on Raspbian. Unfortunately, at the time of this writing Raspbian comes with the outdated SDL 1.2 installed.
Let’s start by updating our Raspbian installation, feel free to skip this step if your system was recently updated:
Getting started with JOGL (OpenGL bindings for Java) in Eclipse
Posted on December 8, 2014 by Paul
Recently, a reader of my OpenGL 101 series emailed me about how to get started with OpenGL in Java. More specifically, he was interested in JOGL the Java bindings for OpenGL. I thought his question was general enough to write a small post about creating a Java OpenGL getting started project.
JOGL is a good fit for a Java programmer that wants to learn OpenGL, it is particularly useful if you follow some OpenGL intro book or article. If you are more interested in writing Java games, you should check a more game friendly library like LWJGL or, even better, libGDX.
C++14 lambda tutorial
Posted on August 28, 2014 by Paul
The last iteration of C++, C++14 was approved this month. C++14 brings a few much anticipated changes to the C++11 standard, like allowing auto to be used as the return type of a function, or generic lambdas - the subject of this article.
Lambdas, in C++, were introduced by the C++11 standard. They were meant to let the coder write short, anonymous functions, that could be used instead of a function object, avoiding the need to create a separate class and a function definition. Here is a typical example of C++11 lambda usage, that returns the square of a number:
If you need to reuse the same piece of code in more than one place, you can save the function in a variable:
C++14 auto tutorial
Posted on August 21, 2014 by Paul
The C++14 standard was recently approved. Without bringing big changes to the language, like the previous standard did, the C++14 standard aims to make the programmer’s job easier by improving the C++11 standard.
C++11 introduced the auto keyword (technically auto was present even in the C++03 standard, however C++11 changed the meaning of auto), auto was meant to make the code cleaner and less error prone, by letting you write for example:
instead of:
Remote text editing with SublimeText and TextMate
Posted on August 16, 2014 by Paul
A common problem for most server administrators and web programmers is how to edit text files quickly and efficiently on the server. For the Emacs and Vim gurus this is not really a problem, they’ll just install some plugin and do their work. What about the other 90% of the world, the mere mortals, that don’t know how to use one of the above editors ?
Some people will use a ftp client, like FileZilla, edit their files locally, with their preferred text editor, and upload the result to the server. Others, will chose to edit directly from a ftp client using the default text editor of their main OS (which on Windows, the horror …, is Notepad or on OSX is TextEdit). The savvy user will set his ftp client to use a more approachable, and usable, text editor like SublimeText, NotePad++, gEdit etc … The problem with using a ftp client to locally edit some file is that it is slow and somehow uncomfortable, at least for me.
In the next part of this post, I will assume that you have administrator rights on your web server and that this server runs on a different machine than your main computer. Another implicit assumption is that you want to use a text editor like SublimeText 3, which runs on all major operating systems, or TextMate 2 which runs only on OSX.
Increase your productivity with the Pomodoro technique
Posted on August 14, 2014 by Paul
A few years have past since I’ve started to work from home, during this time I’ve had my up and downs in productivity. In the beginning, there were more downs than ups, it was simply too tempting to lose an entire day reading various blogs, and articles and since nobody was there to ask me how I spent my day it was easy to lose track of time. Despite the popular beliefs, good and bad habits are built in similar amounts of time.
After a few weeks of working hard to achieve my Master Procrastinator diploma, I’ve realized that I was basically stilling my own time and slowly burning through my savings. It become clear to me that this path will end with me, again, working for someone else instead of working for me and on my own terms. Did I mentioned that I hate working for someone else ?
I always knew that in order to finish something you need to work on it every day, for a few hours, until it is done. The key here is to be completely focused on the task and to not exhaust yourself. I was always good at working full time, from 8 AM to 10 PM, for a few days. The problem with this approach was that after a few days of intense work I was burn out for the same number of days, or even more. When I feel dried out I tend to procrastinate by reading random stuff on forums like Hacker News or Reddit. I don’t remember exactly the context, but in one of my recovering sessions I read about the Pomodoro method as a way of slowly building discipline and improving focus by following a simple recipe:
Getting started with OpenCV on the BeagleBone Black with Ubuntu 14.04 LTS
Posted on April 21, 2014 by Paul
18 December 2018
If you prefer to cross compile the latest version of OpenCV for your BeagleBone Black check this article that uses Debian Stretch.
I’ve recently bought a BeagleBone Black for some computer vision and home automation projects I intend to do sometime in the future. BeagleBone has Ångström Linux already installed on the 2GB eMMC card. I have nothing against Ångström, but I prefer to run Ubuntu headless on this tiny computer. Also, Ångström has g++-4.7.2 as the default C++ compiler and I want to be able to use a newer compiler, like the g++-4.8.2, for C++11 development.
As a side note, the next revision of the BeagleBone Black will support Debian Wheezy out of the box, which has an even older C++ compiler than Ångström.
If you want to be able to run Ubuntu and build OpenCV on the BeagleBone Black, you will need a micro SD card of at least 8GB, I recommend buying one of class 10. Personally, I bought a SanDisk micro SD card of 16 GB.
Modular JavaScript development with Browserify and LivePage
Posted on February 5, 2014 by Paul
Working on a medium to large scale JavaScript project was always a challenge. Just picture yourself editing a few thousands lines of code in a single source file! Fortunately, the next version of the JavaScript standard, ECMAscript 6, is going to give us modules. Personally, I think that the golden standard for JavaScript modules is the Node.js model, what could be more elegant than to write:
and instantly have access to everything was exported in the required module ?
In the past, a possible solution to the above problem was to use an AJAX call to load a piece of JavaScript code in another file, e.g. jQuery.getScript(). More recently, like a few years ago, RequireJS become the state of the art approach. With RequireJS you would write:
this gives us a callback function that will fire once the required module is loaded. But, what if you want something even simpler, something that looks more like the Node.js syntax, or Lua’s require, or other languages ? Enter Browserify!
Compiling Xfoil on OS X
Posted on January 23, 2014 by Paul
If you are into airfoil analysis as an amateur or as a professional you will need a quick way to estimate the aerodynamic characteristics (lift, drag and momentum coefficients) of a given airfoil. The classical approach to calculate the performance of an airfoil is to use a coupled inviscid/viscous flow solver. On a modern computer this analysis will usually take less than a minute. Compare this with a full CFD approach that uses the Navier-Stokes equations for the laminar part of the flow and the Reynolds Averaged Navier-Stokes equations for the turbulent part of the flow. In the former case a typical analysis can run from a few minutes to a few hours on a modern PC.
Xfoil is an open source interactive program for the design and analysis of subsonic isolated airfoils. Xfoil uses a potential flow solver coupled with a Boundary Layer solver to calculate the flow field around an airfoil. The author, Mark Drela, provides a Windows binary on Xfoil’s web page. If you are a Linux user building Xfoil from sources is straightforward. For OS X, well, it is a bit more complicated to build the code from sources.
OpenGL 101: Matrices - projection, view, model
Posted on May 22, 2013 by Paul
The code for this post is on GitHub: https://github.com/sol-prog/OpenGL-101.
This is the fourth article from my OpenGL 101 series, if you need to refresh your memory you can find a list with my previous articles at the end of this post or, you can click on the OpenGL category from the right sidebar.
Until now we’ve used the default OpenGL view for drawing our geometries and textures. While it is possible to draw any 2D geometry we can think of using the default [-1, +1] x [-1, +1] space that OpenGL sets for us, it will quickly became cumbersome and inefficient. Consider the problem of drawing four equilateral triangles, with different positions and orientations, like in the following figure:
OpenGL 101: Textures
Posted on May 17, 2013 by Paul
The code for this post is on GitHub: https://github.com/sol-prog/OpenGL-101.
This is the third article from my OpenGL 101 series. In the first two articles we’ve seen how we can open a window and draw OpenGL primitives: points, lines and triangles. We’ve also seen how we can assign a particular color to a vertex and use this to paint a two-dimensional surface with a smooth color.
Suppose now that we want to draw something more complex like the ruins of an ancient building, think a bit about how we can draw something as close as possible to what we can see in the real world. Theoretically, we can model everything with triangles and calculate the colors corresponding to each vertex, but this quickly gets out of hand - we are limited by the memory of our graphics card and by the speed of our graphics processor. A much practical approach to create the illusion of reality is to use textures that can be glued on the geometrical representation of our computer world.
In this article, we will concern ourselves only with two-dimensional textures, OpenGL can use other type of textures: 1D, 3D, cube textures etc … Technically a texture is just a container for data, you can store any numerical values in a texture, usually color values, and process this data in your shaders, usually in the fragment shader.
OpenGL 101: Drawing primitives - points, lines and triangles
Posted on May 13, 2013 by Paul
The code for this post is on GitHub: https://github.com/sol-prog/OpenGL-101.
This is the second article from my OpenGL 101 series. In the first article we’ve seen how to open a window for our OpenGL application with the GLFW library and how to compile and run the code on Windows, OS X and Linux. It is time to actually draw something using OpenGL.
First, let me mention that OpenGL is a low level API, this means that it has no support for drawing complex geometrical objects. It is the programmer’s job to combine the geometrical primitives from OpenGL in complex shapes and bodies. The basic geometrical primitives that the core OpenGL profile provide to us are points, lines and triangles.
OpenGL 101: Windows, OS X and Linux - Getting Started
Posted on May 10, 2013 by Paul
The code for this post is on GitHub: https://github.com/sol-prog/OpenGL-101.
This is the first in a series of articles that will get you up to speed with programming in modern OpenGL. I have no claim about being an expert in the area, this is an edited version of the notes I took working on various OpenGL projects in the last year. I think the best way to really understand a subject is to try to teach it to another person. Constructive comments are welcome and I will update this series based on your comments.
First step in creating an OpenGL code is the creation of a window, using the underlying OS, and to attach an OpenGL context to it, OpenGL by itself can’t open a window. Using a particular OS APIs to create a new window will make our code non-portable; the usual approach is to use a library that abstracts the process of creating/destroying windows on a given OS and also manages the user’s inputs through mouse, keyboard or touch. There are a number of libraries that can abstract the process of creating an window for us, like, in no particular order, GLUT, Freeglut, SDL, GLFW and many others.
In these notes, we are going to use GLFW because it is a small, flexible and modern library, portable on all major operating systems.
Other useful libraries that we are going to use are GLEW - this will let us use the latest OpenGL functions in a portable way, GLM - a small mathematical library and FreeImage for reading and writing images in various formats.
The Mandelbrot set in C++11
Posted on February 28, 2013 by Paul
The code for this post is on GitHub: https://github.com/sol-prog/Mandelbrot_Set.
Yet another how to draw the Mandelbrot set article ? Well, yes and no, on the one hand fractals are fun and on the other hand, it could be instructive to play with complex numbers and lambdas in C++11. Also, the article presents a not so common continuous coloring procedure based on a slight modification of the Bernstein polynomials.
Please note, that calculating the Mandelbrot set can be done more efficiently if one uses the GPU (using OpenGL shaders for example) and not the CPU.