AdaFace
模型,对低质量人脸
表现尤为突出。阈值分类
,符合要求的进行特性提取质量分数
模糊程度
,图片字节大小
,人脸姿态评估(欧拉角)
等 算出一个综合质量分,用于人脸归类/聚类对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
模糊度检测算法来自 :https://pyimagesearch.com/2015/09/07/blur-detection-with-opencv/
具体实现方式小伙伴可直接看原文
这种方法起作用的原因是由于
拉普拉斯算子
本身的定义,它用于测量图像的二阶导数。拉普拉斯突出显示包含快速强度变化的图像区域,与 Sobel 和 Scharr 算子非常相似。而且,就像这些运算符一样,拉普拉斯通常用于边缘检测
。这里的假设是,如果图像包含高方差,则存在广泛的响应,包括边缘类和非边缘类,代表正常的焦点图像。但是,如果方差非常低,则响应的分布很小,表明图像中的边缘非常小
。众所周知,图像越模糊,边缘就越少
下面为原文的 Demo
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File : detect_blur.py
@Time : 2023/07/24 22:57:51
@Author : Li Ruilong
@Version : 1.0
@Contact : [email protected]
@Desc : 图片模糊度检测
"""
# here put the import lib
# import the necessary packages
from imutils import paths
import cv2
import os
def variance_of_laplacian(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(gray, cv2.CV_64F).var()
# loop over the input images
for imagePath in paths.list_images("./res/mh"):
# 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)
fm = variance_of_laplacian(image)
text = "Not Blurry"
print(fm)
# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < 100:
text = "Blurry"
# show the image
file_name = os.path.basename(imagePath)
cv2.imwrite(str(fm)+'__' + file_name , image)
核心代码:
cv2.Laplacian(gray, cv2.CV_64F).var()
如果为 Image.image
,可以使用下的方式
def variance_of_laplacian(image):
"""
@Time : 2023/07/25 01:57:44
@Author : [email protected]
@Version : 1.0
@Desc : 模糊度检测
Args:
Returns:
void
"""
numpy_image = np.array(image)
cv2_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
gray = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2GRAY)
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(gray, cv2.CV_64F).var()
实际测试中发现,阈值设置为 100 相对来说比较合适,当然如何数据集很大,可以考虑 提高阈值,当模糊度大于 1000 时,一般为较清晰图片,低于 100 时,图片模糊严重
下面为对一组较模糊数据进行检测
最后一个图像,模糊度为 667 ,其他为 200 以内
(AdaFace) C:\Users\liruilong\Documents\GitHub\AdaFace_demo>python detect_blur.py
130.99918569797578
97.54477372302556
70.30346984100659
95.56028915335366
77.70006004883219
107.2065965492792
93.43007114319839
75.44132565995248
127.50238903320515
98.11810838476116
69.49917570127641
132.46578324273048
99.2095025510204
92.97255942246558
93.33812691062155
667.4883318795927
© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知
https://pyimagesearch.com/2015/09/07/blur-detection-with-opencv/
© 2018-2023 [email protected], All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)