CV2: Detecting pools from high quality aerial imagery

Intro

HSV-visualized.png

This projects aim was to detect objects (pools) from high quality satellite imagery. Initially I was going to use a CNN (convolutional neural network) to detect pools, however I soon realized the problem could be approached using a more simple approach. After researching for some time I came across cv2 in python which is able to detect shapes within images or video, as well as process contours/bounding boxes/coordinates and merge them with the images. This solution seemed viable and the learning curve was much smoother than it would be having gone down the CNN route.

Going forward with the cv2 approach I came across several pros and cons. The advantages of tackling the problem this way is

  • Flatter learning curve
  • Fairly fast processing times

Also comes with disadvantages:

  • It probably cannot detect empty or dirty pools (a different colour other than blue)
  • Can be tricky to fine tune, it is an exhaustive approach to optimization

Repository

You can download the current repository here. This repo contains all the code required to process images and detect pools, given the configuration at the time of the most recent update. Currently the code is able to detect pools from geo-referenced images, paint contours, export resulting images, reverse geocode locations back to long and lat (centroids of bounding boxes located).

Clone the repo
git clone https://github.com/danielc92/pool-detection.git

Data

The data I previously scraped from an aerial imagery web service called spookfish, gave me a great starting point. I automatically downloaded over 1500 high resolution images of Bayside Council, and these image sole purpose should not be for detecting pools, but their quality will allow for training models of all sorts.

Concepts

There were several concepts/libraries I had to learn going forward with this piece of work. cv2 computer vision python library is part of almost all object detection frameworks, however I have never used it in isolation. Learning about the colour space in HSV (Hue Saturation Value) format was also important.

  • Understanding the HSV colour space
  • Trialing and error approach to finding the right colour range for pools
  • Learning how to draw contours/bounding boxes around objects
  • Filtering those contours by area to eliminate noise

Results

I’m fairly happy with the results at this point in time, being less than a weeks work. Essentially with this code you can find all the specs of blue within a spectrum of blue defined in your HSV colour space range. Filter those contours down by area/perimeter then save those coordinates. Since the images I scraped were geocoded I can translate those pixel coordinates into approximate long lats too. There is also a huge amount of permutations for the config file, so it can be modified to suit other circumstances and produce different results.

 

2019-01-10 11_53_56-untitled2019-01-10 11_53_51-untitled2019-01-10 12_09_28-untitled2019-01-10 12_09_33-untitled2019-01-10 11_52_44-untitled2019-01-10 11_52_52-untitled2019-01-10 11_53_17-untitled2019-01-10 11_53_23-untitled2019-01-10 11_53_41-untitled2019-01-10 11_53_36-untitled

Sources

Here are some of the sources I used to implement this piece of work, without them I would have gotten nowhere.

Leave a comment

Website Built with WordPress.com.

Up ↑