documents

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

imagecompare.py (786B)


      1 import cv2
      2 from skimage.metrics import structural_similarity as ssim
      3 
      4 def judge_image_difference(image_path_a, image_path_b):
      5     img_a = cv2.imread(image_path_a)
      6     img_b = cv2.imread(image_path_b)
      7 
      8     if img_a.shape != img_b.shape:
      9         return False, 0.0
     10 
     11     gray_a = cv2.cvtColor(img_a, cv2.COLOR_BGR2GRAY)
     12     gray_b = cv2.cvtColor(img_b, cv2.COLOR_BGR2GRAY)
     13 
     14     score, _ = ssim(gray_a, gray_b, full=True)
     15     
     16     is_identical = score == 1.0
     17     return is_identical, score
     18 
     19 if __name__ == "__main__":
     20     identical, similarity_score = judge_image_difference(r"C:\Users\ryout\Downloads\2026_01_20_21_14_33.png", r"C:\Users\ryout\Downloads\2026_01_20_21_15_05.png")
     21     print(f"Identical: {identical}")
     22     print(f"Similarity Score: {similarity_score}")