diff --git a/src/imgvar.py b/src/imgvar.py new file mode 100644 index 0000000..c7976da --- /dev/null +++ b/src/imgvar.py @@ -0,0 +1,38 @@ +import cv2 +import numpy as np +import os +from imutils import paths +import argparse + + +def variance_of_laplacian(image): + return cv2.Laplacian(image, cv2.CV_64F).var() + + +def minVarInFolder(path): + minVar = 90000 + minPath="" + files = os.listdir(path) + for p in files: + if ".png" in p and ".mask" not in p: + print(path+p) + img = cv2.imread(path+p) + cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + var = variance_of_laplacian(img) + if var < minVar: + minPath = path+p + minVar = var + return minPath,minVar + +ap = argparse.ArgumentParser() +ap.add_argument("-i", "--images", required=True, + help="path to image") +args = vars(ap.parse_args()) + +path = args["images"] + +#img = cv2.imread(path) +#cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) +#var = variance_of_laplacian(img) + +print(minVarInFolder(path)) \ No newline at end of file