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. [SOLVED] OpenCV processed image back to QImage doesn't work
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] OpenCV processed image back to QImage doesn't work

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.5k Views 1 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.
  • P Offline
    P Offline
    pmh4514
    wrote on last edited by
    #1

    I'm having trouble getting an OpenCV processed result rendered on a Widget. Basically I have a widget, I process its displayed pixels and then redisplay them.

    I begin by grabbing a Widget's view:

    @
    QPixmap view(myWidget->grab());
    @

    I then convert it to QImage
    @
    QImage image = view.toImage();
    @

    I then setup an OpenCV matrix, one for the original, one for processed:

    @
    Mat matOriginal(iH,iW,CV_8UC4,(uchar*)image.bits(),image.bytesPerLine());
    Mat matProcessed = Mat::zeros( matOriginal.size(), matOriginal.type() );
    @

    I then run OpenCV's equalizeHist to perform a histogram equalization:

    @
    cvtColor(matOriginal, matProcessed, CV_BGR2GRAY);
    equalizeHist(matProcessed, matProcessed);
    @

    This much works perfectly, I can verify the equalized histogram by using OpenCV to pop it open in a new window:

    @
    namedWindow("2", CV_WINDOW_AUTOSIZE);
    imshow("2", matProcessed);
    @

    The new OpenCV window shows matProcessed, and clearly the histogram has been properly equalized.

    Finally I want to convert that back to QImage, so that I can show it on the Qt widget:
    @
    QImage imgFinal = QImage((uchar*) matProcessed.data, matProcessed.cols, matProcessed.rows, matProcessed.step, image.format());

    QPainter paint(this);
    paint.drawImage(0,0, imgFinal);
    

    @

    The problem is that what is rendered on the QWidget during paint(..) is the original image without the histogram equalization. I'm unsure why this is especially since the OpenCV window I opened with matProcessed shows the proper result.

    Where have I gone wrong?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pmh4514
      wrote on last edited by
      #2

      I found a solution.. my resulting transform to QImage was not actually creating an image. I used the accepted solution found here:

      http://stackoverflow.com/questions/11543298/qt-opencv-displaying-images-on-qlabel

      and now it works!

      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