Last active
October 21, 2019 13:48
-
-
Save jagin/e10d829410642e2effaf1bf23c7167cb to your computer and use it in GitHub Desktop.
Pipeline class (see https://medium.com/deepvisionguru/modular-image-processing-pipeline-using-opencv-and-python-generators-9edca3ccb696)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pipeline(object): | |
def __init__(self): | |
self.source = None | |
def __iter__(self): | |
return self.generator() | |
def generator(self): | |
while self.has_next(): | |
data = next(self.source) if self.source else {} | |
if self.filter(data): | |
yield self.map(data) | |
def __or__(self, other): | |
other.source = self.generator() | |
return other | |
def filter(self, data): | |
return True | |
def map(self, data): | |
return data | |
def has_next(self): | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment