完美解决AttributeError: module ‘cv2.cv2‘ has no attribute ‘bgsegm

测试

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()

报错:

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

解决方法:

安装命令选择pip install opencv-contrib-python,而不是pip install opencv-python

你可能感兴趣的:(opencv,opencv)