使用opencv_python进行视频分析遇到的bgsegm问题

来源:互联网 发布:红米2移动版网络解锁 编辑:程序博客网 时间:2024/05/22 03:32

近期在使用opencv_python分析视频过程中总是遇到各种问题,如cv2.cv2的问题、还有使用opencv_python操作视频处理类的需求时总是遇到has no attribute 'bgsegm'等问题。从网上找了但缺少完整的说明,故特地说明下。


遇到has no attribute 'bgsegm'等问题,说明安装的opencv_python版本需要更新了,或者没有安装contrib


详细如下:

        opencv3.0以后的版本中,只有createBackgroundSubtractorKNNcreateBackgroundSubtractorMOG2函数,而createBackgroundSubtractorGMGcreateBackgroundSubtractorMOG被移动到opencv_contrib包中了。

        故使用上要如下方式:

        cv2.createBackgroundSubtractorKNN([,history[, dist2Threshold[, detectShadows]]])

cv2.createBackgroundSubtractorMOG2([,history[, varThreshold[, detectShadows]]])

        

        要调用createBackgroundSubtractorGMGcreateBackgroundSubtractorMOG则采用如下:

        cv2.bgsegm.createBackgroundSubtractorGMG([,initializationFrames[, decisionThreshold]])

       cv2.bgsegm.createBackgroundSubtractorMOG([,history[, nmixtures[, backgroundRatio[,noiseSigma]]]])

        当出现上述问题时,则说明你的python中没有安装contrib包。

        

 安装contrib包时有如下3种方式:

    1、可从https://pypi.python.org/pypi/opencv-contrib-python去下载并安装。

         2、到https://www.lfd.uci.edu/~gohlke/pythonlibs/去下载opencv_python‑3.3.1+contrib‑cp36‑cp36m‑win_amd64.whl

         3、contrib包的源代码地址:https://github.com/opencv/opencv_contrib也可自行编译。


阅读全文
0 0