Created
February 6, 2020 18:24
-
-
Save lydonchandra/6b24bacee6827df797a95ccd43783c9f to your computer and use it in GitHub Desktop.
detect_blur_photos.py
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
from imutils import paths | |
import argparse | |
import cv2 | |
from multiprocessing import Pool, TimeoutError | |
def ResizeWithAspectRatio(image, width=None, height=None, inter=cv2.INTER_AREA): | |
dim = None | |
(h, w) = image.shape[:2] | |
if width is None and height is None: | |
return image | |
if width is None: | |
r = height / float(h) | |
dim = (int(w * r), height) | |
else: | |
r = width / float(w) | |
dim = (width, int(h * r)) | |
return cv2.resize(image, dim, interpolation=inter) | |
def variance_of_laplacian(image): | |
# compute the Laplacian of the image and then return the focus | |
# measure, which is simply the variance of the Laplacian | |
return cv2.Laplacian(image, cv2.CV_64F).var() | |
folder = "c:\photos" | |
threshold = 100 | |
blurry_photos = [] | |
def is_blur(imagePath): | |
image = cv2.imread(imagePath) | |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
fm = variance_of_laplacian(gray) | |
if fm < threshold: | |
print("Blurry " + str(fm) + imagePath) | |
blurry_photos.append( imagePath ) | |
else: | |
print("NOT blurry " + str(fm) + " skipping " + imagePath) | |
if __name__ == '__main__': | |
with Pool(processes=6) as pool: | |
pool.map(is_blur, paths.list_images(folder)) | |
for blurry in blurry_photos: | |
print(blurry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment