Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qlabel in video not showing - Raspberry pi 4 Opencv 4.1.0



  • I installed Opencv 4.1.0 and Qt Creator on Rpi 4. I created a gui with a button and a label. When the button is clicked, I want the video to play in the label. The codes I use for this are:
    VideoCapture cap(“/home/users/video.mp4”);
      if(!cap.isOpened()){
         cout << "Error opening video stream or file" << endl;
         return -1;
      }

    while(1)
    {
    	Mat frame;
    	cap >> frame;
    	if (frame.empty())
    

    break;

    	Qimage img = Qimage((uchar*) frame.data, frame.cols, frame.rows, frame.step, Qimage::Format_RGB888);
    	ui→label→setPixmap(QPixmap::fromImage(img));
    	char c = (char) waitKey(25);
    	if(c==27)
    		break;
    }
    cap.release();
    destroyAllWindows();
    

    No video is shown in Label. But imshow (“Frame”, frame); When I add the command line, the video is displayed in the label.
    How can I show the video in qlabel ?


  • Lifetime Qt Champion

    Hi,

    You are blocking the event loop with your tight loop as well as your wait key.

    Use a Timer that will read your file at regular interval since you anyway wait for 25ms.



  • ui->label->repaint()


Log in to reply