find difference between two images with python

https://github.com/nimadorostkar/images-difference

fuul code:

from skimage.measure import compare_ssim
import argparse
import imutils
import cv2


# load the two input images
imageA = cv2.imread('0.jpg')
imageB = cv2.imread('1.jpg')

# convert the images to grayscale
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)
# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))
# threshold the difference image, followed by finding contours to
# obtain the regions of the two input images that differ
thresh = cv2.threshold(diff, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# loop over the contours
for c in cnts:
# compute the bounding box of the contour and then draw the
# bounding box on both input images to represent where the two
# images differ
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 2)
# show the output images
cv2.imshow("Original", imageA)
cv2.imshow("Modified", imageB)
cv2.imshow("Diff", diff)
cv2.imshow("Thresh", thresh)
cv2.waitKey(0)

پیدا کردن تفاوت های موجود بین دو عکس

Getting started

Pip packages

pip install scikit-imagepip install imutilspip install argparsepip install opencv-python

Run App

python prj.py

https://github.com/nimadorostkar/images-difference

--

--

--

BackEnd Dev, Django

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Pfizer’s landmark COVID vaccine results mean for the pandemic

Y we chose Kotlin

How to Print Alphabet J in Python?

Setting up an Optimal Developer Environment on Windows 10

How to Print Alphabet N in Python?

Immutability in Golang;

Scala Programming: An Introduction

Dockerizing Spring Boot Application

Spring Boot+Docker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nima dorostkar

Nima dorostkar

BackEnd Dev, Django

More from Medium

Make Rock Paper Scissors Game Using Python

Inheritance in Python — Extending Classes

Operators in Python

Lambda Function in Python