Answers.Body: <p>That looks like a case where you get an <em>overflow</em>.</p>
  <p>Just doing an addition of two components with a char (or <code>std::uint8_t</code> in C++) will often overflow. I don't know about python implementation and how you've done your add, but just checking whether it's more than 255 if the value is on one byte is not going to work. You need to do the addition in at least a short, average, then save the results.</p>
  <p>One way people deal with this issue is by using a float for each pixel. The addition won't break the type and you can easily calculate the average afterward.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-23T12:26:28.213Z
Answers.Text: That solved it, thanks! :)
Answers.UserDisplayName: dbantje
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-07-09T17:56:42.650Z
Answers.LastActivityDate: 2021-07-09T17:56:42.650Z
Answers.UserDisplayName: Alexis Wilke
Body: <p>I want to &quot;stack&quot; two (or more) videos with the same background, such that it looks like there are two people moving at the same time (not sure if stacking is the right term for that?).</p>
  <p>So far, I've tried that using opencv-python, both by summing or averaging the overlapping frames.</p>
  <p>The desired effect is there, but I get these weird colors:</p>
  <p><a href="https://i.sstatic.net/Wt8ki.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Wt8ki.jpg" alt="enter image description here" /></a></p>
  <p>Where do these effects come from and how can I avoid them?</p>
  
Tags: <editing>
Title: Weird colors when stacking videos
UserDisplayName: dbantje
ThreadText: # Weird colors when stacking videos
  
  (Asked by: username_0 on 2021-07-09)
  
  I want to "stack" two (or more) videos with the same background, such that it looks like there are two people moving at the same time (not sure if stacking is the right term for that?).
  
  So far, I've tried that using opencv-python, both by summing or averaging the overlapping frames.
  
  The desired effect is there, but I get these weird colors:
  
  [![enter image description here](https://i.sstatic.net/Wt8ki.jpg)](https://i.sstatic.net/Wt8ki.jpg)
  
  Where do these effects come from and how can I avoid them?
  
  **Tags:** editing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-07-09. Score: 0 | Accepted answer
  
  That looks like a case where you get an *overflow*.
  
  Just doing an addition of two components with a char (or `std::uint8_t` in C++) will often overflow. I don't know about python implementation and how you've done your add, but just checking whether it's more than 255 if the value is on one byte is not going to work. You need to do the addition in at least a short, average, then save the results.
  
  One way people deal with this issue is by using a float for each pixel. The addition won't break the type and you can easily calculate the average afterward.
  
  > **Comments:**
  > **username_0**: That solved it, thanks! :)  
  
  ---
  
  