简体   繁体   English

如何在 opencv 中更改鼠标 cursor 图像?

[英]How to change mouse cursor image in opencv?

I try to develop remote program using c++ and opencv, and I want to change mouse cursor (crosshair).我尝试使用 c++ 和 opencv 开发远程程序,并且我想更改鼠标 cursor(十字准线)。

However, it is difficult to change it in opencv.但是,在 opencv 中很难更改。 (In WINAPI, it is possible using Setcursor func) (在 WINAPI 中,可以使用 Setcursor 函数)

Is there any method to change cursor image?有什么方法可以更改 cursor 图像吗? or hide?还是隐藏?

I had the same need, you can do it this way:我有同样的需求,你可以这样做:

import cv2
import win32api
import win32con

def mouse_evt(event, x, y, flags, param):
    # Mouse is Moving
    if event == cv2.EVENT_MOUSEMOVE:
        if some_condition:
            win32api.SetCursor(win32api.LoadCursor(0, win32con.IDC_SIZEALL))

cv2.namedWindow("image")
cv2.setMouseCallback("image", mouse_evt)

while True:
    cv2.imshow("image", image)
    cv2.waitKey(10)

I personally use it to drag cropping point around, the some_condition returns true if the cursor is close to a set point on the image.我个人使用它来拖动裁剪点,如果光标接近图像上的设置点,则 some_condition 返回 true。

I stumbled across this , which doesn't directly apply to us, until you do:我偶然发现了这个,它并不直接适用于我们,直到你这样做:

import cv2
import win32api

cv2.namedWindow("my_window")
cv2.setMouseCallback("my_window", mouse_evt)

def mouse_evt(event, x, y, flags, param):
# could also probably do: def mouse_evt(*args):
    win32api.SetCursor(None)

which "hides" the cursor.它“隐藏”了 cursor。 The problem with this solution is that if the cursor moves, then you may see a flash of one.此解决方案的问题在于,如果 cursor 移动,那么您可能会看到 flash 为 1。 But if you are willing to get past that, it works like a charm.但是,如果您愿意克服这一点,它就像一种魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM