Repository: opencv
Issue: “Retina” resolution support on macOS [feature request]
Labels: category: highgui-gui,platform: ios/osx,RFC

##### System information (version)
- OpenCV => 4.5.1
- Operating System / Platform => macOS Big Sur 11.4
- Compiler => Xcode / LLVM

**Summary:** by default, OpenCV HighGUI windows display on Apple macOS devices at half the normal screen resolution. Ideally HighGUI should (at least have an option to) display images at full “Retina” resolution. (See potential work-around / solution in final paragraph below.)

**Background:** for reasons that must have made sense to them at the time, when Apple generally doubled the screen resolution their macOS (laptop, desktop) machines, they kept a “backwards compatible” mode where the screen content could be specified either in _pixels_ or subpixels called “_points_.” (Generally a pixel is a 2x2 grid of points, although the definition allows other ratios.) Software that is not native to macOS—including OpenCV—generally draws pixels rather than points, so displays at half the hardware resolution of the display.

I had looked into this in February 2020, posting this question in the old Forum [display OpenCV image at full “Retina” resolution on macOS](https://answers.opencv.org/question/226776/display-opencv-image-at-full-retina-resolution-on-macos/). Later Vadim Pisarevsky kindly discussed this with me, and suggested I file a feature request here, which I am finally doing, more that a year later. (He mentioned that he added Retina support to the list of desirable features in a future new GUI: [Implement new-generation UI for OpenCV samples and Demos](https://github.com/opencv/opencv/wiki/OE-24.-Module-HighGUI))

I have been using OpenCV in half-screen-resolution mode. I was reminded of this issue when I wrote some code to size a HighGUI window based on screen size and other constraints. (It would be _really_ nice to have an API to get the current screen size—but that is a different feature request.) I looked up my laptop’s screen resolution and wrote it as a constant in my (prototype, non-portable) code: 2880 by 1800. Everything worked, but I realized everything was half as big as I expected. I think this is a feature of HighGUI that will scale down large windows to fit on the screen (`cv::namedWindow` parameter `flags` of `WINDOW_AUTOSIZE`?). 

**Significantly, in that situation, it was in fact displaying at Retina resolution!!**

**Work-around / potential solution:** While I am largely ignorant of the internals of both OpenCV and macOS’s Cocoa API, this suggests that there may be a relative simple way for OpenCV to support Retina resolution on macOS. It also suggests a simple work-around that for an OpenCV user to use Retina resolution today. Simply define a HighGUI window whose pixel size is twice as large as the screen (that is: define it as the screen resolution measured in “points”). When that window is displayed, it gets scaled down to Retina resolution allowing each screen point to be addressed from OpenCV. Shown below are my “oversized window” at Retina resolution (2880x1800) and another defined at pixel resolution (half screen resolution: 1440x900). Note that the title bar text is about the same size in each, and the spacing between the sub-images is “10” — ten _points_ in one case and ten _pixels_ in the other.

<img width="1442" alt="Screen Shot 2021-07-10 at 11 03 10 AM" src="https://user-images.githubusercontent.com/1909341/125515312-712e64dc-f4ce-4efe-8fe9-b11e744a5e42.png">

<img width="1447" alt="Screen Shot 2021-07-13 at 11 14 08 AM" src="https://user-images.githubusercontent.com/1909341/125515363-9ffa7101-9712-4477-b95c-3f1bb42cace9.png">