opencv: Python samples not correct

Some of my students noticed that the python tutorials are incorrect and no longer working. For example the backgroundsubtraction sample here has an error in line

fgbg = cv2.createBackgroundSubtractorMOG()

which should actually be

fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()

I am wondering if this is the case for all functionality and thus, all samples need to be adapted? If so I am able to provide fixes, but I would rather love to have a more experienced python user to confirm this problem.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (7 by maintainers)

Most upvoted comments

That should work: pip install opencv-contrib-python

There is a risk with this! If your opencv-python and opencv-contrib-python are out of sync (different versions) than there is about 95% chance it will blow up in your face and your software won’t work. In that case I think it is always better to ensure you built the correct version combination yourself.

@swarnak25 , this is not a bug, your cv2 probably does not contain this module

you have to build your cv2 from src with opencv_contrib