You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# -*- 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())