Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting screen size on 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.

like image 685
Lucas C. Feijo Avatar asked Jun 14 '12 21:06

Lucas C. Feijo


2 Answers

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);
}
like image 141
Derzu Avatar answered Sep 16 '22 11:09

Derzu


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/

like image 32
Froyo Avatar answered Sep 20 '22 11:09

Froyo