From 66942b9b4b895e6a2399b4f3dfa0c6bad8d20b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 24 Feb 2018 20:25:05 +0100 Subject: [PATCH] Refactor image loading to class imgrate --- imgrate.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/imgrate.py b/imgrate.py index 761d61f..cc9b923 100755 --- a/imgrate.py +++ b/imgrate.py @@ -16,8 +16,13 @@ def image_required(fun): class imgrate: - def __init__(self, image=None): - self.image = image + def __init__(self, imgfile=None): + self.image = None + if imgfile: self.load_image(imgfile) + + def load_image(self, imgfile): + image = cv2.imread(imgfile) + self.image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) @image_required def laplacian_variance(self): @@ -38,7 +43,4 @@ if __name__ == '__main__': ap.add_argument('images', type=str, nargs='+', help='') args = ap.parse_args() - image = cv2.imread(args.images[0]) - grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - - print(imgrate(grayscale).laplacian_variance()) \ No newline at end of file + print(imgrate(args.images[0]).laplacian_variance())