display OpenCV image at full “Retina” resolution on macOS

asked 2020-02-24 21:53:01 -0500

cwr gravatar image

It was suggested I ask a new question, even though this same issue was asked in June 2016 and never answered.

When imshow is called on an OpenCV mat on an Apple macOS machine, it is displayed at half the “Retina” screen resolution. That is, it is twice the size it should be in both dimensions, essentially “zoomed in” or scaled up.

There may be a reason this is the default behavior. But I want to be able to display images at the same high resolution as the rest of the screen and at their “natural” size. Is there any way to do that?

I'm using OpenCV 4.1.2 on macOS Catalina 10.15.2 with Xcode/clang/c++

image description

edit retag flag offensive close merge delete



Can you show your code? imshow code is here. There is no dpi in opencv

LBerger gravatar imageLBerger ( 2020-02-25 02:37:41 -0500 )edit

The code is pretty unremarkable, and similar to bob_oi’s example in his 2016 question. the variable size is normally set to 511:

// Make a 3-float OpenCV Mat instance
cv::Mat opencv_image(size, size, CV_32FC3, cv::Scalar(0.5, 0.5, 0.5));
// ...load image data from my texture synthesis system into the Mat...
cv::imshow(window_name, opencv_image);
cwr gravatar imagecwr ( 2020-02-25 17:26:56 -0500 )edit

What is the size value? Have you got opengl in your opencv configuration?

LBerger gravatar imageLBerger ( 2020-02-26 01:52:52 -0500 )edit

As I mentioned above, size is normally 511. The resolution of my Retina LCD screen is 2880x1800. When I display my 511x511 images using imshow and tile them horizontally, I can fit two of them (plus most of a third one) across the screen. This corresponds to my original report that they are about 1024x1024, roughly twice their “natural” size. I expected to fit at least 5 of these images across the screen.

As to OpenGL, I do not think so, but am not sure. I installed OpenCV using the HomeBrew package management system, similar to appgeton Linux. This page describes brew’s OpenCV package: https://formulae.brew.sh/formula/opencv (Probably not relevant but an old version of OpenGL is definitely installed on this laptop and I use it in other projects. OpenGL is deprecated by Apple.)

cwr gravatar imagecwr ( 2020-02-27 12:10:43 -0500 )edit

Perhaps I can ask my friends who more about Objective-C++ and the macOS window system if they know how to access Retina resolution.

(Interesting coincidence the macOS source for cvMoveWindow just below the code reference give by LBerger above, was recently patched in response to another bug I reported.)

cwr gravatar imagecwr ( 2020-02-27 12:11:22 -0500 )edit