After a long search here, I found a gem that gave me a working solution. I got most of my code from this answer to another question: fooobar.com/questions/957834 / ...
The main problem I ran into was using the pointer correctly. The big thing that I think is missing is the setize function.
Here is my import:
import cv2 import numpy as np
Here is my function:
def convertQImageToMat(incomingImage): ''' Converts a QImage into an opencv MAT format ''' 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)
source share