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. QLabel show Image problem
Qt 6.11 is out! See what's new in the release blog

QLabel show Image problem

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

    I want to get image from opencv capture and show it on QLabel frame by frame. Now i use a timer to refresh ui

    this->timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updatePicture()));
    
    void FaceCamera::updatePicture()
    {
    	cap >> this->image;
    	showMatOnQLabel(image, ui.cameraLabel);
    }
    
    void FaceCamera::showMatOnQLabel(cv::Mat mat, QLabel *qlabel)
    {
    	//conversion from Mat to QImage
    	if (mat.empty())
    		return;
    
    	cv::Mat dest;
    	cv::cvtColor(mat, dest, CV_BGR2RGB);
    
    	QImage imageFromMat = QImage((uchar*)dest.data, dest.cols, dest.rows, dest.step, QImage::Format_RGB888);
    	QImage qimage = imageFromMat.scaled(QSize(qlabel->width(), qlabel->height()), Qt::AspectRatioMode::KeepAspectRatio);
    
    	//show QImage using QLabel
    	qlabel->setPixmap(QPixmap::fromImage(qimage));
    }
    

    it can works, but if i directly get frame in main thread one by one and showMatOnQLabel,
    it will not show image util the last frame i get.

    why this happens ? plese help me

    thx : ]

    chen.xu
    from beijing
    2019.9.30

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Try adding qlabel->repaint(); after qlabel->setPixmap

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

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

        Hi and welcome to devnet,

        At what speed are you triggering the timer ?

        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