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


Python cv2.EVENT_MOUSEMOVE屬性代碼示例

本文整理匯總了Python中cv2.EVENT_MOUSEMOVE屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.EVENT_MOUSEMOVE屬性的具體用法?Python cv2.EVENT_MOUSEMOVE怎麽用?Python cv2.EVENT_MOUSEMOVE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.EVENT_MOUSEMOVE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw_rectangle

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def draw_rectangle(event, x, y, flags, param):
        global start_x, start_y, end_x, end_y, drawing, expected_value
        if event == cv2.EVENT_LBUTTONDOWN:
            # menu position
            if y < 40:
                # menu map
                if x > 8 and x < 148:
                    SaveImage(event)
                if x > 153 and x < 190:
                    OnClose(event)
                if x > 195 and x < 252:
                    print "OpenSource Development: https://github.com/arturaugusto/display_ocr.\nBased on examples availables at https://code.google.com/p/python-tesseract/.\nGPLv2 License"
            else:
                drawing = True
                start_x, start_y = x, y
                end_x, end_y = x, y
        elif event == cv2.EVENT_LBUTTONUP:
            drawing = False
            #start_x,start_y = -1,-1
            #end_x,end_y = -1,-1
        elif event == cv2.EVENT_MOUSEMOVE and drawing:
            if y < 40:
                end_x, end_y = x, 41
            else:
                end_x, end_y = x, y 
開發者ID:arturaugusto,項目名稱:display_ocr,代碼行數:27,代碼來源:OCR.py

示例2: _callBack

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def _callBack(self, event, x, y, flags, param):
        # マウス左ボタンが押された時の処理
        if event == cv2.EVENT_LBUTTONDOWN:
            self._doEvent(self._press_func, x, y)
            self._is_drag = True

        # マウス左ドラッグ時の処理
        elif event == cv2.EVENT_MOUSEMOVE:
            if self._is_drag:
                self._doEvent(self._drag_func, x, y)

        # マウス左ボタンが離された時の処理
        elif event == cv2.EVENT_LBUTTONUP:
            self._doEvent(self._release_func, x, y)
            self._is_drag = False


# 描畫用の空畫像作成 
開發者ID:tody411,項目名稱:PyIntroduction,代碼行數:20,代碼來源:mouse_painting.py

示例3: on_mouse

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def on_mouse(event, x, y, flags, params):
    global mousedown, mouseupdown, drawnBox, boxToDraw, initialize
    if event == cv2.EVENT_LBUTTONDOWN:
        drawnBox[[0,2]] = x
        drawnBox[[1,3]] = y
        mousedown = True
        mouseupdown = False
    elif mousedown and event == cv2.EVENT_MOUSEMOVE:
        drawnBox[2] = x
        drawnBox[3] = y
    elif event == cv2.EVENT_LBUTTONUP:
        drawnBox[2] = x
        drawnBox[3] = y
        mousedown = False
        mouseupdown = True
        initialize = True
    boxToDraw = drawnBox.copy()
    boxToDraw[[0,2]] = np.sort(boxToDraw[[0,2]])
    boxToDraw[[1,3]] = np.sort(boxToDraw[[1,3]]) 
開發者ID:moorejee,項目名稱:Re3,代碼行數:21,代碼來源:webcam_demo.py

示例4: mouse_event

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def mouse_event(self, event, x, y, flags, param): 
        x, y = np.int16([x, y]) 
 
        # Detecting the mouse button down event 
        if event == cv2.EVENT_LBUTTONDOWN: 
            self.drag_start = (x, y) 
            self.tracking_state = 0 
 
        if self.drag_start:
            if event == cv2.EVENT_MOUSEMOVE:
                h, w = self.frame.shape[:2] 
                xo, yo = self.drag_start 
                x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y]))               
                x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y])) 
                self.selection = None 
 
                if x1-x0 > 0 and y1-y0 > 0:
                    self.selection = (x0, y0, x1, y1) 
 
            elif event == cv2.EVENT_LBUTTONUP:
                self.drag_start = None 
                if self.selection is not None: 
                    self.tracking_state = 1 
 
    # Method to start tracking the object 
開發者ID:PacktPublishing,項目名稱:OpenCV-3-x-with-Python-By-Example,代碼行數:27,代碼來源:object_tracker.py

示例5: mouse_event

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def mouse_event(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) 
 
        # Detecting the mouse button down event 
        if event == cv2.EVENT_LBUTTONDOWN: 
            self.drag_start = (x, y) 
            self.tracking_state = 0 
 
        if self.drag_start:
            if event == cv2.EVENT_MOUSEMOVE:
                h, w = param["frame"].shape[:2] 
                xo, yo = self.drag_start 
                x0, y0 = np.maximum(0, np.minimum([xo, yo], [x, y]))               
                x1, y1 = np.minimum([w, h], np.maximum([xo, yo], [x, y])) 
                self.selected_rect = None 
 
                if x1-x0 > 0 and y1-y0 > 0:
                    self.selected_rect = (x0, y0, x1, y1) 
 
            elif event == cv2.EVENT_LBUTTONUP:
                self.drag_start = None 
                if self.selected_rect is not None: 
                    self.callback_func(self.selected_rect)
                    self.selected_rect = None
                    self.tracking_state = 1 
開發者ID:PacktPublishing,項目名稱:OpenCV-3-x-with-Python-By-Example,代碼行數:27,代碼來源:pose_estimation.py

示例6: draw_rectangle

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def draw_rectangle(event, x, y, flags, params): 
    global x_init, y_init, drawing
    def update_pts():
        params["top_left_pt"] = (min(x_init, x), min(y_init, y))
        params["bottom_right_pt"] = (max(x_init, x), max(y_init, y))
        img[y_init:y, x_init:x] = 255 - img[y_init:y, x_init:x]
    if event == cv2.EVENT_LBUTTONDOWN: 
        drawing = True 
        x_init, y_init = x, y 
 
    elif event == cv2.EVENT_MOUSEMOVE and drawing:
        update_pts() 
 
    elif event == cv2.EVENT_LBUTTONUP: 
        drawing = False 
        update_pts() 
開發者ID:PacktPublishing,項目名稱:OpenCV-3-x-with-Python-By-Example,代碼行數:18,代碼來源:04_interacting_video.py

示例7: draw_circle

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def draw_circle(event,x,y,flags,param):
    global ix,iy,drawing,mode

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix,iy = x,y

    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            if mode == True:
                cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1)
            else:
                cv2.circle(img,(x,y),5,(0,0,255),-1)

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if mode == True:
            cv2.rectangle(img,(ix,iy),(x,y),(0,255,0),-1)
        else:
            cv2.circle(img,(x,y),5,(0,0,255),-1) 
開發者ID:yzy1996,項目名稱:Python-Code,代碼行數:22,代碼來源:opencv_draw.py

示例8: paint_draw

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def paint_draw(event, x, y, flags, param):
    global ix, iy, drawing, mode
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix, iy = x, y
    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            cv2.line(image, (ix, iy), (x, y), (255, 255, 255), 5)
            ix = x
            iy = y
    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        cv2.line(image, (ix, iy), (x, y), (255, 255, 255), 5)
        ix = x
        iy = y
    return x, y 
開發者ID:uvipen,項目名稱:QuickDraw,代碼行數:18,代碼來源:draw.py

示例9: mouse_callback

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def mouse_callback(self, event, x, y, flags, params):
        """
        Callback method for drawing circles on an image
        """

        # left mouse button is pressed
        if event == cv2.EVENT_LBUTTONDOWN:
            self.mouse_pressed = True

        # mouse pointer has moved over the window
        elif event == cv2.EVENT_MOUSEMOVE:
            if self.mouse_pressed:
                cv2.circle(img=self.img, center=(x, y), radius=20, color=self.char_color, thickness=-1)

        # left mouse button is released
        elif event == cv2.EVENT_LBUTTONUP:
            self.mouse_pressed = False
            cv2.circle(img=self.img, center=(x, y), radius=20, color=self.char_color, thickness=-1) 
開發者ID:samkit-jain,項目名稱:Handwriting-Recognition,代碼行數:20,代碼來源:drawer.py

示例10: on_mouse

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def on_mouse(event, x, y, flags, params):
    global mousedown, mouseupdown, drawnBox, boxToDraw, initialize, boxToDraw_xywh
    if event == cv2.EVENT_LBUTTONDOWN:
        drawnBox[[0,2]] = x
        drawnBox[[1,3]] = y
        mousedown = True
        mouseupdown = False
    elif mousedown and event == cv2.EVENT_MOUSEMOVE:
        drawnBox[2] = x
        drawnBox[3] = y
    elif event == cv2.EVENT_LBUTTONUP:
        drawnBox[2] = x
        drawnBox[3] = y
        mousedown = False
        mouseupdown = True
        initialize = True
    boxToDraw = drawnBox.copy()
    boxToDraw[[0, 2]] = np.sort(boxToDraw[[0, 2]])
    boxToDraw[[1, 3]] = np.sort(boxToDraw[[1, 3]])
    boxToDraw_xywh = xyxy_to_xywh(boxToDraw) 
開發者ID:xl-sr,項目名稱:THOR,代碼行數:22,代碼來源:webcam_demo.py

示例11: drawShape

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def drawShape(event, x, y, flags, params):
    global mode, drawing, xi, yi

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        xi, yi = x, y

    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            if mode == True:
                cv2.rectangle(image, (xi, yi), (x, y), (0, 255, 0), -1)
            else:
                cv2.circle(image, (x, y), 5, (255, 0, 0), -1)

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if mode == True:
            cv2.rectangle(image, (xi, yi), (x, y), (0, 255, 0), -1)
        else:
            cv2.circle(image, (x, y), 5, (255, 0, 0), -1) 
開發者ID:amarlearning,項目名稱:Finger-Detection-and-Tracking,代碼行數:22,代碼來源:DrawShape.py

示例12: draw_circle

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [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(): 
開發者ID:PacktPublishing,項目名稱:Mastering-OpenCV-4-with-Python,代碼行數:19,代碼來源:mouse_drawing.py

示例13: _mouse_ops

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [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() 
開發者ID:frombeijingwithlove,項目名稱:dlcv_for_beginners,代碼行數:19,代碼來源:bbox_labeling.py

示例14: annotate

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [as 別名]
def annotate(event, x, y, flags, param):
    """Callback for function 'annotate_tracks'.
    Tracks cursor and detects if mouse position is to be saved as
    a trackpoint. Track points are saved once per frame if the 
    left mouse button is held down.
    """
    
    global is_read
    global px, py
    
    if event == cv2.EVENT_MOUSEMOVE:
        px, py = x, y

    if event == cv2.EVENT_LBUTTONDOWN:
        is_read = 1
        
    if event == cv2.EVENT_LBUTTONUP:
        is_read = 0 
開發者ID:gorchard,項目名稱:event-Python,代碼行數:20,代碼來源:annotate.py

示例15: drawFloorCrop

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import EVENT_MOUSEMOVE [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) 
開發者ID:colinlaney,項目名稱:animal-tracking,代碼行數:40,代碼來源:track.py


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