小编use*_*323的帖子

找不到OpenCV2 Python createBackgroundSubtractor模块

我试图在Python中使用cv2.createBackgroundSubtractorMOG2()方法.我在我的Mac和我的Raspberry Pi上都试过了,并且在运行以下代码行时遇到同样的错误:

fgbg = cv2.createBackgroundSubtractorMOG2()
Run Code Online (Sandbox Code Playgroud)

我使用的代码来自https://github.com/abidrahmank/OpenCV2-Python-Tutorials/blob/master/source/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst

运行此代码时出现以下错误:

fgbg = cv2.createBackgroundSubtractorMOG2()AttributeError:'module'对象没有属性'createBackgroundSubtractorMOG2'

我似乎无法使用任何createBackgroundSubtractor方法.

我一直试图在过去的一天解决这个问题,但我没有在线搜索,因为在Python上对cv2的支持有限.

提前致谢

python opencv background-subtraction

17
推荐指数
4
解决办法
3万
查看次数

比较两个OpenCV图像/ 2D Numpy阵列

我是使用OpenCV,Python和Numpy的新手,但现在已经是Java,C++,C程序员了.

我正在实现一个sigma-delta背景检测器,它执行以下操作:

让i1成为第一张图片,让i2成为第二张图片

    for each pixel:
    if i1(x,y) > i2(x,y), then i2(x,y) = i2(x,y) + 1
    if i1(x,y) < i2(x,y), then i2(x,y) = i2(x,y) - 1
Run Code Online (Sandbox Code Playgroud)

我基本上试图遍历2D图像阵列并将像素值与其他图像进行比较,但我很难使用for循环来处理numpy数组.我尝试过使用嵌套for循环,但是我得到一个错误,说我无法访问该数组的元素.

编辑:

for x in range (width):
    for y in range (height):
        if Mt [x,y] > It[x,y]:
            Mt [x,y] = Mt[x,y]+1
        elif Mt [x,y] < It[x,y]:
            Mt [x,y] = Mt[x,y]-1
Run Code Online (Sandbox Code Playgroud)

这是有效的,但似乎并不优雅或高效.我希望有更快的解决方案......

任何建议都是最受欢迎的

python arrays opencv numpy

4
推荐指数
1
解决办法
1100
查看次数

标签 统计

opencv ×2

python ×2

arrays ×1

background-subtraction ×1

numpy ×1