Last active
October 21, 2019 13:49
-
-
Save jagin/461e68861b091721b90e82c1c0e56da3 to your computer and use it in GitHub Desktop.
Loading images pipeline step (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
import cv2 | |
from pipeline.pipeline import Pipeline | |
import pipeline.utils as utils | |
class LoadImages(Pipeline): | |
def __init__(self, src, valid_exts=(".jpg", ".png")): | |
self.src = src | |
self.valid_exts = valid_exts | |
super(LoadImages, self).__init__() | |
def generator(self): | |
source = utils.list_images(self.src, self.valid_exts) | |
while self.has_next(): | |
image_file = next(source) | |
image = cv2.imread(image_file) | |
data = { | |
"image_file": image_file, | |
"image": image | |
} | |
if self.filter(data): | |
yield self.map(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment