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. adding openCV Video to QT Widget
Forum Updated to NodeBB v4.3 + New Features

adding openCV Video to QT Widget

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 4.9k 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.
  • M Offline
    M Offline
    mjv817
    wrote on last edited by
    #1

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

    }

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

      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

      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
      1
      • M Offline
        M Offline
        mjv817
        wrote on last edited by
        #3

        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.

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

          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 :)

          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