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

前端 未结 5 1004
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-19 20:54
import numpy as np
import cv2
cap = cv2.VideoCapture(\'vtest.avi\')
fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()
while(1):
    ret, frame = cap.read()
    fgmask =          


        
5条回答
  •  半阙折子戏
    2021-02-19 21:01

    Most probably this issue arises when someone tries to install multiple packages of OpenCV or even tries to install multiple packages of OpenCV in a different order.

    If you read the official opencv-contrib-python installation docs there is written that you only need to install one package of OpenCV.

    For example, if you need a base OpenCV module with extra contrib modules, you just need to install opencv-contrib-python with the appropriate version you want:

    $ pip install opencv-contrib-python
    

    And this will install both OpenCV and OpenCV contrib modules.

    The reason for that is all the OpenCV modules use the same namespace which is cv2 and do not use the plugin architecture. So, when you install the other module, it will rewrite the existing namespace with a new module library that is being installed.

提交回复
热议问题