python- opencv 图像处理项目中如何从给定的数据集中查找文件/数据?
How to find a file/ data from a given data set in python- opencv image processing project?
我在图像处理项目中有一组图像。我想输入一个图像并扫描数据集以识别给定的图像。我应该使用什么模块/库/方法(例如: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
我在图像处理项目中有一组图像。我想输入一个图像并扫描数据集以识别给定的图像。我应该使用什么模块/库/方法(例如: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