All problems
Running-Average Background
Problem
Update a running-average background model with a new frame.
new_background = alpha * background + (1 - alpha) * frame per pixel, rounded to 4 decimal places. alpha is in [0, 1].
Hint
alpha weights the old background; 1 - alpha weights the new frame.
Test cases
case 1
in: [[[0,10]],[[10,0]],0.9]
expected: [[1,9]]
case 2
in: [[[0,10]],[[10,0]],1]
expected: [[0,10]]
case 3
in: [[[0,10]],[[10,0]],0]
expected: [[10,0]]
case 4
in: [[[100,100],[100,100]],[[0,0],[200,0]],0.5]
expected: [[50,50],[150,50]]
Starter codePython
def update_background(background, frame, alpha):
# Your code here
pass4 test cases · run your code against them in the editor