在这里插入图片描述

2.代码

import numpy as np
import cv2


x_center = [100,200,300,400]
y_center = [200,200,200,200]
radius = 30

def mouse_LButtonDown(event, x, y, flags, param):
    global temp
    if event == cv2.EVENT_LBUTTONDOWN:
        print(f" Down Clicked at ({x}, {y})")

        for i in range(len(x_center)):

            if (x-x_center[i])**2 + (y-y_center[i])**2 <= radius**2:
                temp = i
                print("选中")


    if event == cv2.EVENT_LBUTTONUP:
        print(f" Up Clicked at ({x}, {y})")
        print(temp)
        x_center[temp] = x
        y_center[temp] = y
        print('更新成功')
        print(x_center)
        print(y_center)



cv2.namedWindow('mouse',cv2.WINDOW_NORMAL)
cv2.resizeWindow('mouse',640,480)
cv2.setMouseCallback('mouse', mouse_LButtonDown)

color = (0, 255, 0)


while True:
    img = np.zeros((480, 640, 3), dtype=np.uint8)
    for i in range(len(x_center)):
        cv2.circle(img, (x_center[i], y_center[i]), 30, color, -1, lineType=cv2.FILLED)
    cv2.imshow('mouse', img)
    key =  cv2.waitKey(1)
    if key == ord('q'):
        break

cv2.destroyAllWindows()



点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部