我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用cv2.EVENT_FLAG_LBUTTON。
def onmouse(self, event, x, y, flags, param): x, y = np.int16([x, y]) # BUG if event == cv2.EVENT_LBUTTONDOWN: self.drag_start = (x, y) if self.drag_start: if flags & cv2.EVENT_FLAG_LBUTTON: xo, yo = self.drag_start x0, y0 = np.minimum([xo, yo], [x, y]) x1, y1 = np.maximum([xo, yo], [x, y]) self.drag_rect = None if x1-x0 > 0 and y1-y0 > 0: self.drag_rect = (x0, y0, x1, y1) else: rect = self.drag_rect self.drag_start = None self.drag_rect = None if rect: self.callback(rect)
def on_mouse(self, event, x, y, flags, param): pt = (x, y) if event == cv2.EVENT_LBUTTONDOWN: self.prev_pt = pt elif event == cv2.EVENT_LBUTTONUP: self.prev_pt = None if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON: for dst, color in zip(self.dests, self.colors_func()): cv2.line(dst, self.prev_pt, pt, color, 5) self.dirty = True self.prev_pt = pt self.show() # palette data from matplotlib/_cm.py
def draw_rect(event,x,y,flags,param): global x1,y1,x2,y2,drawing,img,imgSmall,finishDraw # ?????????????? if event==cv2.EVENT_LBUTTONDOWN: drawing=True x1,y1=x,y # ???????????????? event ??????? flag ?????? elif event==cv2.EVENT_MOUSEMOVE and flags==cv2.EVENT_FLAG_LBUTTON: if drawing==True: img[:,:]=newGray[:,:] img[y1:y,x1:x]=imgSmall[y1:y,x1:x] cv2.rectangle(img,(x1,y1),(x,y),(0,0,255),1) # ?????????? elif event==cv2.EVENT_LBUTTONUP: drawing==False x2,y2=x,y finishDraw = True
def onmouse(self, event, x, y, flags, param): x, y = np.int16([x, y]) # BUG if event == cv2.EVENT_LBUTTONDOWN: self.drag_start = (x, y) return if self.drag_start: if flags & cv2.EVENT_FLAG_LBUTTON: xo, yo = self.drag_start x0, y0 = np.minimum([xo, yo], [x, y]) x1, y1 = np.maximum([xo, yo], [x, y]) self.drag_rect = None if x1-x0 > 0 and y1-y0 > 0: self.drag_rect = (x0, y0, x1, y1) else: rect = self.drag_rect self.drag_start = None self.drag_rect = None if rect: self.callback(rect)
def on_mouse(self, event, x, y, flags, param): pt = (x, y) if event == cv2.EVENT_LBUTTONDOWN: self.prev_pt = pt elif event == cv2.EVENT_LBUTTONUP: self.prev_pt = None if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON: for dst, color in zip(self.dests, self.colors_func()): cv2.line(dst, self.prev_pt, pt, color, 50) self.dirty = True self.prev_pt = pt self.show()
def onmouse(event, x, y, flags, param): global seed_pt if flags & cv2.EVENT_FLAG_LBUTTON: seed_pt = x, y update()
def on_mouse(self, event, x, y, flags, param): pt = (x, y) if event == cv2.EVENT_LBUTTONDOWN: self.prev_pt = pt if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON: for dst, color in zip(self.dests, self.colors_func()): cv2.line(dst, self.prev_pt, pt, color, 5) self.dirty = True self.prev_pt = pt self.show() else: self.prev_pt = None # palette data from matplotlib/_cm.py
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