Python cv2.EVENT_LBUTTONDOWN Examples
The following are 30
code examples of cv2.EVENT_LBUTTONDOWN().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: HSV Color Picker.py From HSV-Color-Picker with MIT License | 9 votes |
def pick_color(event,x,y,flags,param): if event == cv2.EVENT_LBUTTONDOWN: pixel = image_hsv[y,x] #HUE, SATURATION, AND VALUE (BRIGHTNESS) RANGES. TOLERANCE COULD BE ADJUSTED. # Set range = 0 for hue and range = 1 for saturation and brightness # set upper_or_lower = 1 for upper and upper_or_lower = 0 for lower hue_upper = check_boundaries(pixel[0], 10, 0, 1) hue_lower = check_boundaries(pixel[0], 10, 0, 0) saturation_upper = check_boundaries(pixel[1], 10, 1, 1) saturation_lower = check_boundaries(pixel[1], 10, 1, 0) value_upper = check_boundaries(pixel[2], 40, 1, 1) value_lower = check_boundaries(pixel[2], 40, 1, 0) upper = np.array([hue_upper, saturation_upper, value_upper]) lower = np.array([hue_lower, saturation_lower, value_lower]) print(lower, upper) #A MONOCHROME MASK FOR GETTING A BETTER VISION OVER THE COLORS image_mask = cv2.inRange(image_hsv,lower,upper) cv2.imshow("Mask",image_mask)
Example #2
Source File: mouse_drawing.py From Mastering-OpenCV-4-with-Python with MIT License | 8 votes |
def draw_circle(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDBLCLK: print("event: EVENT_LBUTTONDBLCLK") cv2.circle(image, (x, y), 10, colors['magenta'], -1) if event == cv2.EVENT_MOUSEMOVE: print("event: EVENT_MOUSEMOVE") if event == cv2.EVENT_LBUTTONUP: print("event: EVENT_LBUTTONUP") if event == cv2.EVENT_LBUTTONDOWN: print("event: EVENT_LBUTTONDOWN") # We create the canvas to draw: 600 x 600 pixels, 3 channels, uint8 (8-bit unsigned integers) # We set the background to black using np.zeros():
Example #3
Source File: interact.py From DeepFaceLab with GNU General Public License v3.0 | 7 votes |
def on_capture_mouse (self, wnd_name): self.last_xy = (0,0) def onMouse(event, x, y, flags, param): (inst, wnd_name) = param if event == cv2.EVENT_LBUTTONDOWN: ev = InteractBase.EVENT_LBUTTONDOWN elif event == cv2.EVENT_LBUTTONUP: ev = InteractBase.EVENT_LBUTTONUP elif event == cv2.EVENT_RBUTTONDOWN: ev = InteractBase.EVENT_RBUTTONDOWN elif event == cv2.EVENT_RBUTTONUP: ev = InteractBase.EVENT_RBUTTONUP elif event == cv2.EVENT_MBUTTONDOWN: ev = InteractBase.EVENT_MBUTTONDOWN elif event == cv2.EVENT_MBUTTONUP: ev = InteractBase.EVENT_MBUTTONUP elif event == cv2.EVENT_MOUSEWHEEL: ev = InteractBase.EVENT_MOUSEWHEEL x,y = self.last_xy #fix opencv bug when window size more than screen size else: ev = 0 self.last_xy = (x,y) inst.add_mouse_event (wnd_name, x, y, ev, flags) cv2.setMouseCallback(wnd_name, onMouse, (self,wnd_name) )
Example #4
Source File: mouse_painting.py From PyIntroduction with MIT License | 7 votes |
def _callBack(self, event, x, y, flags, param): # マウス左ボタンが押された時の処理 if event == cv2.EVENT_LBUTTONDOWN: self._doEvent(self._press_func, x, y) self._is_drag = True # マウス左ドラッグ時の処理 elif event == cv2.EVENT_MOUSEMOVE: if self._is_drag: self._doEvent(self._drag_func, x, y) # マウス左ボタンが離された時の処理 elif event == cv2.EVENT_LBUTTONUP: self._doEvent(self._release_func, x, y) self._is_drag = False # 描画用の空画像作成
Example #5
Source File: common.py From Traffic-Sign-Detection with MIT License | 7 votes |
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
Example #6
Source File: common.py From OpenCV-Python-Tutorial with MIT License | 7 votes |
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
Example #7
Source File: OCR.py From display_ocr with GNU General Public License v2.0 | 7 votes |
def draw_rectangle(event, x, y, flags, param): global start_x, start_y, end_x, end_y, drawing, expected_value if event == cv2.EVENT_LBUTTONDOWN: # menu position if y < 40: # menu map if x > 8 and x < 148: SaveImage(event) if x > 153 and x < 190: OnClose(event) if x > 195 and x < 252: print "OpenSource Development: https://github.com/arturaugusto/display_ocr.\nBased on examples availables at https://code.google.com/p/python-tesseract/.\nGPLv2 License" else: drawing = True start_x, start_y = x, y end_x, end_y = x, y elif event == cv2.EVENT_LBUTTONUP: drawing = False #start_x,start_y = -1,-1 #end_x,end_y = -1,-1 elif event == cv2.EVENT_MOUSEMOVE and drawing: if y < 40: end_x, end_y = x, 41 else: end_x, end_y = x, y
Example #8
Source File: common.py From MachineLearning with Apache License 2.0 | 7 votes |
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
Example #9
Source File: webcam_demo.py From Re3 with GNU General Public License v3.0 | 7 votes |
def on_mouse(event, x, y, flags, params): global mousedown, mouseupdown, drawnBox, boxToDraw, initialize if event == cv2.EVENT_LBUTTONDOWN: drawnBox[[0,2]] = x drawnBox[[1,3]] = y mousedown = True mouseupdown = False elif mousedown and event == cv2.EVENT_MOUSEMOVE: drawnBox[2] = x drawnBox[3] = y elif event == cv2.EVENT_LBUTTONUP: drawnBox[2] = x drawnBox[3] = y mousedown = False mouseupdown = True initialize = True boxToDraw = drawnBox.copy() boxToDraw[[0,2]] = np.sort(boxToDraw[[0,2]]) boxToDraw[[1,3]] = np.sort(boxToDraw[[1,3]])
Example #10
Source File: object_tracker.py From OpenCV-3-x-with-Python-By-Example with MIT License | 7 votes |
def mouse_event(self, event, x, y, flags, param): x, y = np.int16([x, y]) # Detecting the mouse button down event if event == cv2.EVENT_LBUTTONDOWN: self.drag_start = (x, y) self.tracking_state = 0 if self.drag_start: if event == cv2.EVENT_MOUSEMOVE: h, w = self.frame.shape[:2] xo, yo = self.drag_start x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y])) x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y])) self.selection = None if x1-x0 > 0 and y1-y0 > 0: self.selection = (x0, y0, x1, y1) elif event == cv2.EVENT_LBUTTONUP: self.drag_start = None if self.selection is not None: self.tracking_state = 1 # Method to start tracking the object
Example #11
Source File: pose_estimation.py From OpenCV-3-x-with-Python-By-Example with MIT License | 7 votes |
def mouse_event(self, event, x, y, flags, param): x, y = np.int16([x, y]) # Detecting the mouse button down event if event == cv2.EVENT_LBUTTONDOWN: self.drag_start = (x, y) self.tracking_state = 0 if self.drag_start: if event == cv2.EVENT_MOUSEMOVE: h, w = param["frame"].shape[:2] xo, yo = self.drag_start x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y])) x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y])) self.selected_rect = None if x1-x0 > 0 and y1-y0 > 0: self.selected_rect = (x0, y0, x1, y1) elif event == cv2.EVENT_LBUTTONUP: self.drag_start = None if self.selected_rect is not None: self.callback_func(self.selected_rect) self.selected_rect = None self.tracking_state = 1
Example #12
Source File: 04_interacting_video.py From OpenCV-3-x-with-Python-By-Example with MIT License | 7 votes |
def draw_rectangle(event, x, y, flags, params): global x_init, y_init, drawing def update_pts(): params["top_left_pt"] = (min(x_init, x), min(y_init, y)) params["bottom_right_pt"] = (max(x_init, x), max(y_init, y)) img[y_init:y, x_init:x] = 255 - img[y_init:y, x_init:x] if event == cv2.EVENT_LBUTTONDOWN: drawing = True x_init, y_init = x, y elif event == cv2.EVENT_MOUSEMOVE and drawing: update_pts() elif event == cv2.EVENT_LBUTTONUP: drawing = False update_pts()
Example #13
Source File: opencv_draw.py From Python-Code with MIT License | 7 votes |
def draw_circle(event,x,y,flags,param): global ix,iy,drawing,mode if event == cv2.EVENT_LBUTTONDOWN: drawing = True ix,iy = x,y elif event == cv2.EVENT_MOUSEMOVE: if drawing == True: if mode == True: cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1) else: cv2.circle(img,(x,y),5,(0,0,255),-1) elif event == cv2.EVENT_LBUTTONUP: drawing = False if mode == True: cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1) else: cv2.circle(img,(x,y),5,(0,0,255),-1)
Example #14
Source File: drawer.py From Handwriting-Recognition with Apache License 2.0 | 7 votes |
def mouse_callback(self, event, x, y, flags, params): """ Callback method for drawing circles on an image """ # left mouse button is pressed if event == cv2.EVENT_LBUTTONDOWN: self.mouse_pressed = True # mouse pointer has moved over the window elif event == cv2.EVENT_MOUSEMOVE: if self.mouse_pressed: cv2.circle(img=self.img, center=(x, y), radius=20, color=self.char_color, thickness=-1) # left mouse button is released elif event == cv2.EVENT_LBUTTONUP: self.mouse_pressed = False cv2.circle(img=self.img, center=(x, y), radius=20, color=self.char_color, thickness=-1)
Example #15
Source File: py3_raspberry_pi.py From display_ocr with GNU General Public License v2.0 | 7 votes |
def draw_shape(event,x,y,flags,param): global ix,iy,drawing,mode,rectangle if event == cv2.EVENT_LBUTTONDOWN: drawing = True ix,iy = x,y elif event == cv2.EVENT_MOUSEMOVE: if drawing == True: rectangle = define_rectangle(iy, ix, y, x) elif event == cv2.EVENT_LBUTTONUP: drawing = False if not (ix == x and iy == y): rectangle = define_rectangle(iy, ix, y, x) # GUI INPUTS
Example #16
Source File: common.py From TecoGAN with Apache License 2.0 | 7 votes |
def on_mouse(self, event, x, y, flags, param): pt = (x, y) if event == cv.EVENT_LBUTTONDOWN: self.prev_pt = pt elif event == cv.EVENT_LBUTTONUP: self.prev_pt = None if self.prev_pt and flags & cv.EVENT_FLAG_LBUTTON: for dst, color in zip(self.dests, self.colors_func()): cv.line(dst, self.prev_pt, pt, color, 5) self.dirty = True self.prev_pt = pt self.show() # palette data from matplotlib/_cm.py
Example #17
Source File: common.py From CameraCalibration with GNU General Public License v3.0 | 7 votes |
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
Example #18
Source File: common.py From pi-tracking-telescope with MIT License | 7 votes |
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
Example #19
Source File: common.py From pi-tracking-telescope with MIT License | 7 votes |
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
Example #20
Source File: common.py From pi-tracking-telescope with MIT License | 7 votes |
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
Example #21
Source File: DrawShape.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 7 votes |
def drawShape(event, x, y, flags, params): global mode, drawing, xi, yi if event == cv2.EVENT_LBUTTONDOWN: drawing = True xi, yi = x, y elif event == cv2.EVENT_MOUSEMOVE: if drawing == True: if mode == True: cv2.rectangle(image, (xi, yi), (x, y), (0, 255, 0), -1) else: cv2.circle(image, (x, y), 5, (255, 0, 0), -1) elif event == cv2.EVENT_LBUTTONUP: drawing = False if mode == True: cv2.rectangle(image, (xi, yi), (x, y), (0, 255, 0), -1) else: cv2.circle(image, (x, y), 5, (255, 0, 0), -1)
Example #22
Source File: im_capture.py From machine_feeling with MIT License | 7 votes |
def click_and_crop(event, x, y, flags, param): global coors, is_clicked, loop # if the button is pressed if event == cv2.EVENT_LBUTTONDOWN and not is_clicked: coors.append((x, y)) is_clicked = True # if the button is released elif event == cv2.EVENT_LBUTTONUP and is_clicked: coors.append((x, y)) is_clicked = False # if we have two coordinates if len(coors) == 2 and not is_clicked: # take the selection and write it to file cv2.imwrite(filename + '.png', img[coors[0][1]:coors[1][1], coors[0][0]:coors[1][0]]) # stop looping loop = False
Example #23
Source File: webcam_demo.py From THOR with MIT License | 7 votes |
def on_mouse(event, x, y, flags, params): global mousedown, mouseupdown, drawnBox, boxToDraw, initialize, boxToDraw_xywh if event == cv2.EVENT_LBUTTONDOWN: drawnBox[[0,2]] = x drawnBox[[1,3]] = y mousedown = True mouseupdown = False elif mousedown and event == cv2.EVENT_MOUSEMOVE: drawnBox[2] = x drawnBox[3] = y elif event == cv2.EVENT_LBUTTONUP: drawnBox[2] = x drawnBox[3] = y mousedown = False mouseupdown = True initialize = True boxToDraw = drawnBox.copy() boxToDraw[[0, 2]] = np.sort(boxToDraw[[0, 2]]) boxToDraw[[1, 3]] = np.sort(boxToDraw[[1, 3]]) boxToDraw_xywh = xyxy_to_xywh(boxToDraw)
Example #24
Source File: draw.py From QuickDraw with MIT License | 7 votes |
def paint_draw(event, x, y, flags, param): global ix, iy, drawing, mode if event == cv2.EVENT_LBUTTONDOWN: drawing = True ix, iy = x, y elif event == cv2.EVENT_MOUSEMOVE: if drawing == True: cv2.line(image, (ix, iy), (x, y), (255, 255, 255), 5) ix = x iy = y elif event == cv2.EVENT_LBUTTONUP: drawing = False cv2.line(image, (ix, iy), (x, y), (255, 255, 255), 5) ix = x iy = y return x, y
Example #25
Source File: common.py From pi-tracking-telescope with MIT License | 6 votes |
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)
Example #26
Source File: pcrender.py From midlevel-reps with MIT License | 6 votes |
def _onmouse(self, *args): if args[0] == cv2.EVENT_LBUTTONDOWN: self.org_pitch, self.org_yaw, self.org_x, self.org_y, self.org_z =\ self.pitch,self.yaw,self.x,self.y,self.z self.clickstart = (self.mousex, self.mousey) if args[0] == cv2.EVENT_RBUTTONDOWN: self.org_roll = self.roll self.clickstart = (self.mousex, self.mousey) if (args[3] & cv2.EVENT_FLAG_LBUTTON): self.pitch = self.org_pitch + (self.mousex - self.clickstart[0])/10 self.yaw = self.org_yaw + (self.mousey - self.clickstart[1]) if (args[3] & cv2.EVENT_FLAG_RBUTTON): self.roll = self.org_roll + (self.mousex - self.clickstart[0])/50 my=args[1] mx=args[2] self.mousex=mx/float(256) self.mousey=my/float(256 * 2)
Example #27
Source File: common.py From pi-tracking-telescope with MIT License | 6 votes |
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)
Example #28
Source File: common.py From CameraCalibration with GNU General Public License v3.0 | 6 votes |
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)
Example #29
Source File: common.py From airtest with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #30
Source File: common.py From MachineLearning with Apache License 2.0 | 6 votes |
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)