Getting screen size on OpenCV

后端 未结 6 2027
独厮守ぢ
独厮守ぢ 2021-02-19 09:04

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.

6条回答
  •  时光说笑
    2021-02-19 09:37

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

提交回复
热议问题