效果
![图](https://i-blog.csdnimg.cn/blog_migrate/9ec6740a4f36292bfabd9db686326843.gif#pic_center)
代码
import cv2
import numpy as np
def smear(lengh):
imgs = []
img = yield
simg = np.zeros_like(img, dtype=np.uint)
while img is not None:
if len(imgs) < lengh:
imgs.append(img)
simg += img
else:
fimg = imgs.pop(0)
imgs.append(img)
simg -= fimg
simg += img
img = yield (simg / len(imgs)).astype(np.uint8)
vc = cv2.VideoCapture(0)
ret, image = vc.read()
imgavg = smear(10)
next(imgavg)
while ret and cv2.waitKey(40) & 0xff != ord(' '):
cv2.imshow('ori', image)
image = imgavg.send(image)
cv2.imshow('aft', image)
ret, image = vc.read()
imgavg.close()
cv2.destroyAllWindows()