Skip to content

“y” argument to moveWindow() being ignored? #16343

Closed

Description

@cwreynolds
System information (version)
  • OpenCV => 4.1.2
  • Operating System / Platform => macOS Catalina 10.15.2
  • Compiler => Xcode / clang / c++
Detailed description

(I must be doing something wrong. This seems too obvious to be a real bug.)

Running a version of OpenCV 4.1.2, recently installed (via homebrew) on macOS Catalina 10.15.2, I tried to show several images in individual windows. I wanted to offset the windows along a diagonal:

    int window_counter = 0;
    int window_position = 0;
    for (int i = 0; i < 4; i++)
    {
        std::string window_name = "TexSyn" + std::to_string(window_counter++);
        cv::namedWindow(window_name);
        cv::moveWindow(window_name, window_position, window_position);
        window_position += 30;
        cv::imshow(window_name, opencv_image);
    }
    cv::waitKey(0);

The windows appear. They are offset in “x” but not in “y”:

Screen Shot 2020-01-13 at 4 19 36 PM

Activity

  1. alalek commented on Jan 14, 2020

    @alalek
    Member

    Which GUI backend is used? (check getBuildInformation())

    There is corresponding code for these backends:

  2. cwreynolds commented on Jan 14, 2020

    @cwreynolds
    ContributorAuthor

    Thanks for looking at this. Down below it says GUI: Cocoa: YES:

    General configuration for OpenCV 4.1.2 =====================================
      Version control:               unknown
    
      Extra modules:
        Location (extra):            /tmp/opencv-20191101-13084-e06xvq/opencv-4.1.2/opencv_contrib/modules
        Version control (extra):     unknown
    
      Platform:
        Timestamp:                   2019-11-01T12:57:08Z
        Host:                        Darwin 19.0.0 x86_64
        CMake:                       3.15.4
        CMake generator:             Unix Makefiles
        CMake build tool:            /usr/local/Homebrew/Library/Homebrew/shims/mac/super/gmake
        Configuration:               Release
    
      CPU/HW features:
        Baseline:                    SSE SSE2 SSE3 SSSE3 SSE4_1 POPCNT SSE4_2
          requested:                 DETECT
          disabled:                  AVX AVX2
        Dispatched code generation:  FP16 AVX AVX2 AVX512_SKX
          requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
          FP16 (0 files):            + FP16 AVX
          AVX (4 files):             + AVX
          AVX2 (27 files):           + FP16 FMA3 AVX AVX2
          AVX512_SKX (3 files):      + FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
    
      C/C++:
        Built as dynamic libs?:      YES
        C++ Compiler:                /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang++  (ver 11.0.0.11000033)
        C++ flags (Release):         -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG  -DNDEBUG
        C++ flags (Debug):           -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
        C Compiler:                  /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang
        C flags (Release):           -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG  -DNDEBUG
        C flags (Debug):             -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections  -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
        Linker flags (Release):      -Wl,-dead_strip  
        Linker flags (Debug):        -Wl,-dead_strip  
        ccache:                      NO
        Precompiled headers:         NO
        Extra dependencies:
        3rdparty dependencies:
    
      OpenCV modules:
        To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 quality reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
        Disabled:                    python2 world
        Disabled by dependency:      -
        Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java js matlab ovis ts viz
        Applications:                apps
        Documentation:               NO
        Non-free algorithms:         YES
    
      GUI: 
        Cocoa:                       YES
    
      Media I/O: 
        ZLib:                        /usr/lib/libz.dylib (ver 1.2.11)
        JPEG:                        build-libjpeg-turbo (ver 2.0.2-62)
        WEBP:                        build (ver encoder: 0x020e)
        PNG:                         /usr/local/lib/libpng.dylib (ver 1.6.37)
        TIFF:                        /usr/local/lib/libtiff.dylib (ver 42 / 4.0.10)
        OpenEXR:                     /usr/local/lib/libImath.dylib /usr/local/lib/libIlmImf.dylib /usr/local/lib/libIex.dylib /usr/local/lib/libHalf.dylib /usr/local/lib/libIlmThread.dylib (ver 2.3.0)
        HDR:                         YES
        SUNRASTER:                   YES
        PXM:                         YES
        PFM:                         YES
    
      Video I/O:
        FFMPEG:                      YES
          avcodec:                   YES (58.54.100)
          avformat:                  YES (58.29.100)
          avutil:                    YES (56.31.100)
          swscale:                   YES (5.5.100)
          avresample:                YES (4.0.0)
        AVFoundation:                YES
    
      Parallel framework:            TBB (ver 2019.9 interface 11009)
    
      Trace:                         YES (with Intel ITT)
    
      Other third-party libraries:
        Intel IPP:                   2019.0.0 Gold [2019.0.0]
               at:                   /tmp/opencv-20191101-13084-e06xvq/opencv-4.1.2/build/3rdparty/ippicv/ippicv_mac/icv
        Intel IPP IW:                sources (2019.0.0)
                  at:                /tmp/opencv-20191101-13084-e06xvq/opencv-4.1.2/build/3rdparty/ippicv/ippicv_mac/iw
        Lapack:                      YES (/usr/local/opt/openblas/lib/libopenblas.dylib)
        Eigen:                       YES (ver 3.3.7)
        Custom HAL:                  NO
        Protobuf:                    build (3.5.1)
    
      OpenCL:                        YES (no extra features)
        Include path:                NO
        Link libraries:              -framework OpenCL
    
      Python 3:
        Interpreter:                 /usr/local/opt/python/bin/python3 (ver 3.7.5)
        Libraries:                   /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib (ver 3.7.5)
        numpy:                       /usr/local/lib/python3.7/site-packages/numpy/core/include (ver 1.17.2)
        install path:                lib/python3.7/site-packages/cv2/python-3.7
    
      Python (for build):            /usr/bin/python2.7
    
      Java:                          
        ant:                         NO
        JNI:                         /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include
        Java wrappers:               NO
        Java tests:                  NO
    
      Install to:                    /usr/local/Cellar/opencv/4.1.2
    -----------------------------------------------------------------
    
  3. saskatchewancatch commented on Jan 15, 2020

    @saskatchewancatch
    Contributor

    I think there may be a clue here: window_cocoa.mm Line 290 in the Cocoa handling of moveWindow

    y = [[window screen] frame].size.height - y; ? Maybe this explains why all the windows are anchored to the top (I think that's what I see in your screenshot).

    What do you think? I don't do iOS so why that special handling exists for the y direction is beyond me.🤷

    @alalek @cwreynolds I'm tempted to take that line out but there must be a story why that special handling exists. Seems like lot of debug string comments are also left out in that file, maybe someone forgot to remove debug lines and this special y-direction handling was for debug? 🤷

  4. cwreynolds commented on Jan 15, 2020

    @cwreynolds
    ContributorAuthor

    @saskatchewancatch @alalek

    Thanks. Before I saw your note I was thinking the same thing. There is very little that goes on in that Cocoa-specific function besides flipping the y coordinate. I know next to nothing about the macOS native windowing system. When I web searched I saw that the origin is normally in the lower left, but that sometimes may be “flipped” due to coordinate transforms. Which comes down to: “increasing y is up, unless it is down.”

    I was considering trying it without that line, but having installed OpenCV via homebrew I would first have to clone the repo and get set up to build. If someone can try that easier than me I would be just as happy.

  5. added
    Hackathon
    on Jan 21, 2020
  6. self-assigned this
    on Feb 3, 2020
  7. saskatchewancatch commented on Feb 3, 2020

    @saskatchewancatch
    Contributor

    @vpisarev I see you've taken this issue. I tried something last week, maybe this will help your debug efforts.

    When I use OP's repro code, I am able to repro the issue. But when I try my own, the behaviour is as expected. This will produce 3 cascaded windows:

    int main()
    {
            Mat a = Mat::zeros(Size(100, 100), CV_8U);
            namedWindow("1");
            namedWindow("2");
            namedWindow("3");
    
            moveWindow("1", 100, 100 );
            moveWindow("2", 200, 200);
            moveWindow("3", 300, 300);
    
            imshow("1", a);
            imshow("2", a);
            imshow("3", a);
    
            waitKey(0);
    
            return 0;
    }
    

    Screen Shot 2020-02-03 at 1 55 18 PM

    But OP's code will repro the issue as shown in his screenshot.

    My MacBook Pro SSD is busted and I left the issue last week.

    Perhaps this finding is helpful to you.

  8. saskatchewancatch commented on Feb 3, 2020

    @saskatchewancatch
    Contributor

    Update: I am mistaken. In my repro screenshot above, things are not working correctly. As you can see, first window (1) is supposed to be at 100, 100. But it is clearly not at 100, 100. More like 0, 100.

    It seems that y coordinates given to moveWindow may be off by like 100.

  9. cwreynolds commented on Feb 3, 2020

    @cwreynolds
    ContributorAuthor

    (Sorry if this is just spectator noise, but I am baffled by how this symptom got even weirder after @saskatchewancatch’s experiment. In his screen shot, the vertical position difference between window 1 and 2 is less than between window 2 and 3. I’d be tempted to guess that the windows are moved to the given position, but with the Y shifted up about 128 pixels, then clipped at the top of the screen.)

  10. cwreynolds commented on Feb 5, 2020

    @cwreynolds
    ContributorAuthor

    @vpisarev: One more observation, then I promise I will shut up. I ran @saskatchewancatch’s test case, then overlaid a green diagonal line. It passes very close the the lower-left corner of windows 2 and 3. Window 1 is displaced down to keep it on the screen.

    It looks like the x, y arguments to moveWindow() are being applied to the lower left corner of the window.

    The doc is ambiguous on this detail, but I assumed the x, y arguments to moveWindow() should refer to the upper-left corner of the window

    Screen Shot 2020-02-05 at 2 01 45 PM

  11. saskatchewancatch commented on Feb 6, 2020

    @saskatchewancatch
    Contributor

    @cwreynolds Interesting observation. Though it's interesting that the moveWindow implementation is calling setFrameTopLeftPoint which supposedly sets the window position using the top left part of the window as the anchor.

    I think another part of the problem is that the moveWindow function is relying on the resolution of the whole screen to figure out where to set the top-left of the window. This is a problem because it does not account for the fact that the MacOs menu bar takes up some space at the top. Thus, if Cocoa functions to set the top-left of the window are called to set position to (0, 0), the window will get placed not at (0, 0), but just right under the menu bar.

    The workaround to this would be to get the visibleFrame property of the screen instead of just the frame, as is done currently in moveWindow. visibleFrame will return the position/size of the screen area that is not occupied by the menu bar.

  12. vpisarev commented on Feb 14, 2020

    @vpisarev
    Contributor

    Dear @cwreynolds, @saskatchewancatch, thank you for the help! This discussion and the advice to use "visibleFrame" property worked out well. Also, I had to postpone the actual repositioning of newly created windows until the very first imshow.

  13. cwreynolds commented on Feb 15, 2020

    @cwreynolds
    ContributorAuthor

    Great! Thank you for the fix @vpisarev

  14. added a commit that references this issue on Feb 22, 2020
  15. added a commit that references this issue on Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Hackathonbugcategory: highgui-guiplatform: ios/osx

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions