forked from deepshakes/BlurryFrameRemover
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblurryframeremover.py
43 lines (37 loc) · 1.4 KB
/
blurryframeremover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# import the necessary packages
from imutils import paths
import argparse
import cv2
import shutil
import os
import time
import sys
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()
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True,
help="path to input directory of images")
ap.add_argument("-t", "--threshold", type=float, default=10.0,
help="focus measures that fall below this value will be considered 'blurry'")
args = vars(ap.parse_args())
# Create folder for blurry pics if it doesn't already exist
if not os.path.exists("./blurry"):
os.makedirs("./blurry")
# loop over the input images
for imagePath in paths.list_images(args["images"]):
# load the image, convert it to grayscale, and compute the
# focus measure of the image using the Variance of Laplacian
# method
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = variance_of_laplacian(gray)
clarity = str(fm).split(".")[0]
if fm < args["threshold"]:
print("Blurry image detected. Clarity level: " + clarity)
# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < args["threshold"]:
shutil.move(imagePath, "./blurry")