zhiqingstudy

Be a young person with knowledge and content

To control the mouse, Opencv must first set a callback function for the window. The prototype is: setMouseCallback (winname, callback, userdata)
Winname is the name of the window, callback is the set callback function, userdata is the parameter of the callback function, and the default value is None.
Callback (event, x, y, flags, userdata): callback function, event is an event, whether the mouse is left or right or middle button; x. Y is the position of the mouse, and the event is the coordinate point of the mouse; Flags mainly use combination keys, such as pressing the left mouse button of ctrl.
import cv2
import numpy as np

# 创建一张全黑的图片
img=np.zeros((360,640,3),np.uint8)

def mousecallback(event,x,y,flag,userdata):
    print(event,x,y,flag,userdata)

# mousecallback(1,20,30,16,'666')
# 创建窗口
cv2.namedWindow('窗口',cv2.WINDOW_NORMAL)
cv2.resizeWindow('窗口',640,360)

# 设置鼠标回调
cv2.setMouseCallback('窗口',mousecallback,'123')

while 1:
    cv2.imshow('窗口',img)
    key=cv2.waitKey(1)
    if key==ord('q'):
        break
cv2.destroyAllWindows
comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号