How to subtract two images using python opencv2 to get foreground object

Is there a way to subtract two images in python opencv2?
 1) Image 1: any image (for example: the image of the house) (static image)
 2) Image 2: the same image with the object (there is a person in the house ...) (static image + dynamic objects)
 3) Image 3 = Image 2 - Image 1
If we subtract Image2 from Image1, then Image3 should give Object (person).
Please give any example.
Thanks.

+6
source share
3 answers

, , .

image1 = imread("/path/to/image1")
image2 = imread("/path/to/image2")
image3 = image1 - image2
+15

cv2.subtract , 0-255, , , unit8 int32 int64. unint8 0-255,

image1= np.int32(image1)

image2= np.int32(image2)

image3 = image1 - image2
0

Source: https://habr.com/ru/post/1524239/


All Articles