QT and opencv dualmonitor



  • 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


  • Moderators

    @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.



  • 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.


  • Lifetime Qt Champion

    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.



  • 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?


  • Lifetime Qt Champion

    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.



  • 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


  • Lifetime Qt Champion

    Are you mirroring your desktop ?



  • @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


  • Lifetime Qt Champion

    Then if you are mirroring you have one logical screen.



  • 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


  • Lifetime Qt Champion

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


  • 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.


  • Lifetime Qt Champion

    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.



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

Log in to reply
 

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