gpt4 book ai didi

多台显示器上的 OpenCV 全屏窗口

转载 作者:太空宇宙 更新时间:2023-11-03 20:49:43 33 4
gpt4 key购买 nike

我有一个显示全屏窗口的 OpenCV 应用程序,通过:

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

它工作正常,但是当我有多个显示器时,它总是在第一个显示器上显示全屏窗口。有没有办法在第二台显示器上显示?我试过设置 X/Y 和宽度/高度,但一旦启用全屏,它们似乎就会被忽略。

最佳答案

编辑:

有时纯 OpenCV 代码无法在双显示器上显示全屏窗口。这是一个 Qt实现方式:

#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 文件配置为:

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

# Input
SOURCES += main.cpp

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

qmake
make

原文:

这是可能的。

这是一个有效的演示代码,用于在第二个显示器上显示全屏图像。来自 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 全屏窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24540091/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com