多台显示器上的OpenCV全屏Windows

多台显示器上的OpenCV全屏Windows

本文介绍了多台显示器上的OpenCV全屏Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过以下方式显示全屏窗口的OpenCV应用程序:

I have an OpenCV application that displays a fullscreen window, via:

cv::namedWindow("myWindow", CV_WINDOW_NORMAL)
cv::setWindowProperties("myWindow", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN)

它可以正常工作,但是当我有多台显示器时,它总是在第一台显示器上显示全屏窗口.第二台显示器上有什么显示方式吗?我尝试设置X/Y和Width/Height,但是启用全屏后,它们似乎会被忽略.

It works fine, but when I have multiple monitors it always displays the fullscreen window on the First monitor. Is there any way to display on the 2nd monitor? I've tried setting X/Y and Width/Height, but they seem to be ignored once fullscreen is enabled.

推荐答案

有时,纯OpenCV代码无法在双显示器上执行全屏窗口.这是 Qt 的实现方式:

Sometimes pure OpenCV code cannot do a fullscreen window on a dual display. Here is a Qt way of doing it:

#include <QApplication>
#include <QDesktopWidget>
#include <QLabel>

#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QDesktopWidget dw;
    QLabel myLabel;

    // define dimension of the second display
    int width_second  = 2560;
    int height_second = 1440;

    // define OpenCV Mat
    Mat img = Mat(Size(width_second, height_second), CV_8UC1);

    // move the widget to the second display
    QRect screenres = QApplication::desktop()->screenGeometry(1);
    myLabel.move(QPoint(screenres.x(), screenres.y()));

    // set full screen
    myLabel.showFullScreen();

    // set Qimg
    QImage Qimg((unsigned char*)img.data, img.cols, img.rows, QImage::Format_Indexed8);

    // set Qlabel
    myLabel.setPixmap(QPixmap::fromImage(Qimg));

    // show the image via Qt
    myLabel.show();

    return app.exec();
}

不要忘记将.pro文件配置为:

Don't forget to configure the .pro file as:

TEMPLATE = app
QT += widgets
TARGET = main
LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui

# Input
SOURCES += main.cpp

然后在终端中将代码编译为:

And in terminal compile your code as:

qmake
make


原始:

有可能.

这是一个有效的演示代码,用于在第二台显示器上显示全屏图像.提示来自如何使用OpenCV在不同的显示器中显示不同的窗口:

Here is a working demo code, to show a full-screen image on a second display. Hinted from How to display different windows in different monitors with OpenCV:

#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main ( int argc, char **argv )
{
    // define dimension of the main display
    int width_first  = 1920;
    int height_first = 1200;

    // define dimension of the second display
    int width_second  = 2560;
    int height_second = 1440;

    // move the window to the second display
    // (assuming the two displays are top aligned)
    namedWindow("My Window", CV_WINDOW_NORMAL);
    moveWindow("My Window", width_first, height_first);
    setWindowProperty("My Window", CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);

    // create target image
    Mat img = Mat(Size(width_second, height_second), CV_8UC1);

    // show the image
    imshow("My Window", img);
    waitKey(0);

    return 0;
}

这篇关于多台显示器上的OpenCV全屏Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 04:27