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. QT and opencv dualmonitor
Forum Updated to NodeBB v4.3 + New Features

QT and opencv dualmonitor

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 5.0k Views 2 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.
  • K Offline
    K Offline
    kevin32
    wrote on last edited by
    #1

    Hello everyone, can you help me please?

    I use two camera with opencv but i want display each one in diferent screen, its possible do it that without converting frame from opencv? how to do that ? i saw this class http://doc.qt.io/qt-5/qdesktopwidget.html ?
    thanks sorry for my english

    ? 1 Reply Last reply
    0
    • K kevin32

      Hello everyone, can you help me please?

      I use two camera with opencv but i want display each one in diferent screen, its possible do it that without converting frame from opencv? how to do that ? i saw this class http://doc.qt.io/qt-5/qdesktopwidget.html ?
      thanks sorry for my english

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @kevin32 Hi, and welcome to the Qt forum! I guess you'll read each camera's output frame by frame as a QImage, right? So you can just create two windows, each with a QLabel on it to show one camera's output.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        kevin32
        wrote on last edited by
        #3

        Thanks for your help, but i have problems, i don't understand how to send 2 windows on 2 screen? i have one other problem with my code conversion Mat to Qimage in this code :

        QPixmap Mat2QPixmap(const Mat& mat) {
            Mat rgb;
            QPixmap p;
            cvtColor(mat, rgb, CV_BGR2RGB);
            p.convertFromImage(QImage((const unsigned char*)(rgb.data), rgb.cols, rgb.rows, QImage::Format_RGB888));
            return p;
        }
        
        int main(int argc, char *argv[])
        {
        
            QApplication app(argc, argv);
            MainWindow window;
            VideoCapture cap(0);
            QLabel* l = new QLabel(&window);
        
                        if(!cap.isOpened()) // check if we succeeded
                            return -1;
        
        
                           Mat frame;
        
                            cap >> frame;
                            l->setPixmap(Mat2QPixmap(frame));
                            window.show();
                            QThread::sleep(5000);
        
        
        
        
        
                          return 0;
        }
        
        
        

        No error but window display my label without image.
        Thanks and good day.

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

          Hi and welcome to devnet,

          You should check that convertFromImage was successful.

          To place a window on a give screen you should check QDesktopWidget::screenGeometry and move the widget accordingly.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi and welcome to devnet,

            You should check that convertFromImage was successful.

            To place a window on a give screen you should check QDesktopWidget::screenGeometry and move the widget accordingly.

            K Offline
            K Offline
            kevin32
            wrote on last edited by kevin32
            #5

            Thanks, but according this http://stackoverflow.com/questions/3203095/display-window-full-screen-on-secondary-monitor-using-qt QDesktopWidget::screenGeometry dont run in qt5 in my main i try

            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                MainWindow *w;
                w->show();
                w->windowHandle()->setScreen(qApp->screens()[1]);
                w->showFullScreen();
                return 0;
            }
            

            but my app crash and my second monitor is connected with my computer.

            And i try just with a widget :

            #include "mainwindow.h"
            #include <QApplication>
            #include <QDesktopWidget>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
             //   MainWindow *w;
                QWidget * widget = new QWidget();
                widget->show();
                widget->windowHandle()->setScreen(qApp->screens()[1]);
                widget->showFullScreen();
                return 0;
            }
            
            

            my error is :

            ASSERT failure in QList<T>::operator[]: "index out of range", file ..\..\..\..\Qt\5.4\mingw491_32\include/QtCore/qlist.h, line 486
            

            Thank you for helping

            Please how to do that?

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

              First thing to do is to check the number of screens returns by qApp->screens(). Depending on your configuration, a dual monitor setup can be interpreted as only one big screen by the OS.

              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
              • K Offline
                K Offline
                kevin32
                wrote on last edited by
                #7

                Oh yes with that

                 qDebug() <<  qApp->screens();
                   qDebug() <<  QApplication::desktop()->screenCount();
                

                result in consol is

                (QScreen(0x14acd808) ) 
                1
                

                I executed code in windows 8 on laptop with second screen connected and I display my laptop in second screen but why detected only one screen?

                I can't to do dual monitors?

                Thanks for you help

                My OS detebut

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

                  Are you mirroring your desktop ?

                  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
                  • K Offline
                    K Offline
                    kevin32
                    wrote on last edited by
                    #9

                    @SGaist said:

                    Are you mirroring your desktop

                    I just connect with vga cable, i think by default window choice mirroring desktop, i have to duplicate? my situation is http://windows.microsoft.com/en-us/windows-vista/understanding-multiple-monitors My situation is Mirrored desktop display

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

                      Then if you are mirroring you have one logical screen.

                      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
                      • K Offline
                        K Offline
                        kevin32
                        wrote on last edited by
                        #11

                        ok thanks, now I change mode of display in windows and second screen is detected:

                         qDebug() << "Number of screens:" << QGuiApplication::screens().size();
                        
                               qDebug() << "Primary screen:" << QGuiApplication::primaryScreen()->name();
                        Number of screens: 2
                        Primary screen: "\\.\DISPLAY1"
                        

                        So i try to display a widget with that

                        QWidget * widget = new QWidget();
                                  widget->show();
                                  widget->windowHandle()->setScreen(qApp->screens()[1]);
                                  widget->showFullScreen();
                        

                        I d'ont error my project compil scuessfully but my widget it's not display in nothing screen.
                        How i can to do this? thanks for you helping

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

                          Rather something like:

                          MyWidget widget;
                          QDesktopWidget *desktop = QApplication::desktop();
                          
                          QRect geometry = desktop->screenGeometry(1);
                          QRect widgetGeometry = widget.geometry();
                          widgetRegion.moveCenter(geometry.center());
                          w.setGeometry(wRegion);
                          

                          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
                          • K Offline
                            K Offline
                            kevin32
                            wrote on last edited by
                            #13

                            Don't run nothing is diplay my code is:

                               qDebug() << "Number of screens:" << QGuiApplication::screens().size();
                                QWidget widget ;
                                QDesktopWidget *desktop = QApplication::desktop();
                            
                                QRect geometry = desktop->screenGeometry(1);
                                QRect widgetGeometry = widget.geometry();
                                widgetGeometry.moveCenter(geometry.center());
                                widget.setGeometry(widgetGeometry);
                                return 0;
                            

                            Return compilation :

                            Starting C:\Users\user\Documents\build-Double_video-Desktop_Qt_5_4_2_MinGW_32bit2-Debug\debug\Double_video.exe...
                            Number of screens: 2
                            C:\Users\user\Documents\build-Double_video-Desktop_Qt_5_4_2_MinGW_32bit2-Debug\debug\Double_video.exe exited with code 0

                            thanks for you helping.

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

                              If that's your main application then it's normal that nothing is shown. You don't run Qt's event loop. You just create the widget, modify its geometry and return 0 which just ends the application. You need to replace that by return app.exec(); provided that your QApplication instance is called app.

                              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
                              • K Offline
                                K Offline
                                kevin32
                                wrote on last edited by
                                #15

                                Thanks you very much it's work,
                                My code for other persons with same problem

                                Display two widget one in first monitor and other in second monitor.

                                 QWidget widget ;
                                       QDesktopWidget *desktop = QApplication::desktop();
                                
                                       QRect geometry = desktop->screenGeometry(1);
                                       QRect widgetGeometry = widget.geometry();
                                       widgetGeometry.moveCenter(geometry.center());
                                       widget.setGeometry(widgetGeometry);
                                       widget.show();
                                       QWidget widget2 ;
                                
                                       QRect geometry2 = desktop->screenGeometry(0);
                                       QRect widgetGeometry2 = widget2.geometry();
                                       widgetGeometry2.moveCenter(geometry2.center());
                                       widget2.setGeometry(widgetGeometry2);
                                       widget2.setWindowTitle("test");
                                       widget2.show();
                                
                                       return app.exec();
                                
                                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