def imageToArray(img, copy=False, transpose=True):
 fmt = img.format()
 ptr = img.bits()
 if USE_PYSIDE:
  arr = np.frombuffer(ptr, dtype=np.ubyte)
 else:
  ptr.setsize(img.byteCount())
  arr = np.asarray(ptr)
  if (img.byteCount() != (arr.size * arr.itemsize)):
   arr = np.frombuffer(ptr, np.ubyte, img.byteCount())
 arr = arr.reshape(img.height(), img.width(), 4)
 if (fmt == img.Format_RGB32):
  arr[..., 3] = 255
 if copy:
  arr = arr.copy()
 if transpose:
  return arr.transpose((1, 0, 2))
 else:
  return arr

def imageToArray ( img , copy = False , transpose = True ) : fmt = img . format ( ) ptr = img . bits ( ) if USE_PYSIDE : arr = np . frombuffer ( ptr , dtype = np . ubyte ) else : ptr . setsize ( img . byteCount ( ) ) arr = np . asarray ( ptr ) if ( img . byteCount ( ) != ( arr . size * arr . itemsize ) ) : arr = np . frombuffer ( ptr , np . ubyte , img . byteCount ( ) ) arr = arr . reshape ( img . height ( ) , img . width ( ) , 4 ) if ( fmt == img . Format_RGB32 ) : arr [ ... , 3 ] = 255 if copy : arr = arr . copy ( ) if transpose : return arr . transpose ( ( 1 , 0 , 2 ) ) else : return arr
convert a qimage into numpy array .