Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'cv2.cv2' has no attribute 'bgsegm

Tags:

python

opencv

import numpy as np
import cv2
cap = cv2.VideoCapture('vtest.avi')
fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()
while(1):
    ret, frame = cap.read()
    fgmask = fgbg.apply(frame)
    cv2.imshow('frame',fgmask)
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break
cap.release()
cv2.destroyAllWindows()

I am getting the following error: AttributeError: module 'cv2.cv2' has no attribute 'bgsegm'.

I am using Python 3.6 with OpenCV 3.6 on windows machine. I tried using the pip install opencv-contrib-python command but still the problem remains same on my windows machine. This command helped be on Ubuntu system, but not on windows. I searched similar problems on stack but couldn't solve this issue. Can someone help me out on this? Thanks!

like image 407
Subham Kumar Avatar asked Jun 04 '18 05:06

Subham Kumar


People also ask

Does cv2 have face attribute?

cv2 has no attribute face' in Python - Quora.

What is Opencv headless?

No warning as the package also naturally provides cv2 module. opencv-python-headless is unofficial built of opencv-python minus GUI modules that are not required in many cases. Same is expected to be needed for opencv-python-contrib and opencv-python-contrib-headless packages.


1 Answers

You need to install the contrib dependencies to get this working as it isn't part of the standard build.

pip install opencv-contrib-python
like image 75
user1767754 Avatar answered Sep 18 '22 11:09

user1767754