‘’’
遍历整个文件夹,查看所有图片,使用 matchTemplate()方法判断两个图片相似度
95%以上的,将相似图片删除
‘’’
import os
import cv2
import sys
#遍历目标路径下文件,将jpeg文件插入列表内
def file_list(catalogue):
photos = []
photos_route = []
# 遍历上层目录
for root, dirs, files in os.walk(catalogue):
# 查看存在多少个子目录
if files == []:
#print(‘root’, root, ‘dirs’, dirs, ‘files’, files)
for dir in dirs:
for root_son, dirs_son, files_son in os.walk(catalogue + “/%s” % dir):
#print(‘dir’, dir, ‘files’, files_son)
for file_son in files_son:
file_text = os.path.splitext(file_son)
#print(‘file_text’,file_text)
if file_text[1].upper() == ‘.JPEG’:
#print(‘file’, catalogue + “/%s/%s” % (dir, file_son))
img = cv2.imread(catalogue + “/%s/%s” % (dir, file_son), 0)
imga = cv2.resize(img, (400, 400))
photos.append(imga)
photos_route.a