Skip to content
Advertisement

PyQt5 QImage from Numpy Array

Considering the following code

JavaScript

I get the following error

TypeError: arguments did not match any overloaded call: QImage(): too many arguments QImage(QSize, QImage.Format): argument 1 has unexpected type ‘numpy.ndarray’ QImage(int, int, QImage.Format): argument 1 has unexpected type ‘numpy.ndarray’ QImage(bytes, int, int, QImage.Format): argument 1 has unexpected type ‘numpy.ndarray’
QImage(sip.voidptr, int, int, QImage.Format): argument 1 has unexpected type ‘numpy.ndarray’ QImage(bytes, int, int, int, QImage.Format): argument 1 has unexpected type ‘numpy.ndarray’
QImage(sip.voidptr, int, int, int, QImage.Format): argument 1 has unexpected type ‘numpy.ndarray’ QImage(List[str]): argument 1 has unexpected type ‘numpy.ndarray’ QImage(str, format: str = None): argument 1 has unexpected type ‘numpy.ndarray’ QImage(QImage): argument 1 has unexpected type ‘numpy.ndarray’ QImage(Any): too many arguments

According to this post this can be caused by numpy creating a view. Modifying the lines

JavaScript

To

JavaScript

Produces the same error. To test that I am not passing a view I print the result of the test

JavaScript

and it’s False. The image is visualised correctly with cv2. I am clearly missing something, any idea what?

Cheers!

Advertisement

Answer

I added a copy after the transpose like this:

JavaScript

and that worked for me.

Advertisement