Display image in Qlabel



  • Dear all,
    I receive the image from a camera and want to display at Qlabel.
    I receive the image with a worker thread and whenever the thread receive the image it sends the signal to the MainWindow's slot to display the image. Worker thread's signal and MainWindow's slot are working well. I receive the images and I can save in bmp.
    The problem is I just can't display the image at Qlabel.

    Qlabel also has no problem, I can display offline images.

    The problem is the received images are not displayed at Qlabel. What could be the problem?

    @void MainWindow::newImageReceivedInformed(imageData receiveImage)
    {
    opencvimageData_t opcvImage;
    QPixmap pixma;
    int col = receiveImage.imageframe.GetCols();// captured image's column
    int row = receiveImage.imageframe.GetRows();// captured image's row
    int data_size = receiveImage.imageframe.GetDataSize();//captured image's data size
    QImage qImg = QImage(col, row, QImage::Format_RGB32);
    opcvImage.opencvimageframe = cvCreateImage(cvSize(col, row), IPL_DEPTH_8U, 1);//3 channels for RGB
    memcpy(opcvImage.opencvimageframe->imageData, receiveImage.imageframe.GetData(), data_size);
    cvSaveImage( "imag.bmp", opcvImage.opencvimageframe );
    opcvImage.imgnumber = receiveImage.snr;
    capturedImageQueue.setQueue(opcvImage);
    IplImage2QImage(opcvImage.opencvimageframe, qImg);
    pixma = QPixmap::fromImage(qImg);
    qImg.save("imag1.bmp");
    ui->label->setPixmap(pixma);
    pixma.save("imag2.bmp");
    ui->label->show();
    }@



  • Is received image from the camera 24b? If so, then error is here:

    @cvCreateImage(cvSize(col, row), IPL_DEPTH_8U, 1);//3 channels for RGB@

    This create 8b image, not 24b one (1 channel 8bit).
    Also your qImg is 32bit, 24 + 8 bit alpha, change it to 24b, i.e.: QImage::Format_RGB888.

    Also You don't need threads for receiving images from the webcam, simple signal slot mechanism is more then enought.



  • Will it really be required to save the image to Bitmap?

    If image is already in memory, why not display it right away ???

    Can't construct a QImage from the image data you have in memory?
    http://doc.qt.digia.com/qt/qimage.html#QImage-6



  • @MuldeR
    I don't need to save as bmp. That is my debugging for the image received. So it means, no problem in received image data (i.e. the image data is there and just can't display).
    Thanks



  • [quote author="LuGRU" date="1355499175"]Is received image from the camera 24b? If so, then error is here:

    @cvCreateImage(cvSize(col, row), IPL_DEPTH_8U, 1);//3 channels for RGB@

    This create 8b image, not 24b one (1 channel 8bit).
    Also your qImg is 32bit, 24 + 8 bit alpha, change it to 24b, i.e.: QImage::Format_RGB888.

    Also You don't need threads for receiving images from the webcam, simple signal slot mechanism is more then enought.[/quote]

    I applied thread because I need some processing for the received image. The processing will take longer than the frame interval so I implement thread.
    My camera can receive gray scale image so 8bit depth is not the problem.
    Let me tell you the problem. I make a method to display offline image as below.
    When I call the method from other MainWindow's methods e.g constructor, it displays. But when I call from this slot (void MainWindow::newImageReceivedInformed(imageData receiveImage)), it does not display. What is the problem?

    @void MainWindow::plot()
    {
    QImage *qImg;
    QPixmap pixma;

    qImg = new QImage();
    if(!(qImg->load("orig.bmp")))
    {
            qWarning("ERROR");
    }
    
    pixma = QPixmap::fromImage(*qImg);
    ui->label->setPixmap(pixma);
    //ui->label->show();
    delete qImg;
    

    }
    @



  • Hi,
    Now I found that my thread implementation doesn't work well.
    I followed the idea discussed in the link
    http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/
    But somehow, it didn't work well.
    When the worker thread runs, my main thread is frozen, the whole UI is also frozen.
    That threading idea doesn't work.
    Now I changed to timer, whenever the timer timeout, it calls the MainWindow's slot method.
    Now I can display the image.
    Thanks


Log in to reply
 

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