简体   繁体   English

如何从图像中减去背景 - python,opencv

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

How to subtract the background in a still image?如何减去静止图像中的背景? IF the issue is with videos then we can use cv2.createBackgroundSubtractorMOG() .如果问题出在视频上,那么我们可以使用cv2.createBackgroundSubtractorMOG() I tried to manipulate the function, but I got AttributeError我试图操纵这个函数,但我得到了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!欢迎任何建议!

fgbg = cv2.createBackgroundSubtractorMOG2()

在 opencv3 教程中不可用 - 您可以使用:

fgbg = cv2.BackgroundSubtractorMOG2()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM