title: Converting wx bitmap to numpy using BitmapBufferFormat_RGBA (python)
body: <p>I'm trying to capture a window with wxPython and process the result with cv2. This seems fairly straight forward as wx has a built in function to convert a bitmap object to a simple RGB array.</p>
  
  <p>The problem is that I can't figure out the syntax. The documentation is sparse and the few examples I can find are either deprecated or incomplete.   </p>
  
  <p>Here's basically what I want </p>
  
  <pre><code>app = wx.App(False)
  img = some_RGBA_array #e.g. cv2.imread('some.jpg')
  s = wx.ScreenDC()
  w, h = s.Size.Get()
  b = wx.EmptyBitmap(w, h)
  m = wx.MemoryDCFromDC(s)
  m.SelectObject(b)
  m.Blit(0, 0, w, h, s, 0, 0)
  m.SelectObject(wx.NullBitmap)
  b.CopyFromBuffer(m, format=wx.BitmapBufferFormat_RGBA, stride=-1)#&lt;----problem is here
  img.matchSizeAndChannels(b)#&lt;----placeholder psuedo
  img[:,:,0] = np.where(img[:,:,0] &gt;= 0, b[:,:,0], img[:,:,0])#&lt;---copy a channel
  </code></pre>
  
  <p>For simplicity this doesn't specify a window and only processes one channel but it should give an idea of what I'm attempting to do.</p>
  
  <p>Whenever I try to run it like that using CopyFromBuffer it tells me that the bitmap stored in "b" isn't a readable buffer object yet if I pass it to SaveFile it writes out the image as expected.</p>
  
  <p>Not sure what I'm doing wrong here. </p>
  
  <p><strong>EDIT: Turns out what I'm doing wrong is trying to use BitmapBufferFormat_RGBA to convert wxBitmaps to cv2 rgb's. As per the answer below I should use the following (where "b" is the bitmap):</strong></p>
  
  <pre><code>wxB = wx.ImageFromBitmap(b)#input bitmap 
  buf = wxB.GetDataBuffer() 
  arr = np.frombuffer(buf, dtype='uint8',count=-1, offset=0)
  img2 = np.reshape(arr, (h,w,3))#convert to classic rgb
  img2 = cv2.cvtColor(img2, cv2.COLOR_RGB2BGR)#match colors to original image
  </code></pre>