python模糊图片过滤的方法
作者:digta 时间:2022-07-01 04:37:16
最近在做人脸识别清洗样本的工作,发现经过人脸对齐后存在部分图片十分模糊,所以用opencv滤了一下。
原理就是使用了cv2.Laplacian()这个方法,代码如下。图片越模糊,imageVar的值越小,图像越模糊。
#-*-coding:utf-8-*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import os
import cv2
import shutil
THRESHOLD = 30.0
dst_root = r'/media/unionpay/0009FFAB000A9861/CASIA&KFZX_CLEAR'
for fpath, dirs, fs in os.walk('/media/unionpay/0009FFAB000A9861/CASIA&KFZX'):
i = 0
for dir in dirs:
i += 1
if i%100 == 0:
print (str(i)+'folders processed current:'+dir)
abs_dir = os.path.join(fpath, dir)
for _, __, fs in os.walk(abs_dir):
clear_img_list = []
for f in fs:
item = os.path.join(_, f)
image = cv2.imread(os.path.join("/media/unionpay/0009FFAB000A9861/CASIA&KFZX/0000447", item))
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
imageVar = cv2.Laplacian(gray, cv2.CV_64F).var()
if not imageVar < THRESHOLD:
clear_img_list.append(item)
dst_folder = os.path.join(dst_root, dir)
if len(clear_img_list) >= 15:
if not os.path.exists(dst_folder):
os.mkdir(dst_folder)
for item in clear_img_list:
dst_path = os.path.join(dst_folder, item.split('/')[-1])
shutil.copy(item, dst_path)
来源:https://blog.csdn.net/u014642834/article/details/78532798
标签:python,模糊,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python数组的复制与列表中的pop
2021-07-10 12:05:24
![](https://img.aspxhome.com/file/2023/4/67944_0s.png)
如何使用repr调试python程序
2023-10-11 21:39:15
js如何能知道浏览者计算机使用的语言是繁体还是简体
2008-10-09 13:10:00
Python如何获取多线程返回结果
2024-01-01 23:34:28
制作设置404页面
2009-07-03 13:01:00
![](https://img.aspxhome.com/file/UploadPic/20097/3/200973131448261s.jpg)
Python操作json的方法实例分析
2022-10-13 10:39:09
![](https://img.aspxhome.com/file/2023/1/95721_0s.png)
python tkinter模块的简单使用
2021-11-20 16:52:33
![](https://img.aspxhome.com/file/2023/5/75325_0s.png)
SQL语句练习实例之一——找出最近的两次晋升日期与工资额
2011-10-24 20:16:42
python实现从字典中删除元素的方法
2023-11-10 17:26:33
慎用 script 节点的 src 属性来传递参数
2009-11-18 12:59:00
django如何自定义manage.py管理命令
2023-04-08 01:10:47
![](https://img.aspxhome.com/file/2023/4/63874_0s.png)
python学习数据结构实例代码
2023-09-20 22:56:32
Win10下安装并使用tensorflow-gpu1.8.0+python3.6全过程分析(显卡MX250+CUDA9.0+cudnn)
2021-06-29 20:05:21
![](https://img.aspxhome.com/file/2023/0/80620_0s.jpg)
Sublime Text4 配置 Python3 环境、代码提示、编译报错的解决方案
2021-09-24 12:00:03
![](https://img.aspxhome.com/file/2023/4/72074_0s.png)
python对RabbitMQ的简单入门使用教程
2021-01-13 17:53:44
![](https://img.aspxhome.com/file/2023/4/93734_0s.jpg)
使用Python脚本将绝对url替换为相对url的教程
2022-09-03 09:36:39
Python机器学习之决策树
2022-02-24 07:19:01
![](https://img.aspxhome.com/file/2023/6/79416_0s.png)
golang中使用匿名结构体的方法
2023-07-10 07:26:56
ASP状态封装类Cache、Cookie & Session
2008-05-11 19:33:00
python 查找字符串是否存在实例详解
2023-09-22 21:31:17