Blob detection, tracking and serial communication to esp32 through IBus protocol using an OpenMV compatible edge camera device. Currently it has two modes:
- Pure color-based blob detection and tracking, which requires a fine-tuned threshold in LAB space. Look at OpenMV documentation on the function find_blobs for detailed reference.
- IR blinking-based detection for retro-reflective surfaces using a IR-filter-free lens. The camera captures two consecutive images with LED off and on, respectively, then compute pixel-wise difference to highlight the reflective surfaces in the environment. Refer to the initial tests on the reflective solution for more details.
- Under colored mode (
isColored = True
), the algorithm distinguishes the reflective surfaces with different colors. - Under grayscale mode (
isColored = False
), the algorithm does not distinguish the reflective surfaces with different colors.
- Under colored mode (
Both modes use the same moving-window-based tracking methods (see classes Tracking_ROI
and TrackedBlob
).
- Initialize the ROI as the maximum size of the image.
- Whenever a new detection is fed, find its bounding box.
- New ROI is a weight average of the current rectangular ROI and the detection bounding box.
- Initialization:
- find a reference blob by constraining the minimum roundness, density, and of course color
- initialize a feature vector and a history list of blobs based on the reference
- feature vector: a vector of {five} values marking the average center x, y position, width, height, and blob direction of the tracked blob history
- history: a list of blobs that the algorithm considers as the same blob through multiple frames
- Update: check the feature vector of the tracked blob against new detected blobs in terms of 1-norm/2-norm feature vector distance
- if the history list is full, pop the oldest, push the latest. Otherwise populate it.
- if the new blob feature vector is too far from the tracked blob, mark the tracked blob with an additional missed track
- if the tracked blob has too many missed tracks, reset the tracked blob history and feature vector, then go to step 1.ii.
- IR LED off, take image1.
- IR LED on (~2W power LEDs), take image2.
- Compute pixel-wise difference between image1 and image2 by
diff = image2 - image1
. - (Optional) Filter out differences due to motion by finding high-frequency edges on image1 and use them as a
mask
. - Negate
diff
to recover the original color of the reflective surfaces. - Find colored blobs on
diff
with regions marked withmask
masked out.
thresholds
: it determines the color to detect and track- In function
find_reference
,density_threshold
androundness_threshold=0.4
: they determine how strictly dense and round the initial blob needs to be. - In initialization of the
TrackedBlob
object currently in functionfind_reference
,norm_level
controls the distance type, 1-norm is faster and 2-norm is smoother (try both and feel the difference)feature_dist_threshold
controls how strict a feature vector match needs to bewindow_size
controls how long a history of tracked blobs the user wants to keep. Higher value gives a smoother but more draggy track
- If the nicla is connected to another device through uart, when it receives
0x80
, it will try to switch to balloon tracking mode. When it receives0x81
, it will try to switch to goal tracking mode. - In the initialization of
Tracking_ROI
objects,forgetting_factor
controls how rapid the bounding box is updated with respect to a new input or a new misinput.
id
: we would like to identify/distinguish different blobs.
We recorded the (manually-tuned) optimal color thresholds for balloon detection under different initial and ambient lighting consitions in this file.