import numpy as np
from PyQt5.QtGui import QImage

def qimage_to_numpy(qimage):
    """Convert a QImage to a numpy array"""
    qimage = qimage.convertToFormat(QImage.Format_RGB888)
    width = qimage.width()
    height = qimage.height()
    ptr = qimage.bits()
    ptr.setsize(qimage.byteCount())
    arr = np.array(ptr).reshape(height, width, 3)
    return arr