如何组合许多连续图像来模拟逼真的运动模糊?

How to combine many successive image to simulate a realistic motion blurring?

我想模拟逼真的运动模糊。我不想对整个图像产生模糊效果,而只是对移动的物体产生模糊效果。我知道我可以使用滤镜,但模糊效果会散布在整个图像中。我想使用光流但我不确定它是否会起作用,因为结果在很大程度上取决于提取的特征。

我的主要想法是合并连续帧以生成运动模糊。

谢谢

没那么容易。

你确实可以试试光流。估计每对帧之间的流量。模糊运动方向的帧(例如各向异性高斯),过滤范围等于位移。最后,通过形成加权平均来混合模糊图像和背景,其中每一帧在移动更多的地方获得更多权重。

您需要为对象设置 [0,1] alpha 掩码。然后,您可以使用定向滤镜来模糊对象及其蒙版,例如,如下所示: https://www.packtpub.com/mapt/book/application_development/9781785283932/2/ch02lvl1sec21/motion-blur

然后使用模糊蒙版将模糊对象 alpha 混合回原始未模糊或其他场景:

 #Blend the alpha_mask region of the foreground over the image background
 #fg is foreground, alpha_mask is a [0,255] mask, image is background scene
    foreground = fg.astype(float)
    background = image.astype(float)
    #Normalize alpha_mask
    alpha = alpha_mask.astype(float) / 255
    # Multiply the foreground with the alpha_mask
    foreground = cv2.multiply(alpha, foreground)
    # Multiply the background with ( 1 - alpha )
    background = cv2.multiply(1.0 - alpha, background)
    # Add the masked foreground and background, turn back to byte image
    composit_image = cv2.add(foreground, background).astype(np.uint8)