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



  • 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?



  • 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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.