Sep-03-2022, 03:37 PM
(This post was last modified: Sep-03-2022, 03:43 PM by Yoriz.
Edit Reason: Added code tags
)
I am comparing images from a master image to a 100s of others. If its not a match what is best practice to then search the next image. All images are .png.
Manually changing the file name gives me the intended result but I need to check, if match then do something if not match try next image until match found. Things are a little all over while I attempt to do this.
Bare in mind I am no programmer and normally get things working by excessive googling but this one has stumped me.
Below is a better example
Manually changing the file name gives me the intended result but I need to check, if match then do something if not match try next image until match found. Things are a little all over while I attempt to do this.
Bare in mind I am no programmer and normally get things working by excessive googling but this one has stumped me.
from skimage.metrics import structural_similarity import cv2 import numpy filenames = 'images/a.png' img00 = cv2.imread('Output.png', 0) img01 = cv2.imread(filenames, 0) def orb_sim(img1, img2): orb = cv2.ORB_create() kp_a, desc_a = orb.detectAndCompute(img1, None) kp_b, desc_b = orb.detectAndCompute(img2, None) bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) matches = bf.match(desc_a, desc_b) similar_regions = [i for i in matches if i.distance < 80] if len(matches) == 0: return 0 return len(similar_regions) / len(matches) def structural_sim(img1, img2): sim, diff = structural_similarity(img1, img2, full=True) return sim def run(): ssim = structural_sim(img01, img00) print("{0:.2f}".format(ssim)) if ssim >= 0.50: print("Match") else: print("Fail") run()
Below is a better example
from skimage.metrics import structural_similarity import cv2 ToCompare = cv2.imread('a.png', 0) MasterImage = cv2.imread('Output.png', 0) def structural_sim(imageonem, imagetwoc): sim, diff = structural_similarity(imageonem, imagetwoc, full=True) return sim def run(): ssim = structural_sim(MasterImage, ToCompare) print("{0:.2f}".format(ssim)) if ssim >= 0.50: print("Match") #do something else else: print("Fail") #if no match the try b.png from images folder run()