How to display opencv output window inside a Label or Widget in form.ui

  • Hi all,

    I am new to Qt and opencv, I am programming a graphical interface to record a video through webcam using opencv libraries in Qt. Problem is when I push the start recording button on my interface, a new window gets launched and I dont want that. It should be like after pressing the start recording button it should display the opencv output of webcam inside a Label or Widget on my graphical interface and not on a newly launched window.

    I am using Qt 5.8 on windows 10. Below is the while loop which captures the frame and displays in a window

    while (1)
                    Mat frame;
                    bool bSuccess =; // read a new frame from video
                    if (!bSuccess) 
                         cout << "ERROR: Cannot read a frame from video file" << endl;
                    imshow("MyVideo", frame); //this line launches a new output window
                   if (waitKey(10) == 27) 
                        cout << "esc key is pressed by user" << endl;
                        return ;

    Can anyone please guide me on how can I embed the opencv output window inside a Label or Widget in my form.ui.

    Thank you for your time and knowledge.

  • Lifetime Qt Champion


    AFAIK, you can't direclty.

    One way to do it is described here.

  • @SGaist I tried with your suggested link and it works. Thank you so much

Log in to reply

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