PyQt QImage cna't copy, crash without error code
-
@darrenleeleelee1 I think you should change your code to:
qimage = QtGui.QImage(arr.data, arr.shape[1], arr.shape[0], QtGui.QImage.Format_Grayscale16)
wrote on 7 Jun 2021, 13:36 last edited by@KroMignon I change but still crash...What is the different between
arr
andarr.data
? -
@KroMignon I change but still crash...What is the different between
arr
andarr.data
?wrote on 7 Jun 2021, 13:51 last edited by@darrenleeleelee1 said in PyQt QImage cna't copy, crash without error code:
What is the different between arr and arr.data?
arr
is an instance ofnumpy.ndarray
type, according to your code!
Andarr.data
is the data buffer according to numpy documentation ==> https://numpy.org/doc/stable/reference/generated/numpy.ndarray.htmlI think it would be great if you first explain what you want to do.
Perhaps you should take a look at this python script which convertsnumpy.ndatarray
toQImage
and vice versa:
https://kogs-www.informatik.uni-hamburg.de/~meine/software/vigraqt/qimage2ndarray.py -
@darrenleeleelee1 said in PyQt QImage cna't copy, crash without error code:
What is the different between arr and arr.data?
arr
is an instance ofnumpy.ndarray
type, according to your code!
Andarr.data
is the data buffer according to numpy documentation ==> https://numpy.org/doc/stable/reference/generated/numpy.ndarray.htmlI think it would be great if you first explain what you want to do.
Perhaps you should take a look at this python script which convertsnumpy.ndatarray
toQImage
and vice versa:
https://kogs-www.informatik.uni-hamburg.de/~meine/software/vigraqt/qimage2ndarray.pywrote on 8 Jun 2021, 01:43 last edited by@KroMignon I saw this before, but I don't know how to apply to uint16.
-
@KroMignon I saw this before, but I don't know how to apply to uint16.
wrote on 8 Jun 2021, 05:45 last edited by@darrenleeleelee1 said in PyQt QImage cna't copy, crash without error code:
I saw this before, but I don't know how to apply to uint16.
Which version of Qt-Libs are you using?
Format_Grayscale16
is only support starting from Qt 5.13 (cf. QImage.Format)Because of this note from documentation:
Constructs an image with the given width , height and format , that uses an existing memory buffer, data . The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
Perhaps you should specify the number of bytes per line, like this:
qimage = QtGui.QImage(arr.data, arr.shape[1], arr.shape[0], arr.shape[1]*2, QtGui.QImage.Format_Grayscale16)
-
@darrenleeleelee1 said in PyQt QImage cna't copy, crash without error code:
I saw this before, but I don't know how to apply to uint16.
Which version of Qt-Libs are you using?
Format_Grayscale16
is only support starting from Qt 5.13 (cf. QImage.Format)Because of this note from documentation:
Constructs an image with the given width , height and format , that uses an existing memory buffer, data . The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
Perhaps you should specify the number of bytes per line, like this:
qimage = QtGui.QImage(arr.data, arr.shape[1], arr.shape[0], arr.shape[1]*2, QtGui.QImage.Format_Grayscale16)
wrote on 8 Jun 2021, 07:09 last edited by darrenleeleelee1 6 Aug 2021, 07:09@KroMignon said in PyQt QImage cna't copy, crash without error code:
arr.shape[1]*2
sorry, I read through the QImage API, but I don;t get why I need to add this.
After I add this it seems can work. -
@KroMignon said in PyQt QImage cna't copy, crash without error code:
arr.shape[1]*2
sorry, I read through the QImage API, but I don;t get why I need to add this.
After I add this it seems can work.wrote on 8 Jun 2021, 07:15 last edited by KroMignon 6 Aug 2021, 07:16@darrenleeleelee1 said in PyQt QImage cna't copy, crash without error code:
sorry, I read through the QImage API, but I don;t get why I need to add this.
Then you don't read carefully ;)
The point is when you only specify width and height: The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.To avoid this, you can use width, height and scanline length in bytes, which is pixel_per_line x pixel_size:
- pixel_per_line is arr.shape[1]
- pixel_size is uint16 which are 2 bytes
==> scanline_size = arr.shape[1]*2
After I add this it seems can work.
Great
-
@darrenleeleelee1 said in PyQt QImage cna't copy, crash without error code:
sorry, I read through the QImage API, but I don;t get why I need to add this.
Then you don't read carefully ;)
The point is when you only specify width and height: The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.To avoid this, you can use width, height and scanline length in bytes, which is pixel_per_line x pixel_size:
- pixel_per_line is arr.shape[1]
- pixel_size is uint16 which are 2 bytes
==> scanline_size = arr.shape[1]*2
After I add this it seems can work.
Great
wrote on 8 Jun 2021, 11:51 last edited by@KroMignon @J-Hilk @JonB @jsulm thanks all u guys!
21/27