1

Short question about the cv2.createBackgroundSubtragtorMOG2().

I have two video files, one contains the background without moving objects. The second one is with moving objects.

Question here is if there is a possibility to set the background frame in the function of opencv or if it needs to get own coding via converting the first image to grayscale and then take the absdiff from every frame where the moving objects are?

import cv2

cap = cv2.VideoCapture("PATH")

fgbg = cv2.createBackgroundSubtractorMOG2()  

while True:

    ret, frame = cap.read()  

    if ret:
        gray = cv2.cvtColor(frame, cv2.COLOR_RGB2YCrCb)
        fgmask = fgbg.apply(gray, learningRate = 0.05)  
    else: 
        break
cap.release()
cv2.destroyAllWindows()

I know that the learning rate in the .apply() function is the parameter for the learning of the background, but I would like to set it to 0 and have my own background. The idea would be to analyze more videos with the same background frame from the included background subtractor of opencv if possible.

Limbomike
  • 11
  • 2

0 Answers0