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. Display image in Qlabel
QtWS25 Last Chance

Display image in Qlabel

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 13.1k 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
    thomas11live.com.sg
    wrote on last edited by
    #1

    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();
    }@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      LuGRU
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        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

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thomas11live.com.sg
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thomas11live.com.sg
            wrote on last edited by
            #5

            [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;
            

            }
            @

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thomas11live.com.sg
              wrote on last edited by
              #6

              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

              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