def mouse_event(self, event, x, y, flags, param):
# Convert x and y coordinates into 16-bit numpy integers
x, y = np.int16([x, y])
# Check if a mouse button down event has occurred
if event == cv2.EVENT_LBUTTONDOWN:
self.drag_start = (x, y)
self.tracking_state = 0
# Check if the user has started selecting the region
if self.drag_start:
if flags & cv2.EVENT_FLAG_LBUTTON:
# Extract the dimensions of the frame
h, w = self.frame.shape[:2]
# Get the initial position
xi, yi = self.drag_start
# Get the max and min values
x0, y0 = np.maximum(0, np.minimum([xi, yi], [x, y]))
x1, y1 = np.minimum([w, h], np.maximum([xi, yi], [x, y]))
# Reset the selection variable
self.selection = None
# Finalize the rectangular selection
if x1-x0 > 0 and y1-y0 > 0:
self.selection = (x0, y0, x1, y1)
else:
# If the selection is done, start tracking
self.drag_start = None
if self.selection is not None:
self.tracking_state = 1
# Method to start tracking the object
camshift.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录