Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

compute difference between two images python opencv

import cv2

# load images
image1 = cv2.imread("leftImage.jpg")
image2 = cv2.imread("rightImage.jpg")

# compute difference
difference = cv2.subtract(image1, image2)

# color the mask red
Conv_hsv_Gray = cv2.cvtColor(difference, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(Conv_hsv_Gray, 0, 255,cv2.THRESH_BINARY_INV |cv2.THRESH_OTSU)
difference[mask != 255] = [0, 0, 255]

# add the red mask to the images to make the differences obvious
image1[mask != 255] = [0, 0, 255]
image2[mask != 255] = [0, 0, 255]

# store images
cv2.imwrite('diffOverImage1.png', image1)
cv2.imwrite('diffOverImage2.png', image1)
cv2.imwrite('diff.png', difference)
Comment

PREVIOUS NEXT
Code Example
Python :: name unnamed column pandas 
Python :: list to csv pandas 
Python :: add all string elements in list python 
Python :: Could not build wheels for opencv-python which use PEP 517 and cannot be installed directly 
Python :: using bs4 to obtain html element by id 
Python :: pandas dataframe convert nan to string 
Python :: df dropna ensure that one column is not nan 
Python :: disable devtools listening on ws://127.0.0.1 python 
Python ::  
Python :: column standardization pandas 
Python :: pip install chatterbot 
Python :: openpyxl font 
Python :: tkinter navigate pages 
:: runserver manage.py 
Python :: ddos in python 
Python :: how to save a model fast ai 
Python :: display full dataframe pandas 
Python :: pandas groupby as new column 
Python :: name exit not defined python 
Python :: brownie normalize to wei 
Python :: pandas to_csv append 
Python :: pandas remove index column when saving to csv 
Python :: python convert latitude longitude to x y 
Python :: load from np file py 
Python :: mean deviation python 
Python :: Add help text in Django model forms 
Python :: LookupError: unknown encoding: idna python 
Python :: change the default python version mac 
::  
Python :: check if any values overlap in numpy array 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =