Last active
September 15, 2021 20:14
-
-
Save mrioqueiroz/7153fc47f672e98964490a180df08d5c to your computer and use it in GitHub Desktop.
Script para identificar diferenças entre imagens ou buscar imagens iguais em uma árvore de diretórios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import cv2 | |
def check_differences(): | |
im1 = cv2.imread(sys.argv[1]) | |
im2 = cv2.imread(sys.argv[2]) | |
diff = cv2.subtract(im1, im2) | |
print(f"As imagens {sys.argv[1]} e {sys.argv[2]} são ", end="") | |
if diff.any(): | |
print("diferentes.") | |
cv2.imshow("Diferencas encontradas", diff) | |
cv2.waitKey(5000) | |
else: | |
print("iguais.") | |
def are_equal(): | |
print(cv2.subtract(cv2.imread(sys.argv[1]), cv2.imread(sys.argv[2])).any()) | |
def find_equal(): | |
im1 = cv2.imread(sys.argv[1]) | |
for dirpath, _, filenames in os.walk(sys.argv[2]): | |
for filename in filenames: | |
path = os.path.join(dirpath, filename) | |
if filename.endswith(".png"): | |
try: | |
im2 = cv2.imread(path) | |
diff1 = cv2.subtract(im1, im2) | |
diff2 = cv2.subtract(im2, im1) | |
if not diff1.any() and not diff2.any(): | |
print(path) | |
except cv2.error: | |
pass | |
if __name__ == '__main__': | |
find_equal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment