简体   繁体   中英

How to find a file/ data from a given data set in python- opencv image processing project?

I have a data set of images in an image processing project. I want to input an image and scan through the data set to recognize the given image. What module/ library/ approach( eg: ML) should I use to identify my image in my python- opencv code?

To find exactly the same image , you don't need any kind of ML. The image is just an array of pixels, so you can check if the array of the input image equals that of an image in your dataset.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM