效果
代码
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()