def convertQImageToMat(incomingImage):
''' Converts a QImage into an opencv MAT format '''
# Format_RGB32 = 4,存入格式为B,G,R,A 对应 0,1,2,3
# RGB32图像每个像素用32比特位表示,占4个字节,
# R,G,B分量分别用8个bit表示,存储顺序为B,G,R,最后8个字节保留
incomingImage = incomingImage.convertToFormat(4)
width = incomingImage.width()
height = incomingImage.height()
ptr = incomingImage.bits()
ptr.setsize(incomingImage.byteCount())
arr = np.array(ptr).reshape(height, width, 4) # Copies the data
# arr为BGRA,4通道图片
return arr