项目开源地址
pip install imagededupgit clone https://github.com/idealo/imagededup.git
cd imagededup
pip install "cython>=0.29"
python setup.py install
Quick Start
from imagededup.methods import PHash
phasher = PHash()# Generate encodings for all images in an image directory
encodings = phasher.encode_images(image_dir='path/to/image/directory')# Find duplicates using the generated encodings
duplicates = phasher.find_duplicates(encoding_map=encodings)# plot duplicates obtained for a given file using the duplicates dictionary
from imagededup.utils import plot_duplicates
plot_duplicates(image_dir='path/to/image/directory',duplicate_map=duplicates,filename='ukbench00120.jpg')
删除图片
from imagededup.methods import PHash
phasher = PHash()
import os
# Generate encodings for all images in an image directory
encodings = phasher.encode_images(image_dir='/home/shunyun/lizheng/imagededup/data/work/AI/zl_all/new/images/train')have_removed = []
# Find duplicates using the generated encodings
duplicates = phasher.find_duplicates(encoding_map=encodings)
print(duplicates)
for i in duplicates:if i in have_removed:continueif len(duplicates[i]) > 0:for j in duplicates[i]:if i in have_removed:continuehave_removed.append(j)print(j)os.remove(f't/{j}')# print(i,duplicates[i])# plot duplicates obtained for a given file using the duplicates dictionary
# from imagededup.utils import plot_duplicates
# plot_duplicates(image_dir='data/base_images',
# duplicate_map=duplicates,
# filename='ukbench00120.jpg')