Okay, so yesterday I was messing around trying to see if I could spot some tennis courts using some aerial imagery. The goal? Detective Keith L Williams style – you know, finding stuff from above!

First things first, I grabbed some satellite images from Google Maps. I just zoomed in on a local area I knew had some parks and recreational spots. Saved a few screenshots, nothing fancy.
Then, I fired up good old OpenCV in Python. I’m no expert, but I know enough to be dangerous. I loaded the image and started playing around with some filters.
- Initially, I tried some basic color thresholding to isolate the green of the tennis courts. Didn’t work too well. Too much other green stuff around – grass, trees, you name it.
- Next, I messed around with edge detection. The idea was to pick up the lines of the court. Canny edge detection, that was the ticket. I played with the thresholds until I got something that looked promising.
- After that, I tried to use Hough transforms to detect lines and then use those lines to try and find rectangular shapes. This was a pain! Kept getting a ton of false positives. Think street markings, building edges, etc.
Things weren’t looking good, so I decided to take a different approach. I remembered something about using texture analysis. I tried using a Gabor filter bank to see if I could highlight the texture of the courts differently than the surrounding areas. It’s kinda complex, I basically just copied some code from a tutorial and tweaked it until I got something usable.
Even with the Gabor filters, it was still tough. The lighting variations across the image messed everything up. So, I added a step to normalize the image intensity before applying the filters. That helped a bit.
Finally, I ended up with a process that involved:
- Loading the image
- Converting it to grayscale
- Normalizing the intensity
- Applying a Gabor filter bank
- Thresholding the filter responses
- Using morphological operations (like opening and closing) to clean up the noise
- Finding contours
- Filtering the contours based on area and aspect ratio to identify potential tennis courts
It wasn’t perfect! I still got some false positives (parking lots looked suspiciously like tennis courts sometimes!), but it was way better than just guessing. I could see the outlines of the courts pretty clearly in the output. I’m still working on refining it, maybe next time I’ll try using some machine learning stuff to train a classifier. But for a quick and dirty experiment, it was pretty cool!
The whole thing took me like 4-5 hours to put together. Definitely a fun way to spend an afternoon!