本文整理汇总了Python中cv2.setMouseCallback方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.setMouseCallback方法的具体用法?Python cv2.setMouseCallback怎么用?Python cv2.setMouseCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.setMouseCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def __init__(self):
# Initialize the video capture object
# 0 -> indicates that frame should be captured
# from webcam
self.cap = cv2.VideoCapture(0)
# Capture the frame from the webcam
ret, self.frame = self.cap.read()
# Downsampling factor for the input frame
self.scaling_factor = 0.8
self.frame = cv2.resize(self.frame, None, fx=self.scaling_factor, fy=self.scaling_factor, interpolation=cv2.INTER_AREA)
cv2.namedWindow('Object Tracker')
cv2.setMouseCallback('Object Tracker', self.mouse_event)
self.selection = None
self.drag_start = None
self.tracking_state = 0
# Method to track mouse events
示例2: draw
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def draw(self):
"""
Method to draw continuous multiple circles on an image. Like a paint brush.
"""
self.reset()
window_name = 'Draw character'
cv2.namedWindow(winname=window_name)
cv2.setMouseCallback(window_name=window_name, on_mouse=self.mouse_callback)
# continue till ESC key is pressed
while True:
cv2.imshow(winname=window_name, mat=self.img)
# ESC key pressed
k = cv2.waitKey(delay=1) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
示例3: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def main():
"""Test code"""
global mp
mp = np.array((2, 1), np.float32) # measurement
def onmouse(k, x, y, s, p):
global mp
mp = np.array([[np.float32(x)], [np.float32(y)]])
cv2.namedWindow("kalman")
cv2.setMouseCallback("kalman", onmouse)
kalman = Stabilizer(4, 2)
frame = np.zeros((480, 640, 3), np.uint8) # drawing canvas
while True:
kalman.update(mp)
point = kalman.prediction
state = kalman.filter.statePost
cv2.circle(frame, (state[0], state[1]), 2, (255, 0, 0), -1)
cv2.circle(frame, (point[0], point[1]), 2, (0, 255, 0), -1)
cv2.imshow("kalman", frame)
k = cv2.waitKey(30) & 0xFF
if k == 27:
break
示例4: pick_corrs
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def pick_corrs(images, n_pts_to_pick=4):
data = [ [[], 0, False, False, False, image, "Image %d" % i, n_pts_to_pick]
for i, image in enumerate(images)]
for d in data:
win_name = d[6]
cv2.namedWindow(win_name)
cv2.setMouseCallback(win_name, corr_picker_callback, d)
cv2.startWindowThread()
cv2.imshow(win_name, d[5])
key = None
while key != '\n' and key != '\r' and key != 'q':
key = cv2.waitKey(33)
key = chr(key & 255) if key >= 0 else None
cv2.destroyAllWindows()
if key == 'q':
return None
else:
return [d[0] for d in data]
示例5: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def main():
global image_hsv, pixel
#OPEN DIALOG FOR READING THE IMAGE FILE
root = tk.Tk()
root.withdraw() #HIDE THE TKINTER GUI
file_path = filedialog.askopenfilename(filetypes = ftypes)
root.update()
image_src = cv2.imread(file_path)
cv2.imshow("BGR",image_src)
#CREATE THE HSV FROM THE BGR IMAGE
image_hsv = cv2.cvtColor(image_src,cv2.COLOR_BGR2HSV)
cv2.imshow("HSV",image_hsv)
#CALLBACK FUNCTION
cv2.setMouseCallback("HSV", pick_color)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例6: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def __init__(self, window_name = "", world_path=""):
if not Config.linux_env:
cv2.namedWindow(window_name)
cv2.setMouseCallback(window_name, GUI.mouse_listener)
self.world = World(world_path = world_path)
if os.path.exists(self.world.save_path):
self.world.load_world()
self.camera = self.world.get_camera_from_actors()
print ("World loaded")
else:
self.camera = Camera()
self.world.actors.append(self.camera)
print ("Warning, world not loaded, creating a new one")
self.pressed_key = None
self.display_image = np.zeros((Config.r_res[0], Config.r_res[1], 3), np.uint8)
self.window_name = window_name
self.running = True
self.time_step = 33
示例7: on_capture_mouse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [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) )
示例8: run
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def run(self):
""" Run the program.
Runs the program by continually calling for hotkeys function
defined in the subclasses.
"""
cv2.namedWindow(self.window_name)
cv2.setMouseCallback(self.window_name, _mouse_click, self)
self._update_canvas()
while True:
self.key = cv2.waitKey(self.refresh) & 0xFF
self._hotkeys()
if self._exit():
break
cv2.destroyAllWindows()
cv2.waitKey(1)
示例9: handle_click
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def handle_click(event, x, y, flags, params):
"""
Records clicks on the image and lets the user choose one of the detected
faces by simply pointing and clicking.
params:
(As needed by setMouseCallback)
event: The event that occured
x, y: Integers. Coordinates of the event
flags: Any flags reported by setMouseCallback
params: Any params returned by setMouseCallback
"""
# Capture when the LClick is released
if event == cv2.EVENT_LBUTTONUP and y > a // 2: # Ignore clicks on padding
response = x // (faces_copy.shape[1] // len(faces))
cv2.destroyAllWindows()
cv2.imwrite('_search_.png', faces[response])
try:
Search()
except KeyboardInterrupt: # Delete the generated image if user stops
print("\nTerminated execution. Cleaning up...") # the execution.
os.remove('_search_.png')
sys.exit()
# The path to the face detection Haar cascade. Specified in the install.sh file
示例10: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def __init__(self, windowname, dests, colors_func):
self.prev_pt = None
self.windowname = windowname
self.dests = dests
self.colors_func = colors_func
self.dirty = False
self.show()
cv2.setMouseCallback(self.windowname, self.on_mouse)
示例11: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def __init__(self, video_src):
self.cam = video.create_capture(video_src, presets['cube'])
ret, self.frame = self.cam.read()
cv2.namedWindow('camshift')
cv2.setMouseCallback('camshift', self.onmouse)
self.selection = None
self.drag_start = None
self.show_backproj = False
self.track_window = None
示例12: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def main():
global image
cv2.namedWindow("Input")
cv2.setMouseCallback("Input", click)
output = np.ones((512, 512, 1))
font = cv2.FONT_HERSHEY_SIMPLEX
bottomLeftCornerOfText = (1, 511)
fontScale = 23
fontColor = (0, 0, 0)
lineType = 2
while True:
cv2.imshow("Input", image)
cv2.imshow("Output", output)
key = cv2.waitKey(1) & 0xFF
if key == ord("f"):
cv2.destroyAllWindows()
break
if key == ord("r"):
image = np.ones((640, 640, 1))
if key == ord("p"):
clone = image.copy()
clone = cv2.resize(clone, (32,32))
final = np.zeros((32, 32, 1))
for x in range(len(clone)):
for y in range(len(clone[x])):
final[x][y][0] = clone[x][y]
pred = p.predict(final)
print("Predicted " , pred)
output = np.ones((512, 512, 1))
cv2.putText(output, pred, (10, 500), font, fontScale, fontColor, 10, 2)
示例13: setCallBack
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def setCallBack(self, win_name):
cv2.setMouseCallback(win_name, self._callBack)
示例14: BB_init
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def BB_init(self):
# use HOG method to initialize bounding box
self.hog = cv2.HOGDescriptor()
self.hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
self._box_init_window_name = 'Bounding Box Initialization'
cv2.namedWindow(self._box_init_window_name)
cv2.setMouseCallback(self._box_init_window_name, self._on_mouse)
示例15: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import setMouseCallback [as 别名]
def __init__(self):
print('Initializing HOGBox...')
self.hog = cv2.HOGDescriptor()
self.hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
self._box_init_window_name = 'Click mouse to initialize bounding box'
cv2.namedWindow(self._box_init_window_name)
cv2.setMouseCallback(self._box_init_window_name, self.on_mouse)
print('HOGBox initialized.')