Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT QImage to cv::Mat conversion causing memory leak
Forum Updated to NodeBB v4.3 + New Features

QT QImage to cv::Mat conversion causing memory leak

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 776 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.
  • S Offline
    S Offline
    sigmind
    wrote on last edited by
    #1

    I have a QPixmap which I want to convert to cv::Mat. First I've converted it to QImage.

    QPixmap picture;
    QImage image = picture.toImage();
    

    Then the QImage is sent to the conversion function. But this function is causing memory leak.

    cv::Mat QImage2Mat(const QImage& src) {
        cv::Mat mat = cv::Mat(src.height(), src.width(), CV_8UC4, (uchar*)src.bits(), src.bytesPerLine());
        cv::Mat result = cv::Mat(mat.rows, mat.cols, CV_8UC3 );
        int from_to[] = { 0,0,  1,1,  2,2 };
        cv::mixChannels( &mat, 1, &result, 1, from_to, 3 );
        return result;
    }
    
    cv::Mat matImage  = QImage2Mat(image);
    
    Pablo J. RoginaP 1 Reply Last reply
    0
    • S sigmind

      I have a QPixmap which I want to convert to cv::Mat. First I've converted it to QImage.

      QPixmap picture;
      QImage image = picture.toImage();
      

      Then the QImage is sent to the conversion function. But this function is causing memory leak.

      cv::Mat QImage2Mat(const QImage& src) {
          cv::Mat mat = cv::Mat(src.height(), src.width(), CV_8UC4, (uchar*)src.bits(), src.bytesPerLine());
          cv::Mat result = cv::Mat(mat.rows, mat.cols, CV_8UC3 );
          int from_to[] = { 0,0,  1,1,  2,2 };
          cv::mixChannels( &mat, 1, &result, 1, from_to, 3 );
          return result;
      }
      
      cv::Mat matImage  = QImage2Mat(image);
      
      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @sigmind just in case you may want to take a look at this post

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        What makes you think there's a memory leak ?

        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
        0

        • Login

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