# -*- coding: UTF-8 -*- import argparse import cv2 import os # 使用方法:命令行cd到脚本所在文件夹,python picture.py -i "图片路径" #便历图片,合格则保存,不合格则删除 def variance_of_laplacian(image): # 使用拉普拉斯算子提取图像边缘信息,计算边缘的平均方差 return cv2.Laplacian(image, cv2.CV_64F).var() def read_path(file_pathname): #遍历该目录下的所有图片文件 for filename in os.listdir(file_pathname): print(filename) image = cv2.imread(file_pathname+'/'+filename) # 取图片的灰度通道 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) fm = variance_of_laplacian(gray) # 如果得分比阈值低,认为是模糊 if fm < 100.0: os.remove(file_pathname+'/'+filename) #read_path(r"C:\Users\xinluo\PycharmProjects\pythonProject\Saved Pictures") #print(os.getcwd())