本文整理汇总了Python中cv2.EVENT_RBUTTONDOWN属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.EVENT_RBUTTONDOWN属性的具体用法?Python cv2.EVENT_RBUTTONDOWN怎么用?Python cv2.EVENT_RBUTTONDOWN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.EVENT_RBUTTONDOWN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
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)
示例2: on_capture_mouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
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) )
示例3: onMouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def onMouse(self, event, x, y, flags, data):
if event == cv2.EVENT_LBUTTONDOWN or event == cv2.EVENT_RBUTTONDOWN:
if event == cv2.EVENT_LBUTTONDOWN:
increment = 1
else:
increment = -1
self.colorSpaceIdx = (
(self.colorSpaceIdx + increment) % len(self.COLOR_SPACES))
self.updateButton()
# Threshold image on color space change only in image
# mode. If video or cam mode, the while loop in start()
# handles this.
if self.mode == "image":
self.thresholdImage()
示例4: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def onmouse(event, x, y, flags, param):
global selected_cell
if event == cv2.EVENT_LBUTTONDOWN:
# show region detail
key = model.find_key(int(x/args.scale), int(y/args.scale))
selected_cell = key
(r1, r2, c1, c2) = model.cells[key]["region"]
rgb_region = rgb[r1:r2,c1:c2]
cv2.imshow('region', cv2.resize(rgb_region, ( (r2-r1)*3, (c2-c1)*3) ))
scale = draw_prediction(scale_orig, model.cells,
selected_cell, show_mode)
cv2.imshow(win, scale)
elif event == cv2.EVENT_RBUTTONDOWN:
key = model.find_key(int(x/args.scale), int(y/args.scale))
#if cells[key]["user"] == None:
# cells[key]["user"] = "yes"
#elif cells[key]["user"] == "yes":
# cells[key]["user"] = "no"
#else:
# cells[key]["user"] = None
scale = draw_prediction(scale_orig, model.cells,
selected_cell, show_mode)
cv2.imshow(win, scale)
示例5: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def onmouse(event, x, y, flags, param):
global selected_cell
if event == cv2.EVENT_LBUTTONDOWN:
# show region detail
key = tmodel.find_key(int(x/args.scale), int(y/args.scale))
selected_cell = key
(r1, r2, c1, c2) = tmodel.cells[key]["region"]
rgb_region = rgb[r1:r2,c1:c2]
cv2.imshow('region', cv2.resize(rgb_region, ( (r2-r1)*3, (c2-c1)*3) ))
scale = draw_prediction(scale_orig, tmodel.cells, cmodel.cells,
selected_cell, show_mode)
cv2.imshow(win, scale)
elif event == cv2.EVENT_RBUTTONDOWN:
key = tmodel.find_key(int(x/args.scale), int(y/args.scale))
#if cells[key]["user"] == None:
# cells[key]["user"] = "yes"
#elif cells[key]["user"] == "yes":
# cells[key]["user"] = "no"
#else:
# cells[key]["user"] = None
scale = draw_prediction(scale_orig, tmodel.cells, cmodel.cells,
selected_cell, show_mode)
cv2.imshow(win, scale)
示例6: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def onmouse(event, x, y, flags, param):
global selected_cell
if event == cv2.EVENT_LBUTTONDOWN:
# show region detail
key = model.find_key(int(x/args.scale), int(y/args.scale))
selected_cell = key
(r1, r2, c1, c2) = model.cells[key]["region"]
rgb_region = rgb[r1:r2,c1:c2]
(max, avg, count, hue_dist) = model.cells[key]["score"]
print("max:", max, "avg:", avg, "count:", count, "hue dist:", hue_dist)
cv2.imshow('region', cv2.resize(rgb_region, ( (r2-r1)*3, (c2-c1)*3) ))
scale = draw_prediction(scale_orig, model.cells,
selected_cell, show_mode)
cv2.imshow(win, scale)
elif event == cv2.EVENT_RBUTTONDOWN:
key = model.find_key(int(x/args.scale), int(y/args.scale))
scale = draw_prediction(scale_orig, model.cells,
selected_cell, show_mode)
cv2.imshow(win, scale)
示例7: click_event
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def click_event(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
print(x, y)
if event == cv2.EVENT_RBUTTONDOWN:
red = img[y, x, 2]
blue = img[y, x, 0]
green = img[y, x, 1]
print(red, green, blue)
strRGB = str(red) + "," + str(green) + "," + str(blue)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img, strRGB, (x, y), font, 1, (255, 255, 255), 2)
cv2.imshow('original', img)
示例8: draw_boundingbox
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def draw_boundingbox(self,event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
self.selectingObject = True
self.onTracking = False
self.ix, self.iy = x, y
self.cx, self.cy = x, y
print(self.ix,self.iy)
elif event == cv2.EVENT_MOUSEMOVE:
self.cx, self.cy = x, y
elif event == cv2.EVENT_LBUTTONUP:
self.selectingObject = False
if(abs(x-self.ix)>10 and abs(y-self.iy)>10):
self.w, self.h = abs(x - self.ix), abs(y - self.iy)
self.ix, self.iy = min(x, self.ix), min(y, self.iy)
self.initTracking = True
else:
self.onTracking = False
elif event == cv2.EVENT_RBUTTONDOWN:
self.onTracking = False
if(self.w>0):
self.ix, self.iy = x-self.w/2, y-self.h/2
self.initTracking = True
示例9: do_draw
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def do_draw(self, event, x, y, flags, param):
draw_vals = {1: 100, 2: 0}
if event == cv2.EVENT_LBUTTONUP or event == cv2.EVENT_RBUTTONUP:
self.drawing = 0
elif event == cv2.EVENT_LBUTTONDOWN:
self.drawing = 1
elif event == cv2.EVENT_RBUTTONDOWN:
self.drawing = 2
elif self.drawing != 0:
cv2.circle(self.img, (x, y), 5, draw_vals[self.drawing], -1)
示例10: draw_boundingbox
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def draw_boundingbox(event, x, y, flags, param):
global selectingObject, initTracking, onTracking, ix, iy, cx,cy, w, h
if event == cv2.EVENT_LBUTTONDOWN:
selectingObject = True
onTracking = False
ix, iy = x, y
cx, cy = x, y
elif event == cv2.EVENT_MOUSEMOVE:
cx, cy = x, y
elif event == cv2.EVENT_LBUTTONUP:
selectingObject = False
if(abs(x-ix)>10 and abs(y-iy)>10):
w, h = abs(x - ix), abs(y - iy)
ix, iy = min(x, ix), min(y, iy)
initTracking = True
else:
onTracking = False
elif event == cv2.EVENT_RBUTTONDOWN:
onTracking = False
if(w>0):
ix, iy = x-w/2, y-h/2
initTracking = True
示例11: click
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def click(event, x, y, flags, param):
global clicks, l_down, r_down
if event == cv2.EVENT_LBUTTONDOWN or (event == cv2.EVENT_MOUSEMOVE and l_down):
l_down = True
x = max(0, min(x, WIDTH-1))
y = max(0, min(y, HEIGHT-1))
r = y // KERNEL
c = x // KERNEL
grid[r][c] = 1
elif event == cv2.EVENT_LBUTTONUP:
l_down = False
if event == cv2.EVENT_RBUTTONDOWN or (event == cv2.EVENT_MOUSEMOVE and r_down):
r_down = True
r = y // KERNEL
c = x // KERNEL
grid[r][c] = 0
elif event == cv2.EVENT_RBUTTONUP:
r_down = False
示例12: draw_circle
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def draw_circle(event, x, y, flags, param):
"""Mouse callback function"""
global circles
if event == cv2.EVENT_LBUTTONDBLCLK:
# Add the circle with coordinates x,y
print("event: EVENT_LBUTTONDBLCLK")
circles.append((x, y))
if event == cv2.EVENT_RBUTTONDBLCLK:
# Delete all circles (clean the screen)
print("event: EVENT_RBUTTONDBLCLK")
circles[:] = []
elif event == cv2.EVENT_RBUTTONDOWN:
# Delete last added circle
print("event: EVENT_RBUTTONDOWN")
try:
circles.pop()
except (IndexError):
print("no circles to delete")
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")
# Structure to hold the created circles:
开发者ID:PacktPublishing,项目名称:Mastering-OpenCV-4-with-Python,代码行数:30,代码来源:mouse_drawing_circles_and_text.py
示例13: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def onmouse(event,x,y,flags,param):
global img,img2,drawing,value,mask,rectangle,rect,rect_or_mask,ix,iy,rect_over
# Draw Rectangle
if event == cv2.EVENT_RBUTTONDOWN:
rectangle = True
ix,iy = x,y
elif event == cv2.EVENT_MOUSEMOVE:
if rectangle == True:
img = img2.copy()
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
rect = (min(ix,x),min(iy,y),abs(ix-x),abs(iy-y))
rect_or_mask = 0
elif event == cv2.EVENT_RBUTTONUP:
rectangle = False
rect_over = True
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
rect = (min(ix,x),min(iy,y),abs(ix-x),abs(iy-y))
rect_or_mask = 0
print(" Now press the key 'n' a few times until no further change \n")
# draw touchup curves
if event == cv2.EVENT_LBUTTONDOWN:
if rect_over == False:
print("first draw rectangle \n")
else:
drawing = True
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
elif event == cv2.EVENT_MOUSEMOVE:
if drawing == True:
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
elif event == cv2.EVENT_LBUTTONUP:
if drawing == True:
drawing = False
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
示例14: mouse_listener
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def mouse_listener(event, x, y, flags, param):
# mouse callback function
global is_bbox_selected, prev_was_double_click, mouse_x, mouse_y, point_1, point_2
set_class = True
if event == cv2.EVENT_MOUSEMOVE:
mouse_x = x
mouse_y = y
elif event == cv2.EVENT_LBUTTONDBLCLK:
prev_was_double_click = True
#print('Double click')
point_1 = (-1, -1)
# if clicked inside a bounding box we set that bbox
set_selected_bbox(set_class)
# By AlexeyGy: delete via right-click
elif event == cv2.EVENT_RBUTTONDOWN:
set_class = False
set_selected_bbox(set_class)
if is_bbox_selected:
obj_to_edit = img_objects[selected_bbox]
edit_bbox(obj_to_edit, 'delete')
is_bbox_selected = False
elif event == cv2.EVENT_LBUTTONDOWN:
if prev_was_double_click:
#print('Finish double click')
prev_was_double_click = False
else:
#print('Normal left click')
# Check if mouse inside on of resizing anchors of the selected bbox
if is_bbox_selected:
dragBBox.handler_left_mouse_down(x, y, img_objects[selected_bbox])
if dragBBox.anchor_being_dragged is None:
if point_1[0] == -1:
if is_bbox_selected:
if is_mouse_inside_delete_button():
set_selected_bbox(set_class)
obj_to_edit = img_objects[selected_bbox]
edit_bbox(obj_to_edit, 'delete')
is_bbox_selected = False
else:
# first click (start drawing a bounding box or delete an item)
point_1 = (x, y)
else:
# minimal size for bounding box to avoid errors
threshold = 5
if abs(x - point_1[0]) > threshold or abs(y - point_1[1]) > threshold:
# second click
point_2 = (x, y)
elif event == cv2.EVENT_LBUTTONUP:
if dragBBox.anchor_being_dragged is not None:
dragBBox.handler_left_mouse_up(x, y)
示例15: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONDOWN [as 别名]
def onmouse(event,x,y,flags,param):
global img,img2,drawing,value,mask,rectangle,rect,rect_or_mask,ix,iy,rect_over
# Draw Rectangle
if event == cv2.EVENT_RBUTTONDOWN:
rectangle = True
ix,iy = x,y
elif event == cv2.EVENT_MOUSEMOVE:
if rectangle == True:
img = img2.copy()
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
rect = (ix,iy,abs(ix-x),abs(iy-y))
rect_or_mask = 0
elif event == cv2.EVENT_RBUTTONUP:
rectangle = False
rect_over = True
cv2.rectangle(img,(ix,iy),(x,y),BLUE,2)
rect = (ix,iy,abs(ix-x),abs(iy-y))
rect_or_mask = 0
print " Now press the key 'n' a few times until no further change \n"
# draw touchup curves
if event == cv2.EVENT_LBUTTONDOWN:
if rect_over == False:
print "first draw rectangle \n"
else:
drawing = True
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
elif event == cv2.EVENT_MOUSEMOVE:
if drawing == True:
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
elif event == cv2.EVENT_LBUTTONUP:
if drawing == True:
drawing = False
cv2.circle(img,(x,y),thickness,value['color'],-1)
cv2.circle(mask,(x,y),thickness,value['val'],-1)
# print documentation