Remove background of the image using opencv Python

后端 未结 3 1584
无人及你
无人及你 2020-12-13 07:09

I have two images, one with only background and the other with background + detectable object (in my case its a car). Below are the images

I am trying to re

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 07:41

    The problem is that you're subtracting arrays of unsigned 8 bit integers. This operation can overflow.

    To demonstrate

    >>> import numpy as np
    >>> a = np.array([[10,10]],dtype=np.uint8)
    >>> b = np.array([[11,11]],dtype=np.uint8)
    >>> a - b
    array([[255, 255]], dtype=uint8)
    

    Since you're using OpenCV, the simplest way to achieve your goal is to use cv2.absdiff().

    >>> cv2.absdiff(a,b)
    array([[1, 1]], dtype=uint8)
    

提交回复
热议问题