After zooming in image, how to get standard mouse cursor back?

asked 2019-08-08 14:19:52 -0600

updated 2019-08-08 16:14:32 -0600

I have an application where I draw lots of rectangles on images in OpenCv 4 using Python. Some of the images are very large, so it is helpful to zoom in on them before selecting regions to crop. The problem is when you zoom on an image, you get the "hand" symbol for interaction with the image and this completely interferes with the mouse callback function I use to crop images. That is, once you zoom, the mouse cursor is permanently toggled to a hand, and then clicking, dragging only serves to translate the position of the image in the window (unless I go back out to full size, but then I can't draw rectangles on the zoomed-in image).

So my question is once I've zoomed in, how can I get back to the standard mouse cursor so I can use my standard mouse button events to draw/drag rectangles?

Here is my mouse-callback function.

def mouse_callback(event, x, y, flags, param):
    global image_to_show, s_x, s_y, e_x, e_y, mouse_pressed

    if event == cv2.EVENT_LBUTTONDOWN:
        mouse_pressed = True
        s_x, s_y = x, y
        image_to_show = np.copy(image)

    elif event == cv2.EVENT_MOUSEMOVE:
        if mouse_pressed:
            image_to_show = np.copy(image)
            cv2.rectangle(image_to_show, (s_x, s_y),
                          (x, y), (255, 255, 255), line_width)

    elif event == cv2.EVENT_LBUTTONUP:
        mouse_pressed = False
        e_x, e_y = x, y
        print(s_x, s_y, e_x, e_y)

One thing that sort of works is when I changed my program so that it is right button presses/releases that draws the rectangles, so then there is no longer any interference with the native left-click navigation. The problem is I can draw more precise rectangles when I have an arrow than when I have a hand. So while this is a hack I can use as a workaround, it would be really nice if I could toggle back to the arrow for drawing rectangles while zoomed in.

Note I have asked this at stack overflow:

edit retag flag offensive close merge delete