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.
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);
}
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With