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)
cv2.imwrite("dst.jpg",dst)
```

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)
cv2.imwrite("dst.jpg",dst)
```

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

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.