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?
Asked
Active
Viewed 863 times
0
-
What do you mean with “recognize the given image”? Exactly the same image, or the same kind of category/object/etc? (e.g. “cats”). – Niels Henkens Dec 31 '18 at 19:00
-
Exactly the same image. – Aakash Meshram Jan 01 '19 at 07:43
-
To find the exact same image, see my answer below. – Niels Henkens Jan 01 '19 at 13:52
1 Answers
0
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

Niels Henkens
- 2,553
- 1
- 12
- 27