我有一个显示全屏窗口的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_WINDOW_FULLSCREEN); // create target image Mat img = Mat(Size(width_second,CV_8UC1); // show the image imshow("My Window",img); waitKey(0); return 0; }