我想将鼠标双击2D坐标转换为数组。这是我到目前为止的代码:
import cv2
import numpy as np
ix,iy = -1,-1
# mouse callback function
def draw_circle(event,x,y,flags,param):
global ix,iy
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(img,(x,y),10,(255,0,0),-1)
ix,iy = x,y
# Create a black image, a window and bind the function to window
img = np.zeros((1000,1000,3), np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)
physNodes =[]
while(1):
img = cv2.imread('RPE.jpg')
cv2.imshow('image',img)
k = cv2.waitKey(20) & 0xFF
if k == 27:
break
elif k == ord('a'):
Nodes =[ix,iy]
physNodes.append(Nodes)
#print(physNodes)
cv2.destroyAllWindows()
您可以加载任何类型的图像进行重现。我在一个jupyter笔记本中运行此代码并遇到无法关闭窗口的问题。 但我真正想问的是如何使用传入的用户输入填充数组。谢谢!