Is it possible to set/update the cursor coordinates from within OpenCV mouse events? I have a virtual keyboard and I am trying to make it such that whenever the cursor hovers over a button, it is locked at the mid-point of the button.
My current mouse callback function:
def on_mouse(self, event, x, y, flags, param):
global x1, y1
if event == cv2.EVENT_MOUSEMOVE:
x1, y1 = x, y
for button in self.button_list:
if button.is_hovered_over(x1, y1):
# set the cursor coordinates here
The main function:
import cv2
cap = cv2.VideoCapture(0)
from pynput.mouse import Button, Controller
mouse = Controller()
from keyboards import QWERTYKeyboard
keyboard = QWERTYKeyboard.QWERTYKeyboard()
cv2.namedWindow("Image", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.setMouseCallback("Image", keyboard.on_mouse)
while cap.isOpened():
success, image = cap.read()
.
.
.
pred_x, pred_y = model.predict(ave_x, ave_y)
cv2.circle(image, (ave_x, ave_y), 1, (255, 0, 0), 5)
mouse.position = (pred_x, pred_y)
cv2.imshow("Image", image)
if cv2.waitKey(1) & 0xFF == 27:
break
cv2.destroyAllWindows()
cap.release()