Overlaying multiple frame

I have been trying to overlay multiple frame together from an array of image, but it only generate first frame (img[0]) as output.

for i in range(0,len(img),1):
    dst = cv2.addWeighted(first_frame,0.5,img[i],1,0)

assignment: try to find the weighted (average) sum of [1,2,3,4,5]
once you got that right, you’ll see, what is wrong with your current attempt

I added the weighted average as

        alpha = 1.0/(i+1)
        beta = 1.0-alpha
        dst = cv2.addWeighted(list_,alpha,dst,beta,0.0)

But It gave an error of

Overload resolution failed:

  • src1 is not a numpy array, neither a scalar
  • Expected Ptrcv::UMat for argument ‘src1’

that’s as bad as your last attempt.
how do you even expect that to work ?

do you want to weight the images equally ?

addWeighted might be the entirely wrong function for this (and N>2 images).

just sum them, divide afterwards.

there are ways to successively calculate the mean, by adding successively smaller contributions, when you need a running mean. 1/(i+1) probably goes in that direction. however, you’ve got a finite number of images. just add, then divide.

and watch what you’re adding, and what you’re adding it to. review the docs for addWeighted

no. first divide, then add (overflow)

1 Like

add to a larger data type. dividing first, assuming this is integers, will cause noticeable rounding errors

there is accumulate() function ( i have never tried it) may be related to your problem

1 Like

that appears to require dst to be a single/double float, not integer. still, very useful.

besides that, numpy is perfectly happy to add an uint8 array to an array of uint16 or any other type. OpenCV’s C++ Mat class, or its “matrix expressions” (cv::MatOp::add), also support adding to arbitrarily-typed Mats.