Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. “qimage out of memory returning null image” after working for 60 QImages

“qimage out of memory returning null image” after working for 60 QImages

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
opencvqimageqpixmap
5 Posts 3 Posters 1.2k Views
  • 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.
  • T Offline
    T Offline
    tim5
    wrote on 8 Jul 2021, 12:46 last edited by tim5 7 Aug 2021, 12:47
    #1

    I read a lot of posts on this topic but no post seems to help me. I am running a 32Bit Qt Application.

    I wonder why I receive this error at some point:

    qimage out of memory returning null image

    I want to read videoframes from a mp4 File and convert them into a QImage. After that I want to convert the QImage to a QPixmap to display it on a QGraphicsView (setPixmap).

    Thats the relevant code:

    Function I use to convert a cv::Mat into a QPixmap:

    QPixmap QtMainApp::MatToQPixmap(cv::Mat& cvMat)
    {
        QImage qimg((cvMat).data,
            (cvMat).cols,
            (cvMat).rows,
            (cvMat).step,
            QImage::Format_RGB888);
    
        return QPixmap::fromImage(qimg.rgbSwapped());
    }
    

    Where I call the function and read the videoframes from the mp4 file:

    std::vector <QPixmap> vecQVideobilder{};
     
    cv::VideoCapture videofile;
    videofile.open("video.mp4");
    
    while(true)
    {
    
       bool bErfolg = videofile.read(MatTemp);
                    
       if (!bErfolg)
           break;
    
                  
       vecQVideobilder.push_back(MatToQPixmap(MatTemp));
                    
    
    }
    

    The weird thing is, that it works fine for a random number of frames. I can display these frames without a problem.

    But at some point (after 60 to 100 frames (it differs)) I receive the error message and I get blank images only.

    I have read that It could be that the size/solution of the frame is to big for a 32Bit application QImage. But then I wonder why it is working for the first 60 or 100 frames.

    Is there something I can do? Thanks in advance.

    Kind regards Tim

    J 1 Reply Last reply 8 Jul 2021, 12:51
    0
    • T tim5
      8 Jul 2021, 12:46

      I read a lot of posts on this topic but no post seems to help me. I am running a 32Bit Qt Application.

      I wonder why I receive this error at some point:

      qimage out of memory returning null image

      I want to read videoframes from a mp4 File and convert them into a QImage. After that I want to convert the QImage to a QPixmap to display it on a QGraphicsView (setPixmap).

      Thats the relevant code:

      Function I use to convert a cv::Mat into a QPixmap:

      QPixmap QtMainApp::MatToQPixmap(cv::Mat& cvMat)
      {
          QImage qimg((cvMat).data,
              (cvMat).cols,
              (cvMat).rows,
              (cvMat).step,
              QImage::Format_RGB888);
      
          return QPixmap::fromImage(qimg.rgbSwapped());
      }
      

      Where I call the function and read the videoframes from the mp4 file:

      std::vector <QPixmap> vecQVideobilder{};
       
      cv::VideoCapture videofile;
      videofile.open("video.mp4");
      
      while(true)
      {
      
         bool bErfolg = videofile.read(MatTemp);
                      
         if (!bErfolg)
             break;
      
                    
         vecQVideobilder.push_back(MatToQPixmap(MatTemp));
                      
      
      }
      

      The weird thing is, that it works fine for a random number of frames. I can display these frames without a problem.

      But at some point (after 60 to 100 frames (it differs)) I receive the error message and I get blank images only.

      I have read that It could be that the size/solution of the frame is to big for a 32Bit application QImage. But then I wonder why it is working for the first 60 or 100 frames.

      Is there something I can do? Thanks in advance.

      Kind regards Tim

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 8 Jul 2021, 12:51 last edited by
      #2

      @tim5 Did you observe memory consumption of your app? Maybe it gets out of memory?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tim5
        wrote on 8 Jul 2021, 13:13 last edited by
        #3

        I looked in the task-manager. I only used 50%.
        Is there a way to see exactly the memory reserved for my qt app? Or is the qt app able to access all of the available memory?

        J 1 Reply Last reply 8 Jul 2021, 13:28
        0
        • T tim5
          8 Jul 2021, 13:13

          I looked in the task-manager. I only used 50%.
          Is there a way to see exactly the memory reserved for my qt app? Or is the qt app able to access all of the available memory?

          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 8 Jul 2021, 13:28 last edited by
          #4

          @tim5 The task manager can show how much memory an app is consuming (on the first tab). If I understood you correctly your app is 32bit? Such an app can only use up to 3GB if I'm not mistaken on Windows (or 2GB).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 8 Jul 2021, 14:07 last edited by
            #5

            Hi,

            You should check your video file, but as I wild guess, it's likely a FullHD video which is 1920 * 1024. Since you are creating a RGB QImage out of it, it's already weighing about 6MB per image. QPixmap is meant to be optimised for rendering and thus the backing memory used might even be larger for, for example, alpha channel handling. Depending on what else you do with your application and these images you can pretty quickly hit memory limits if your application is 32bit.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            2/5

            8 Jul 2021, 12:51

            • Login

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