Getting screen size on OpenCV

自作多情 提交于 2019-12-05 16:19:21

问题


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.


回答1:


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



回答2:


In Linux, try this

#include <stdio.h>
int main()
{
 char *command="xrandr | grep '*'";
 FILE *fpipe = (FILE*)popen(command,"r");
 char line[256];
 while ( fgets( line, sizeof(line), fpipe))
 {
  printf("%s", line);
 }
 pclose(fpipe);
 return 0;
}

In Windows,

http://cppkid.wordpress.com/2009/01/07/how-to-get-the-screen-resolution-in-pixels/




回答3:


This is not an answer to how to get the screen width and height, but it will let you solve your problem of displaying two images using the full screen size.

1) Create a window like this:

namedWindow("hello", WINDOW_NORMAL);

This will allow you to set the window size yourself, you can set easily maximize it and it will take the whole screen. It will also remember the settings the next time you run the program. You can also set flags to keep the aspect ratio if you desire.

2) If you need to get the exact number of pixels, you can get the window size using this:

getWindowImageRect("hello");

That way, you can easily combine the two images into one and display the result on screen. I'm doing it myself.




回答4:


You can't it's an OS function - it depends on your operating system




回答5:


In new version it also works like below, which is great :-D

printf("%f",cap.get(CV_CAP_PROP_FRAME_HEIGHT));

for setting video res.

<capture_handle>.set(property_in_caps, value_in_double);

ex, cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720);


来源:https://stackoverflow.com/questions/11041607/getting-screen-size-on-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!