ethall / LED-Timeline

Track changes in LED on and off states with OpenCV

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LED Timeline

Track LED on and off states with OpenCV.

A small personal project to see what's possible with Python + OpenCV.

⚠ WARNING ⚠

This code is awful. The whole thing is a hack. Use at your discretion.

Requirements

  1. Python 3.7+
  2. OpenCV
    I built my libraries from source (specifically, commit c722625f28). Pre-built binaries should work, but your milage may vary.

Steps

  1. Extract valid frames.
    Ran into an issue where trimming the video with the Android camera app resulted in a frame count larger than the number of readable frames. This is mitigated by extracting all readable frames from the given video.
  2. Denoising via the non-local means algorithm.
    The goal here is to smooth digital sensor noise in order to reduce its impact on changes in pixel value over time. This is extremely CPU intensive and will take a while to complete. While offloading this process to the GPU is an option, it makes the code (even) less portable since the CUDA SDK is required.
  3. Convert the video to grayscale.
  4. Calculate the change in pixel intensity over time.
    This causes each LED appear as though it only turns on for a single frame.
  5. Using Canny edge detection and contour tracing, search each frame and attempt to resolve a bounding rectangle. Once all bounding rectangles have been identified, the grayscale video is replayed and each area is analyzed. If the average pixel value of an area defined by a bounding rectange reaches a certain threshold, then that LED is considered "on".

License

MIT License

Copyright (c) 2020 Evan Hall

See the LICENSE file for more details.

About

Track changes in LED on and off states with OpenCV

License:MIT License


Languages

Language:Python 100.0%