Close

First OpenCV experiments

A project log for Where's my Christmas Light?

Quickly identifying individual LEDs in a randomly distributed arrangement

Danny HavenithDanny Havenith 01/31/2016 at 15:330 Comments

Now that the LEDs are blinking, it's time to start working on the recognition software (ongoing experiments on GitHub). The plan is to use OpenCV, and more specifically OpenCVs SimpleBlobDetector to recognize the LEDs.

Feature detection with SimpleBlobDetector is fairly easy:

Mat cooked = ...;
SimpleBlobDetector::Params params;
params.minDistBetweenBlobs = minDistance;
params.filterByInertia = false;
params.filterByConvexity = false;
params.filterByColor = false;
params.filterByCircularity = false;
params.filterByArea = true;
params.minArea = minArea;
params.maxArea = maxArea;

Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
vector<KeyPoint> features;
detector->detect(cooked, features);

The idea was to filter the blue (or red) parts of the image and then running the blob detector to find the blue (or red) spots.But not everything is as simple as it seems: using default parameters to the blob detector resulted in finding zero LEDs. Luckily, OpenCV allows you to quickly create some sliders in a UI that allowed me to tweak the parameters until a reasonable match was made, that looked like the image at the top of this log entry.

The most important parameters appear to be minimum- and maximum area size and minimum distance between blobs, but I suspect that these parameters are very much dependent on circumstances like distance to the LEDs, brightness settings of both the video and the LEDs, etc.

So at this point, there are some things to consider:

Because over-engineering is fun, my next step is going to be to try Nelder-Mead on the blob detector parameters...

Discussions