本文整理匯總了Python中cv2.EVENT_LBUTTONDOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.EVENT_LBUTTONDOWN屬性的具體用法?Python cv2.EVENT_LBUTTONDOWN怎麽用?Python cv2.EVENT_LBUTTONDOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.EVENT_LBUTTONDOWN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: pick_color
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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)
示例2: on_mouse
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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)
示例3: on_mouse
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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
示例4: _callBack
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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
# 描畫用の空畫像作成
示例5: draw_rectangle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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
示例6: onmouse
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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)
示例7: on_mouse
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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]])
示例8: mouseclick_callback
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
def mouseclick_callback(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
global camera, robot, click_point_pix
click_point_pix = (x,y)
# Get click point in camera coordinates
click_z = camera_depth_img[y][x] * robot.cam_depth_scale
click_x = np.multiply(x-robot.cam_intrinsics[0][2],click_z/robot.cam_intrinsics[0][0])
click_y = np.multiply(y-robot.cam_intrinsics[1][2],click_z/robot.cam_intrinsics[1][1])
if click_z == 0:
return
click_point = np.asarray([click_x,click_y,click_z])
click_point.shape = (3,1)
# Convert camera to robot coordinates
# camera2robot = np.linalg.inv(robot.cam_pose)
camera2robot = robot.cam_pose
target_position = np.dot(camera2robot[0:3,0:3],click_point) + camera2robot[0:3,3:]
target_position = target_position[0:3,0]
print(target_position)
robot.move_to(target_position, tool_orientation)
# Show color and depth frames
示例9: mouse_event
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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
示例10: mouse_event
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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
示例11: draw_rectangle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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()
示例12: detect_quadrant
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
def detect_quadrant(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
if x > width/2:
if y > height/2:
point_top_left = (int(width/2), int(height/2))
point_bottom_right = (width-1, height-1)
else:
point_top_left = (int(width/2), 0)
point_bottom_right = (width-1, int(height/2))
else:
if y > height/2:
point_top_left = (0, int(height/2))
point_bottom_right = (int(width/2), height-1)
else:
point_top_left = (0, 0)
point_bottom_right = (int(width/2), int(height/2))
img = param["img"]
# Repaint all in white again
cv2.rectangle(img, (0,0), (width-1,height-1), (255,255,255), -1)
# Paint green quadrant
cv2.rectangle(img, point_top_left, point_bottom_right, (0,100,0), -1)
示例13: draw_line
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
def draw_line(event, x ,y ,flags, params):
lp1,lp2 = params[0],params[1]
thermal_image = params[2]
if len(lp1)<=2 and len(lp2) <2:
if event == cv.EVENT_LBUTTONDOWN:
CFlir.line_flag = not(CFlir.line_flag)
if CFlir.line_flag == True:
lp1.append(x)
lp1.append(y)
else:
lp2.append(x)
lp2.append(y)
lp1 = tuple(lp1)
lp2 = tuple(lp2)
cv.line(thermal_image, lp1, lp2, (0,0,0), 2, 8 )
示例14: draw_circle
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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)
示例15: onmouse
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_LBUTTONDOWN [as 別名]
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)