Python检测高斯模糊

我有以下代码来检测输入图像是否模糊。

from imutils import paths
import argparse
import cv2
import os

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=100.0,
    help="focus measures that fall below this value will be considered 'blurry'")
args = vars(ap.parse_args())

# 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)
    text = "Not Blurry"

    # if the focus measure is less than the supplied threshold,
    # then the image should be considered "blurry"
    if fm < args["threshold"]:
        text = "Blurry"

要使用该脚本,我运行以下命令:

python detect_blur.py --images images

where images is the folder name containing a series of photos.

但是,结果是非常不准确的(考虑到拉普拉斯值<100被认为是模糊的,可以将其分类):

它检测到该照片模糊(正确,拉普拉斯值= 1.26):

Blur Photo

但是它也检测到这张照片也模糊了(不正确,拉普拉斯值= 62.9):

Not blurry photo

如何使代码更准确?我想专门检测高斯模糊,如何更改代码?