title: Python: merging channels in opencv and manually
body: <pre><code>def frame_processing(frame):
  out_frame = np.zeros((frame.shape[0],frame.shape[1],4),dtype = np.uint8)
  b,g,r = cv2.split(frame)
  alpha = np.zeros_like(b , dtype=np.uint8)
  print(out_frame.shape)
  print(b.shape);print(g.shape);print(r.shape);print(alpha.shape)
  for i in range(frame.shape[0]):
      for j in range(frame.shape[1]):
          a = (frame[i,j,0],frame[i,j,1],frame[i,j,2])
          b = (225,225,225)
          if all(i &gt; j for i, j in zip(a,b)):  #all(a&gt;b) :
              alpha[i,j] = 0
          else:
              alpha[i,j] = 255
  out_frame[:,:,0] = b
  out_frame[:,:,1] = g
  out_frame[:,:,2] = r
  out_frame[:,:,3] = alpha
  #out_frame = cv2.merge((b,g,r,alpha))
  return out_frame
  </code></pre>
  
  <p>Wanted to add an alpha channel; tried <code>cv2.Merge()</code> and manual stacking of channels but failed.</p>
  
  <p>When using <code>cv2.merge()</code>:</p>
  
  <pre><code>error: OpenCV(3.4.2) C:\projects\opencv- 
  python\opencv\modules\core\src\merge.cpp:458: error: (-215:Assertion failed) 
  mv[i].size == mv[0].size &amp;&amp; mv[i].depth() == depth in function 'cv::merge'
  </code></pre>
  
  <p>When manually adding channels:</p>
  
  <pre><code>ValueError: could not broadcast input array from shape (3) into shape 
  (225,225)
  </code></pre>