Results 1 to 3 of 3

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

  1. #1
    Join Date
    Feb 2017
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

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

    Qt Code:
    1. while (1)
    2. {
    3.  
    4. Mat frame;
    5.  
    6. bool bSuccess = cap.read(frame); // read a new frame from video
    7.  
    8. if (!bSuccess)
    9. {
    10. cout << "ERROR: Cannot read a frame from video file" << endl;
    11. break;
    12. }
    13.  
    14. oVideoWriter.write(frame);
    15.  
    16.  
    17. imshow("MyVideo", frame); //this line launches a new output window
    18.  
    19.  
    20. if (waitKey(10) == 27)
    21. {
    22.  
    23. cout << "esc key is pressed by user" << endl;
    24. return ;
    25.  
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

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

    Thank you for your time and knowledge.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

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

    Back in the day I was doing such things using QImage and QPixmap.
    Have a look at the documentation of both classes, ask if you have any further questions.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    And don't use infinite while() loops in Qt applications without also calling QCoreApplication::processEvents() somewhere within it. Otherwise, your application GUI will lock up. All GUI updates in Qt depend on having an event loop that that can process events (like painting); if you write an infinite while() loop that doesn't let this processing occur, then even if your loop is retrieving frames and updating an image to be displayed on a label, the label will never have chance to repaint itself.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 18th October 2015, 13:06
  2. Qt Creator Display console output in main window in a sidebar
    By Cupidvogel in forum Qt Tools
    Replies: 4
    Last Post: 30th May 2014, 10:54
  3. Replies: 7
    Last Post: 1st February 2013, 01:36
  4. Inserting label inside textEdit widget
    By dshan in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2011, 12:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.