I was testing out OpenCV
's mouse callback function with pynput.mouse
and I realised the coordinates of the cursor are different. Here is the output from the code below. Does anyone know what the offset is as it does not seem to be consistent in the output
import cv2
cap = cv2.VideoCapture(0)
from pynput.mouse import Controller
mouse = Controller()
def on_mouse(event, x, y, flags, param):
'''
Mouse callback function
'''
global x1, y1
if event == cv2.EVENT_MOUSEMOVE:
x1, y1 = x, y
print("opencv: ", str((x1, y1)))
print("pynput: ", str(mouse.position))
cv2.namedWindow("Image", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.setMouseCallback("Image", on_mouse)
while cap.isOpened():
success, image = cap.read()
cv2.imshow("Image", image)
if cv2.waitKey(1) & 0xFF == 27:
break
cv2.destroyAllWindows()
cap.release()