鼠标左键为例讲解鼠标事件

#以鼠标左键为例
import cv2
def MouseEventDo(event,x,y,flags,param):
    global txtDir
    if event==cv2.EVENT_FLAG_LBUTTON:#如果鼠标左键发生
        print(txtDir)
        with open(txtDir, 'w') as f:
            f.write(str(int(x*2.5))+' '+ str(int(2.5*y)))

for picNum in picNumList:
    print(picNum)
    txtDir = rootTxt+'\\'+str(picNum)+'.txt'
    imgDir = rootImage+'\\'+str(picNum)+'.0.jpg'


    img = cv2.imread(imgDir)
    img = cv2.resize(img, (0, 0), fx=0.4, fy=0.4, interpolation=cv2.INTER_NEAREST)
    cv2.imshow(str(picNum), img)

    cv2.setMouseCallback(str(picNum), MouseEventDo)

    key = cv2.waitKey()
    if key==32:
        cv2.destroyAllWindows()

 

相关文章:

  • 2021-10-24
  • 2021-07-16
  • 2021-06-11
  • 2022-12-23
  • 2021-04-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-07
  • 2021-12-05
  • 2021-10-04
  • 2022-12-23
  • 2021-09-06
  • 2022-02-13
  • 2021-12-09
相关资源
相似解决方案