You better DON'T use loops, if you don't want to handle exact weights. With each iteration you'd give the newly overlayed image proportionately too much weight w.r.t. to the already merged image.
Let's see these four images:
I prepared some code to visualize:
import cv2
import numpy as np
images = ['1.png', '2.png', '3.jpg', '4.jpg']
images = [cv2.resize(cv2.imread(i), (400, 400)) for i in images]
# Don't do loops, m'kay?
output = images[0]
for i, image in enumerate(images[1:]):
output = cv2.addWeighted(output, 0.5, image, 0.5, 0)
cv2.imwrite(str(i) + '.png', output)
# Do linear blending using all images at once.
output = (np.array(images) / len(images)).sum(axis=0).astype(np.uint8)
cv2.imwrite('output.png', output)
The (intermediate) output(s) of the loop look like that:
The night image is most prominent, whereas Paddington can be hardly seen.
It'd be better to divide all images by the number of images you want to overlay, and then sum them. Using NumPy, that's the given one-liner, and that'd be the output:
----------------------------------------
System information
----------------------------------------
Platform: Windows-10-10.0.16299-SP0
Python: 3.8.5
NumPy: 1.19.5
OpenCV: 4.5.1
----------------------------------------
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…