-
Notifications
You must be signed in to change notification settings - Fork 2
/
single.py
46 lines (34 loc) · 1.54 KB
/
single.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
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import argparse
import logging
import cv2
import numpy
from blur_detection.detection import estimate_blur
from blur_detection.detection import fix_image_size
from blur_detection.detection import pretty_blur_map
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='run blur detection on a single image')
parser.add_argument('-i', '--input_image', dest="input_image", type=str, required=True, help="directory of images")
# parameters
parser.add_argument("-t", "--threshold", dest='threshold', type=float, default=100.0, help="blurry threshold")
parser.add_argument("-f", "--fix_size", dest="fix_size", help="fix the image size", action="store_true")
# options
parser.add_argument("-v", "--verbose", dest='verbose', help='set logging level to debug', action="store_true")
parser.add_argument("-d", "--display", dest='display', help='display images', action="store_true")
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
assert os.path.exists(args.input_image)
input_image = cv2.imread(args.input_image)
if args.fix_size:
input_image = fix_image_size(input_image)
blur_map, score, blurry = estimate_blur(input_image)
logging.info("score: {0}, blurry: {1}".format(score, blurry))
if args.display:
cv2.imshow("input", input_image)
cv2.imshow("result", pretty_blur_map(blur_map))
cv2.waitKey(0)