Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackgroundSubtractorGSOC and LSBP does not respect a zero learning rate #3557

Open
4 tasks done
ArdooTala opened this issue Sep 5, 2023 · 1 comment
Open
4 tasks done

Comments

@ArdooTala
Copy link

System Information

OpenCV python version: 4.8.0.76 opencv-contrib-python
Operating System / Platform: Ubuntu 22.04
Python version: 3.10.12

Detailed description

The BackgroundSubtractorGSOC() does not stop updating the background model regardless of the zero learningRate factor when calling the BackgroundSubtractorGSOC.apply(<image>, None, learningRate=0).
It works fine when using the BackgroundSubtractorMOG and BackgroundSubtractorMGM, but BackgroundSubtractorGSOC and BackgroundSubtractorLSBP does not respect the learning rate. The background model keeps updating regardless of the learningRate value.

The same issue exists with BackgroundSubtractorKNN from the standard OpenCV.

Steps to reproduce

import cv2


# back_sub = cv2.createBackgroundSubtractorKNN()    # Has the same problem
# back_sub = cv2.bgsegm.createBackgroundSubtractorLSBP()    # Has the same problem
back_sub = cv2.bgsegm.createBackgroundSubtractorGSOC()

cap = cv2.VideoCapture(0)
if not cap.isOpened():
    raise (Exception("Could not open capture"))

learning_rate = 0.1
while True:
    ret, frame = cap.read()
    if not ret:
        break

    fg_mask = back_sub.apply(frame, None, learning_rate)
    print(learning_rate)

    cv2.imshow("frame", frame)
    cv2.imshow("foreground", fg_mask)
    cv2.imshow("background", back_sub.getBackgroundImage())

    k = cv2.waitKey(1)
    if k == ord("q"):
        break
    # Press "d" to switch learning_rate between 0.1 and 0.0
    elif k == ord("d"):
        if not learning_rate:
            learning_rate = 0.1
        else:
            learning_rate = 0.0

cap.release()
cv2.destroyAllWindows()

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@Tarunnagpal7
Copy link

I can handle this where is the file of code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants