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
#else
#include
#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);
}