Source code for lavaflow.pipes.tracking

"""Pipes for apply feature tracking.
"""

import cv2

from lavaflow.pipes.core import AbstractPipe

import logging
logger = logging.getLogger('lavaflow')


# -----------------------------------------------------------------------------

# OpenCV feature + descriptor matcher tracking

[docs]class FeatureDescriptorMatchingWindowPipe(AbstractPipe): """Pipe for applying a function to each dictionary in an iterable to map an input key to an output key. """ def __init__(self, feature_tracker, x, y, z): """Constructor. Args: feature_tracker (FeatureDescriptorMatching): feature descriptor matching x (str): image key y (str): boundary key z (str): output key Returns: self (FuncPipe): pipe """ self.feature_tracker = feature_tracker self.x = x self.y = y self.z = z
[docs] def map(self, window): """Map. Args: window (list): window of items Returns: d (dict): item with feature tracking """ N = len(window) w1 = window[0] w2 = window[N - 1] img1 = w1[self.x] img2 = w2[self.x] boundary1 = w1[self.y] boundary2 = w2[self.y] p1, p2, mask = self.feature_tracker(img1, img2, boundary1, boundary2) d = window[-1] d[self.z] = { 'p1': p1, 'p2': p2, 'mask': mask, } return d