我一直在开发opencv,并通过了cv 2。setMouseCallback()。下面是在鼠标单击时绘制圆的代码。
import cv2 import numpy as np
import cv2
import numpy as np
def draw_circle(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(image,(x,y),(100,100),(255,0,0),-1)
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow("image")
cv2.setMouseCallback("image",draw_circle)
while True:
cv2.imshow("image",image)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
cv2.destroyAllWindows()`
请解释
1.函数draw_circle如何在不传递所有参数的情况下被调用
1.函数中有五个参数,只有两个变量可以赋值
1.创建cv 2的目的是什么?namedWindow(“image”)
谢谢!
1条答案
按热度按时间xqk2d5yq1#
1.您不调用
draw_circle
,openCV会在鼠标事件中使用适当的事件和坐标为您调用它,您只需指定在setMouseCallback
中调用哪个函数1.如果你需要额外的变量,你可以通过
param
发送1.您可以有多个窗口,每个窗口都有不同的鼠标操作集
我希望这个例子可以帮助那些偶然发现的人: