Skip to main content

Get the difference between 2 images

Tested against Windows 10 / Python 3.11 / Anaconda

pip install whacamolefinder

The WhacAMoleFinder class is designed for continuously comparing pairs of images and finding differences between them. It is used in scenarios where you want to monitor a changing image, such as a game or application interface, and detect any alterations or visual changes.

The advantages:

Continuous Image Comparison:

The class allows you to continuously compare two consecutive screenshots or images, enabling real-time monitoring for changes.

Difference Detection:

It detects differences between the images using image processing techniques, highlighting regions where changes occur.

Customizable Parameters:

You can customize various parameters, such as the percentage of resizing, the color used for highlighting differences, the thickness of highlighting lines, and the threshold for difference detection. This flexibility allows you to adapt the class to different use cases and scenarios.

Visualization:

It provides an option to display the images with differences highlighted, making it easy to visualize what has changed.

Interactive Control:

The class includes a control mechanism to stop the comparison process, which is useful when you want to pause or terminate the monitoring.

Yielding Results:

It yields the results of the comparison as a list of Token namedtuples, providing information about the differences found in consecutive images.

Args:
	screenshotiter: A generator or iterator that provides screenshots for comparison.

Attributes:
	screenshotiter (generator): The iterator supplying screenshots.
	stop (bool): A flag to control the comparison process. Set to True to stop comparing.
	last_screenshot
	before_last_screenshot

Methods:
	start_comparing: Begin the image comparison process and yield results.

Example:
	from whacamolefinder import WhacAMoleFinder
	from fast_ctypes_screenshots import (
		ScreenshotOfOneMonitor,
	)

	# create your own screenshot function, you can use whatever you want (fast_ctypes_screenshots/adb/mss/pyautogui/...),
	# but it is important to use a loop and yield!
	def screenshot_iter_function():
		while True:
			with ScreenshotOfOneMonitor(
				monitor=0, ascontiguousarray=False
			) as screenshots_monitor:
				yield screenshots_monitor.screenshot_one_monitor()



	# Create an instance of WhacAMoleFinder

	piit = WhacAMoleFinder(screenshot_iter_function) # pass the function without calling it!
	for ini, di in enumerate(
		piit.start_comparing(
			percent_resize=10,
			draw_output=True,
			draw_color=(255, 0, 255),
			thickness=20,
			thresh=3,
			maxval=255,
			draw_on_1_or_2=2,
			break_key="q",
		)
	):
		print(di)
		if ini > 100:
		piit.stop = True
		print(piitlast_screenshot)
		print(piitbefore_last_screenshot)

#You can compare 2 images without using the class:
# Call the get_difference_of_2_pics function to compare the two images
allresults, out = get_difference_of_2_pics(
	pic1='c:/pic1.jpg',
	pic2='c:/pic2.jpg',
	percent_resize=10,
	draw_output=True,  # Set to True to visualize the differences
	draw_color=(255, 0, 255),  # Custom color for highlighting differences
	thickness=2,  # Line thickness for highlighting
	thresh=3,  # Threshold for difference detection
	maxval=255,  # Maximum value for thresholding
	draw_on_1_or_2=1,  # Draw differences on the first image
)

Metadata

Release files for whacamolefinder 0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whacamolefinder 0.11
File Size Uploaded Provenance Actions
whacamolefinder-0.11.tar.gz 59.3 kB Without provenance Details for whacamolefinder-0.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for whacamolefinder 0.11
File Interpreter ABI Platform Actions
whacamolefinder-0.11-py3-none-any.whl Python 3 none any Details for whacamolefinder-0.11-py3-none-any.whl

Total release size: 119.5 kB

Release files / whacamolefinder-0.11.tar.gz

Download URL whacamolefinder-0.11.tar.gz
Size 59.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d55563e4c451e30c4243637903c812210aadcf5d3102681c358622b7e9118f7f
BLAKE2b-256 checksum
How to use checksums
97d97b351d9e9393c3f829450012592c03c0c81e7612cf4736d791f0139346ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / whacamolefinder-0.11-py3-none-any.whl

Download URL whacamolefinder-0.11-py3-none-any.whl
Size 60.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02ab50365ed2b026a2b1bcfdc7d64c8145ff6dafd0db495555c3aadfc928df5b
BLAKE2b-256 checksum
How to use checksums
90bf0a674d89011ba7e47b75c4c27285e05fb81b6a50dafd8fa0c402f19c1e2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for whacamolefinder 0.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.11 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page