OpenCV and AHS Heatmap | Automatically Finding Rooms in an Image (Part 1)

This is part 1 of a series of blog posts about the computer vision behind the AHS Heatmap.

As I was designing the AHS Heatmap, one of my main goals was to create software that was not bound to any specific floor map. That is to say, I did not want the software to be designed for a specific set of SVG floor plans or rely on a manually-labeled list of room coordinates to know which rooms were on the current floor, which color to fill them with, and where to place the colored rectangle. By designing it in this way, the program would have the potential to be applied to all of Andover’s public schools, not solely Andover High School. Implementing this, however, proved to be quite complicated.

Throughout this post, I will introduce the tools behind this process and the file format that will be worked with.

Input Format

AHS Heatmap takes in a folder of SVG floor maps. These equate to enormous vector images (those of AHS are roughly 11,000 by 8,500 pixels). SVGs are quite difficult to work with programmatically - although their status as essentially “programmed” images makes them great to work with directly or within websites, the vast difference between the content of an SVG and a standard image format, such as a PNG or a JPG, makes SVGs unusable by many image-processing tools and libraries.

A sample floor plan from AHS is shown below: Andover High School Level 4 Floor Plan

OpenCV

OpenCV is a massively popular computer vision library with implementations in many languages, including Python. It is free-to-use and very well-documented, so I decided to employ it for the heatmap’s computer vision.

Converting SVGs to PNGs

The heatmap depends on Inkscape a free vector graphic design tool. Inkscape uniquely has a command-line interface that allows the usage of Inkscape to convert SVGs to PNG images (alongside many other formats) with a great degree of flexibility. This worked out very well for the project the ability to utilize Inkscape’s conversion functionality without GUI meant that the heatmap could be deployed to SSH-only machines, such as the Google Compute Engine virtual machine upon which it is currently hosted.

Converting SVGs to PDFs

Although the reasoning behind my need for this functionality may not be clear just yet, it will be explained in part 2 of this series. It turns out that Inkscape’s CLI is also capable of performing this kind of conversion.