我想知道opencv中的 cv2.setMouseCallback()函数的第一个参数,如果是想在网页上捕捉鼠标动作我要填写什么,是网页的title还是其他什么东西,还有怎么获取到这个东西
希望熟悉python和opencv的能给解惑,九敏
一个事例,功能是使用鼠标在命名窗口中显示的图像上渲染一个矩形,可以参考一下
# Import packages
import cv2
# Lists to store the bounding box coordinates
top_left_corner=[]
bottom_right_corner=[]
# function which will be called on mouse input
def drawRectangle(action, x, y, flags, *userdata):
# Referencing global variables
global top_left_corner, bottom_right_corner
# Mark the top left corner when left mouse button is pressed
if action == cv2.EVENT_LBUTTONDOWN:
top_left_corner = [(x,y)]
# When left mouse button is released, mark bottom right corner
elif action == cv2.EVENT_LBUTTONUP:
bottom_right_corner = [(x,y)]
# Draw the rectangle
cv2.rectangle(image, top_left_corner[0], bottom_right_corner[0], (0,255,0),2, 8)
cv2.imshow("Window",image)
# Read Images
image = cv2.imread("../Input/sample.jpg")
# Make a temporary image, will be useful to clear the drawing
temp = image.copy()
# Create a named window
cv2.namedWindow("Window")
# highgui function called when mouse events occur
cv2.setMouseCallback("Window", drawRectangle)
k=0
# Close the window when key q is pressed
while k!=113:
# Display the image
cv2.imshow("Window", image)
k = cv2.waitKey(0)
# If c is pressed, clear the window, using the dummy image
if (k == 99):
image= temp.copy()
cv2.imshow("Window", image)
cv2.destroyAllWindows()