我试着把一张图片和一个满是图片的文件夹进行比较,并试图找到一张相等的图片,但我不知道如何把一张图片和一个满是图片的文件夹进行比较
我试着用fnmatch和os制作一个listOfFiles,但它只需要少数几个图像中的一个
#import
import cv2
import numpy as np
import os, fnmatch
#Collects all images
listOfFiles = os.listdir('./images')
pattern = "*.jpg"
for entry in listOfFiles:
if fnmatch.fnmatch(entry, pattern):
Allimages = ("images/" + entry)
#Define variables
upload = cv2.imread("images/img1.jpg")
duplicate = cv2.imread(Allimages)
#Checks if duplicate is duplicate
if upload.shape == duplicate.shape:
print("The images have same size and channels")
difference = cv2.subtract(upload, duplicate)
b, g, r = cv2.split(difference)
if cv2.countNonZero(b) == 0 and cv2.countNonZero (g) == 0 and cv2.countNonZero(r) == 0:
print("images are the same")
else:
print("images are different")
必须在
for
循环内完成所有操作也许你只能用
代码:
相关问题 更多 >
编程相关推荐