Skip to content

Developed with Python that compares two images with the same sizes and shows the differences visually by drawing rectangles. Useful for visual regression ui automation testings.

License

Notifications You must be signed in to change notification settings

BASILAHAMED/visual-comparison

Repository files navigation

logo-trans

About

Developed with Python utilizing the OpenCV library, this program compares two images of identical sizes, visually highlighting their differences by drawing red rectangles. Offering flexibility for various automation Quality Assurance (QA) tests, especially visual regression testing.

Key Features:

  • Utilizes standard Python language and specific modules for implementation.
  • Generates an output comprising copies of the 'actual' images, with discrepancies delineated by red rectangles.
  • This tool serves as a valuable asset for automated visual regression testing, facilitating precise visual comparisons to ensure the integrity and accuracy of image-based applications.

Usage

Installation

pip install visual-comparison

To compare two images through visual-comparison module

1. Sample Code to get Similarity Index:

Get Similarity Index

    # Using ImageComparisonUtil to get similarity index and compare output image
    # Load images to be compared
    expected_image = ImageComparisonUtil.read_image_from_resources("expected.png")
    actual_image = ImageComparisonUtil.read_image_from_resources("actual.png")
    
    # Where to save the result 
    result_destination = "result.png"
    
    # Compare the images and save it as result.png
    similarity_index = ImageComparisonUtil.compare_images(expected_image, actual_image, result_destination)
    print("Similarity Index:", similarity_index)

2. Sample Code to assert match/mismatch:

Assert Match/Mismatch

    # Using ImageComparisonUtil
    # Load images to be compared
    expected_image = ImageComparisonUtil.read_image_from_resources("expected.png")
    actual_image = ImageComparisonUtil.read_image_from_resources("actual.png")
    
    # Asserting both images
    match_result = ImageComparisonUtil.check_match(expected_image, actual_image)
    assert match_result

Demo

  1. Demo shows how basic image comparison works.

Expected Image

expected

Actual Image

actual

Result

result

  1. Demo shows how colour comparison works.

Expected Image

expected

Actual Image

actual

Result

result