在OpenCV上获取屏幕尺寸 [英] Getting screen size on OpenCV

查看:402
本文介绍了在OpenCV上获取屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在OpenCV上获得计算机屏幕分辨率? 我需要使用整个屏幕宽度并排显示两个图像,OpenCV需要我要创建的确切窗口大小.

How do I get the computer screen resolution on OpenCV? I need to show two images side by side using the whole screen width, OpenCV requires the exact window size I wanna create.

推荐答案

您可以在有或没有opencv的情况下使用此解决方案跨平台解决方案:

You can use this solution cross-platform solution with or without opencv:

#if WIN32
  #include <windows.h>
#else
  #include <X11/Xlib.h>
#endif

//...

void getScreenResolution(int &width, int &height) {
#if WIN32
    width  = (int) GetSystemMetrics(SM_CXSCREEN);
    height = (int) GetSystemMetrics(SM_CYSCREEN);
#else
    Display* disp = XOpenDisplay(NULL);
    Screen*  scrn = DefaultScreenOfDisplay(disp);
    width  = scrn->width;
    height = scrn->height;
#endif
}

int main() {
    int width, height;
    getScreenResolution(width, height);
    printf("Screen resolution: %dx%d\n", width, height);
}

这篇关于在OpenCV上获取屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆