OpenCV BackgroundSubtractor 认为繁忙的前景是背景

OpenCV BackgroundSubtractor Thinks A Busy Foreground Is The Background

我正在使用背景减法来识别和控制传送带上的物品。 这项工作与高速公路示例中的典型跟踪汽车非常相似。 我从一个空的传送带开始,这样计算机一开始就知道背景。 但是在传送带上装满包裹一段时间后,计算机开始认为这些包裹是背景。这需要我不时地重新启动程序。 有人对此有解决方法吗? 由于传送带是黑色的,我想知道时不时地扔进几个空白帧是否有意义,或者是否有其他解决方案。 非常感谢


# After experimentation, these values seem to work best.
backSub = cv2.createBackgroundSubtractorMOG2(history = 5000, varThreshold = 1000, detectShadows = False)    

while True:
    return_value, frame = vid.read()
    
    if frame is None:
        print('Video has ended or failed, try a different video format!')
        break        
    
        
    ## [gaussian blur helps to remove noise These settings seem to remove reflections from rollers.] 
    blur = cv2.GaussianBlur(frame, (0,0), 5, 0, 0)
    ## [End of: gaussian blur helps to remove noise These settings seem to remove reflections from rollers.]
    

    ## [Remove the background and produce a grays scale image]
    fgMask = backSub.apply(blur)       
    ## [End of: Remove the background and produce a grey scale image]

你说你最初给背景减法器一些纯背景。

完成后,在“运行”阶段,使用 learningRate = 0 调用 apply()。这样可以确保模型不会更新。