本文整理汇总了Python中cv2.EVENT_LBUTTONDBLCLK属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.EVENT_LBUTTONDBLCLK属性的具体用法?Python cv2.EVENT_LBUTTONDBLCLK怎么用?Python cv2.EVENT_LBUTTONDBLCLK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.EVENT_LBUTTONDBLCLK属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: coords_mouse_disp
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
def coords_mouse_disp(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDBLCLK:
#print x,y,disp[y,x],filteredImg[y,x]
average=0
for u in range (-1,2):
for v in range (-1,2):
average += disp[y+u,x+v]
average=average/9
Distance= -593.97*average**(3) + 1506.8*average**(2) - 1373.1*average + 522.06
Distance= np.around(Distance*0.01,decimals=2)
print('Distance: '+ str(Distance)+' m')
# This section has to be uncommented if you want to take mesurements and store them in the excel
## ws.append([counterdist, average])
## print('Measure at '+str(counterdist)+' cm, the dispasrity is ' + str(average))
## if (counterdist <= 85):
## counterdist += 3
## elif(counterdist <= 120):
## counterdist += 5
## else:
## counterdist += 10
## print('Next distance to measure: '+str(counterdist)+'cm')
# Mouseclick callback
示例2: draw_circle
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
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():
示例3: draw_circle
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
def draw_circle(event, x, y, flags, param): # 只用做一件事:在双击过的地方绘 制一个圆圈。
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(img, (x, y), 100, (255, 0, 0), -1)
# 创建图像与窗口并将窗口与回调函数绑定
示例4: on_mouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
def on_mouse(self, event, x, y, flag, param):
if event == cv2.EVENT_LBUTTONDBLCLK:
# Circle to indicate hsv location, and update frame
cv2.circle(self.img_debug, (x, y), 3, (0, 0, 255))
cv2.imshow('hsv_extractor', self.img_debug)
# Print values
values = self.hsv_frame[y, x]
print('H:', values[0], '\tS:', values[1], '\tV:', values[2])
示例5: captures
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
def captures(event, x, y, flags, params):
global countClicks, coordinates, image
if countClicks < 4:
if event == cv2.EVENT_LBUTTONDBLCLK:
countClicks = countClicks + 1
coordinates = np.append(coordinates, np.float32([x, y]), axis=0)
cv2.circle(image, (x, y), 5, (0, 0, 255), -1)
示例6: draw_circle
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [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
示例7: click_gripper
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
def click_gripper(event, x, y, flags, param):
global clicked_pt
if event == cv2.EVENT_LBUTTONDBLCLK:
clicked_pt = np.array([x,y])
logging.info('Clicked: {}'.format(clicked_pt))
示例8: define_new_pose_configuration
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [as 别名]
def define_new_pose_configuration(configName, noAnimals, noBps, Imagepath, BpNameList, animalNumber):
global ix, iy
global centerCordStatus
def draw_circle(event,x,y,flags,param):
global ix,iy
global centerCordStatus
if (event == cv2.EVENT_LBUTTONDBLCLK):
if centerCordStatus == False:
cv2.circle(overlay,(x,y-sideImageHeight),10,colorList[-i],-1)
cv2.putText(overlay,str(bpNumber+1), (x+4,y-sideImageHeight), cv2.FONT_HERSHEY_SIMPLEX, 0.7, colorList[i], 2)
cv2.imshow('Define pose', overlay)
centerCordStatus = True
im = cv2.imread(Imagepath)
imHeight, imWidth = im.shape[0], im.shape[1]
if imWidth < 300:
im = imutils.resize(im, width=800)
imHeight, imWidth = im.shape[0], im.shape[1]
im = np.uint8(im)
fontScale = max(imWidth, imHeight) / (max(imWidth, imHeight) * 1.2)
cv2.namedWindow('Define pose', cv2.WINDOW_NORMAL)
overlay = im.copy()
colorList = []
for color in range(len(BpNameList)):
r, g, b = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
colorTuple = (r, g, b)
colorList.append(colorTuple)
for i in range(len(BpNameList)):
cv2.namedWindow('Define pose', cv2.WINDOW_NORMAL)
centerCordStatus = False
bpNumber = i
sideImage = np.zeros((100, imWidth, 3), np.uint8)
sideImageHeight, sideImageWidth = sideImage.shape[0], sideImage.shape[1]
cv2.putText(sideImage, 'Double left click ' + BpNameList[i] + '. Press ESC to continue.', (10, 50), cv2.FONT_HERSHEY_SIMPLEX, fontScale, colorList[i], 2)
ix, iy = -1, -1
while (1):
cv2.setMouseCallback('Define pose', draw_circle)
imageConcat = cv2.vconcat([sideImage, overlay])
cv2.imshow('Define pose', imageConcat)
k = cv2.waitKey(20) & 0xFF
if k == 27:
cv2.destroyWindow('Define pose')
break
overlay = cv2.resize(overlay, (250,300))
imagePath = os.path.join(os.getcwd(), 'pose_configurations', 'schematics')
namePath = os.path.join(os.getcwd(), 'pose_configurations', 'configuration_names', 'pose_config_names.csv')
bpPath = os.path.join(os.getcwd(), 'pose_configurations', 'bp_names', 'bp_names.csv')
noAnimalsPath = os.path.join(os.getcwd(), 'pose_configurations', 'no_animals', 'no_animals.csv')
imageNos = len(glob.glob(imagePath + '/*.png'))
newImageName = 'Picture' + str(imageNos+1) + '.png'
imageOutPath = os.path.join(imagePath, newImageName)
BpNameList = ','.join(BpNameList)
with open(namePath, 'a') as fd:
fd.write(configName + '\n')
with open(bpPath, 'a') as fd:
fd.write(BpNameList + '\n')
with open(noAnimalsPath, 'a') as fd:
fd.write(animalNumber + '\n')
cv2.imwrite(imageOutPath, overlay)
示例9: mouse_listener
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import EVENT_LBUTTONDBLCLK [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)