Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Intermittent errors displaying image with pixmap
Forum Updated to NodeBB v4.3 + New Features

Intermittent errors displaying image with pixmap

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 2 Posters 730 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    metalshreds
    wrote on last edited by
    #1

    Sometimes when I load an image (np array to QImage to pixmap) into my application, the image does not display but instead I get an image like the one attached. Without changing any code I can re-load the app and the image will display fine. I am not sure where to start troubleshooting as this does work but intermittently. Thanks in advance for any help.

    0_1558458006967_img.PNG

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      show us yoru code that takes the raw array data and converts to the Qt intermediate and final formats. smells like you are not doing the conversions properly and are ending up with buffer overruns that are not being captured. so, sometimes it works and sometimes it does not.

      M 1 Reply Last reply
      0
      • Kent-DorfmanK Kent-Dorfman

        show us yoru code that takes the raw array data and converts to the Qt intermediate and final formats. smells like you are not doing the conversions properly and are ending up with buffer overruns that are not being captured. so, sometimes it works and sometimes it does not.

        M Offline
        M Offline
        metalshreds
        wrote on last edited by metalshreds
        #3

        @Kent-Dorfman Hi sorry for the delayed response, I didn't get a notification on your reply. Below is the code that I'm using to take a 3d numpy array of data (im), collapsing it into a 2d x,y image and then converting it to a QImage. I then add this to a Qpixmap that I display in a QLabel. I am new to Qt so not sure if I'm doing that correctly :/

        x, y, t = im.shape
          im = np.sum(im, axis=2)  # collapse to 2d image
          img_8bit = ((im - im.min()) / (im.ptp() / 255.0)).astype(np.uint8)  # map the data range to 0 - 255
          return QImage(img_8bit, x, y, x, QImage.Format_Grayscale8)
        

        Maybe Format_Grayscale8 isnt' the correct format to use but not sure which is, Format_Indexed8 also displays my image fine. the numpy array stores vlaues as uint16. Please let me know if you need more info.

        https://doc.qt.io/qt-5/qimage.html#Format-enum

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved