如何在python-opencv图像处理项目中从给定数据集中查找文件/数据



我在图像处理项目中有一个图像数据集。我想输入图像并扫描数据集以识别给定的图像。我应该使用什么模块/库/方法(例如:ML)来识别我的python-opencv代码中的图像?

要找到完全相同的图像,您不需要任何类型的 ML。图像只是一个像素数组,因此您可以检查输入图像的数组是否等于数据集中图像的数组。

import glob
import cv2
import numpy as np
# Read in source image (the one you want to match to others in the dataset)
source = cv2.imread('test.jpg') 
# Make a list of all the images in the dataset (I assume they are images in a directory)
filelist = glob.glob(r'C:Users...Images*.JPG')
# Loop through the images, read them in and check if an image is equal to your source
for file in filelist:
    img = cv2.imread(file)
    if np.array_equal(source, img):
        print("%s is the same image as source" %(file))
        break

最新更新