Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

opencv

Is there any way to subtract two images in python opencv2 ?

  • Image 1 : Any image (eg. a house Image) (static image)
  • Image 2 : The same Image with an Object (In house, a person is standing...) (static image + dynamic objects)
  • Image 3 = Image 2 - Image 1

If we subtract Image2 from Image1 means Image3 should give Object(person) only.

like image 523
Thamizh Avatar asked Jan 29 '14 08:01

Thamizh


People also ask

How do you subtract an image in Python?

You can subtract two images by OpenCV function, cv. subtract(). res = img1 - img2.


1 Answers

Try background subtraction.

Use cv2.subtract(img1,img2) instead of arithmetic operation, as cv2 will take care of negative values.

like image 183
dvigneshwer Avatar answered Sep 21 '22 12:09

dvigneshwer