當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.setMouseCallback方法代碼示例

本文整理匯總了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 
開發者ID:PacktPublishing,項目名稱:OpenCV-3-x-with-Python-By-Example,代碼行數:23,代碼來源:object_tracker.py

示例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() 
開發者ID:samkit-jain,項目名稱:Handwriting-Recognition,代碼行數:24,代碼來源:drawer.py

示例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 
開發者ID:junhwanjang,項目名稱:face_landmark_dnn,代碼行數:26,代碼來源:kalman_filter.py

示例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] 
開發者ID:nelpy,項目名稱:nelpy,代碼行數:24,代碼來源:homography.py

示例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() 
開發者ID:alieldinayman,項目名稱:HSV-Color-Picker,代碼行數:23,代碼來源:HSV Color Picker.py

示例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 
開發者ID:Iftimie,項目名稱:ChauffeurNet,代碼行數:23,代碼來源:GUI.py

示例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) ) 
開發者ID:iperov,項目名稱:DeepFaceLab,代碼行數:21,代碼來源:interact.py

示例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) 
開發者ID:jgraving,項目名稱:DeepPoseKit,代碼行數:19,代碼來源:GUI.py

示例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 
開發者ID:HoussemCharf,項目名稱:FunUtils,代碼行數:28,代碼來源:facesearch.py

示例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) 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:10,代碼來源:common.py

示例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 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:12,代碼來源:camshift.py

示例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) 
開發者ID:frereit,項目名稱:TensorflowHandwritingRecognition,代碼行數:32,代碼來源:demo.py

示例13: setCallBack

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import setMouseCallback [as 別名]
def setCallBack(self, win_name):
        cv2.setMouseCallback(win_name, self._callBack) 
開發者ID:tody411,項目名稱:PyIntroduction,代碼行數:4,代碼來源:mouse_painting.py

示例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) 
開發者ID:XinArkh,項目名稱:VNect,代碼行數:10,代碼來源:benchmark.py

示例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.') 
開發者ID:XinArkh,項目名稱:VNect,代碼行數:10,代碼來源:hog_box.py


注:本文中的cv2.setMouseCallback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。