[Python] How to subtract the background from an image - python , opencv

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    How to subtract the background in a still image? IF the issue is with videos then we can use cv2.createBackgroundSubtractorMOG(). I tried to manipulate the function, but I got AttributeError

    This is what i have tried:

    img = cv2.imread('lena.png')
    fgbg = cv2.createBackgroundSubtractorMOG2()
    fgmask = fgbg.apply(img)
    cv2.imwrite('{0:d}.jpg'.format(i),fgmask)


    But I got this error:

    AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2'


    Any suggestion are welcome!

    Continue reading...

Compartilhe esta Página