adding openCV Video to QT Widget



  • Hey Folks,

    Having a bit of an issue getting a video to display in a QT Widget.

    I can get an openCV window to run/function and display video from my webcam just fine,but when I execute a program the openCV window is the only part the will open until I terminate the webcam loop. Once the webcam is disabled my QT GUI will pop up like normal.

    Below is a copy of my VideoCapture example and a part of my MainWindow Class.

    void VideoHeader::videoCap()
    {
    
        Mat frame;
        VideoCapture cap;
    
        cap.open(0);
        if(!cap.isOpened())
        {
            cerr << "ERROR! Unable to open camera\n";
        }
    
        cout << "Start grabbing" << endl;
    
    
    
        for(;;)
        {
            cap.read(frame);
            if(frame.empty())
            {
                cerr << "ERROR! Blank frame grabbed\n";
                break;
            }
            //convertMat(frame);
            //imshow("Live", frame);
    
            /*
            if(waitKey(5) >= 0)
                break;
            */
    
    
    
        }
    
    
    }```
    
    

    MainWindow::MainWindow() : textEdit(new QTextEdit)
    {

    //createOpenCVWindow();
    createCentralWindow();
    createDockingWindow_One();
    VideoHeader newVideo;
    //videoCap();
    //createDockingWindow_Two();
    

    }


  • Lifetime Qt Champion

    Hi,

    That's because you are creating an infinite loop that doesn't let Qt's event loop run.

    This post describes an interesting way of using OpenCV capture with a Qt GUI.

    Hope it helps



  • Thanks for the response! That link has lead me down the right path I believe. Using QThread to run the VideoCapture function portion and it appears to be working somewhat properly now.


  • Lifetime Qt Champion

    Great !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)


Log in to reply
 

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