本文整理汇总了Python中cv2.EVENT_RBUTTONUP属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.EVENT_RBUTTONUP属性的具体用法?Python cv2.EVENT_RBUTTONUP怎么用?Python cv2.EVENT_RBUTTONUP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.EVENT_RBUTTONUP属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_capture_mouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [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) )
示例2: _mouse_ops
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [as 别名]
def _mouse_ops(self, event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
self._drawing = True
self._pt0 = (x, y)
elif event == cv2.EVENT_LBUTTONUP:
self._drawing = False
self._pt1 = (x, y)
self._bboxes.append((self._cur_label, (self._pt0, self._pt1)))
elif event == cv2.EVENT_MOUSEMOVE:
self._pt1 = (x, y)
elif event == cv2.EVENT_RBUTTONUP:
if self._bboxes:
self._bboxes.pop()
示例3: drawFloorCrop
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [as 别名]
def drawFloorCrop(event, x, y, flags, params):
global perspectiveMatrix, name, RENEW_TETRAGON
imgCroppingPolygon = np.zeros_like(params['imgFloorCorners'])
if event == cv2.EVENT_RBUTTONUP:
cv2.destroyWindow(f'Floor Corners for {name}')
if len(params['croppingPolygons'][name]) > 4 and event == cv2.EVENT_LBUTTONUP:
RENEW_TETRAGON = True
h = params['imgFloorCorners'].shape[0]
# delete 5th extra vertex of the floor cropping tetragon
params['croppingPolygons'][name] = np.delete(params['croppingPolygons'][name], -1, 0)
params['croppingPolygons'][name] = params['croppingPolygons'][name] - [h,0]
# Sort cropping tetragon vertices counter-clockwise starting with top left
params['croppingPolygons'][name] = counterclockwiseSort(params['croppingPolygons'][name])
# Get the matrix of perspective transformation
params['croppingPolygons'][name] = np.reshape(params['croppingPolygons'][name], (4,2))
tetragonVertices = np.float32(params['croppingPolygons'][name])
tetragonVerticesUpd = np.float32([[0,0], [0,h], [h,h], [h,0]])
perspectiveMatrix[name] = cv2.getPerspectiveTransform(tetragonVertices, tetragonVerticesUpd)
if event == cv2.EVENT_LBUTTONDOWN:
if len(params['croppingPolygons'][name]) == 4 and RENEW_TETRAGON:
params['croppingPolygons'][name] = np.array([[0,0]])
RENEW_TETRAGON = False
if len(params['croppingPolygons'][name]) == 1:
params['croppingPolygons'][name][0] = [x,y]
params['croppingPolygons'][name] = np.append(params['croppingPolygons'][name], [[x,y]], axis=0)
if event == cv2.EVENT_MOUSEMOVE and not (len(params['croppingPolygons'][name]) == 4 and RENEW_TETRAGON):
params['croppingPolygons'][name][-1] = [x,y]
if len(params['croppingPolygons'][name]) > 1:
cv2.fillPoly(
imgCroppingPolygon,
[np.reshape(
params['croppingPolygons'][name],
(len(params['croppingPolygons'][name]),2)
)],
BGR_COLOR['green'], cv2.LINE_AA)
imgCroppingPolygon = cv2.addWeighted(params['imgFloorCorners'], 1.0, imgCroppingPolygon, 0.5, 0.)
cv2.imshow(f'Floor Corners for {name}', imgCroppingPolygon)
示例4: do_draw
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [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)
示例5: position
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [as 别名]
def position(event, x, y, flags, param):
global pos
if event == cv2.EVENT_LBUTTONUP or event == cv2.EVENT_RBUTTONUP:
pos = (x, y)
示例6: click
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [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
示例7: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [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)
示例8: interactive_imshow
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [as 别名]
def interactive_imshow(img, lclick_cb=None, rclick_cb=None, **kwargs):
"""
Args:
img (np.ndarray): an image (expect BGR) to show.
lclick_cb, rclick_cb: a callback ``func(img, x, y)`` for left/right click event.
kwargs: can be {key_cb_a: callback_img, key_cb_b: callback_img}, to
specify a callback ``func(img)`` for keypress.
Some existing keypress event handler:
* q: destroy the current window
* x: execute ``sys.exit()``
* s: save image to "out.png"
"""
name = 'tensorpack_viz_window'
cv2.imshow(name, img)
def mouse_cb(event, x, y, *args):
if event == cv2.EVENT_LBUTTONUP and lclick_cb is not None:
lclick_cb(img, x, y)
elif event == cv2.EVENT_RBUTTONUP and rclick_cb is not None:
rclick_cb(img, x, y)
cv2.setMouseCallback(name, mouse_cb)
key = cv2.waitKey(-1)
while key >= 128:
key = cv2.waitKey(-1)
key = chr(key & 0xff)
cb_name = 'key_cb_' + key
if cb_name in kwargs:
kwargs[cb_name](img)
elif key == 'q':
cv2.destroyWindow(name)
elif key == 'x':
sys.exit()
elif key == 's':
cv2.imwrite('out.png', img)
elif key in ['+', '=']:
img = cv2.resize(img, None, fx=1.3, fy=1.3, interpolation=cv2.INTER_CUBIC)
interactive_imshow(img, lclick_cb, rclick_cb, **kwargs)
elif key == '-':
img = cv2.resize(img, None, fx=0.7, fy=0.7, interpolation=cv2.INTER_CUBIC)
interactive_imshow(img, lclick_cb, rclick_cb, **kwargs)
示例9: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [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
示例10: onmouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_RBUTTONUP [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)
# print documentation