From 1cf96336d9592d7e1a44119b1a9f27175208152b Mon Sep 17 00:00:00 2001 From: Dou Du Date: Tue, 17 Dec 2024 16:34:36 +0200 Subject: [PATCH] change back image test --- .github/workflows/screenshot-comparison.yml | 2 -- test/test_figures.py | 31 ++++++--------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/.github/workflows/screenshot-comparison.yml b/.github/workflows/screenshot-comparison.yml index 1ecd9db..0eb079b 100644 --- a/.github/workflows/screenshot-comparison.yml +++ b/.github/workflows/screenshot-comparison.yml @@ -40,8 +40,6 @@ jobs: pip install --upgrade pytest pip install --upgrade selenium pip install --upgrade Pillow - pip install --upgrade imagededup - - uses: nanasess/setup-chromedriver@master - run: | export DISPLAY=:99 diff --git a/test/test_figures.py b/test/test_figures.py index c2d35c5..b1e208d 100644 --- a/test/test_figures.py +++ b/test/test_figures.py @@ -1,27 +1,12 @@ -from imagededup.methods import PHash +from PIL import Image, ImageChops, ImageStat -# Initialize the hashing method -phasher = PHash() +image1 = Image.open('widget-01.png') +image2 = Image.open('test/widget-sample.png') -# Provide the paths to your images -image1_path = 'widget-01.png' -image2_path = 'test/widget-sample.png' +diff = ImageChops.difference(image1, image2) +stat = ImageStat.Stat(diff) -# Generate hashes for both images -hash1 = phasher.encode_image(image_file=image1_path) -hash2 = phasher.encode_image(image_file=image2_path) - -# Calculate the Hamming distance between the two hashes -distance = phasher.hamming_distance(hash1, hash2) - -# Print similarity score -print(f"Hamming distance between the two images: {distance}") - -# Interpret the similarity -if distance == 0: - print("The images are identical!") -elif distance < 10: # Adjust threshold as needed - print("The images are very similar.") +if sum(stat.mean) == 0: + print('images are the same') else: - raise Exception("The result is NOT the same as expected. Please check matplotlib version.") - + raise Exception("The result is NOT the same as expected. Please check matplotlib version.")