You are using integer math in summing frames to increase processing speed. Integer math has the advantage that it can keep the high precision of floating point values even though you use integers. But then (e.g. when adding YUYV images), you artificially reduce the precision of your result to 8bit before you sum (average) your frames. You would get a much better result if you first summed them and later clip them. I have produced a version of the code which uses 16bit integer precision combined with 32bit buffers to achieve a better image quality when adding images that internally are anyways available in 16bit precision.
You are using integer math in summing frames to increase processing speed. Integer math has the advantage that it can keep the high precision of floating point values even though you use integers. But then (e.g. when adding YUYV images), you artificially reduce the precision of your result to 8bit before you sum (average) your frames. You would get a much better result if you first summed them and later clip them. I have produced a version of the code which uses 16bit integer precision combined with 32bit buffers to achieve a better image quality when adding images that internally are anyways available in 16bit precision.