python类EVENT_FLAG_LBUTTON的实例源码

common.py 文件源码 项目:python-opencv2 作者: bunkahle 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)
common.py 文件源码 项目:emojivis 作者: JustinShenk 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def on_mouse(self, event, x, y, flags, param):
        pt = (x, y)
        if event == cv2.EVENT_LBUTTONDOWN:
            self.prev_pt = pt
        elif event == cv2.EVENT_LBUTTONUP:
            self.prev_pt = None

        if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON:
            for dst, color in zip(self.dests, self.colors_func()):
                cv2.line(dst, self.prev_pt, pt, color, 5)
            self.dirty = True
            self.prev_pt = pt
            self.show()


# palette data from matplotlib/_cm.py
common.py 文件源码 项目:emojivis 作者: JustinShenk 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)
??QQ????.py 文件源码 项目:Python-Learner 作者: fire717 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def draw_rect(event,x,y,flags,param):
    global x1,y1,x2,y2,drawing,img,imgSmall,finishDraw
    # ??????????????
    if event==cv2.EVENT_LBUTTONDOWN:
        drawing=True
        x1,y1=x,y
    # ???????????????? event ??????? flag ??????
    elif event==cv2.EVENT_MOUSEMOVE and flags==cv2.EVENT_FLAG_LBUTTON:
        if drawing==True:
            img[:,:]=newGray[:,:]
            img[y1:y,x1:x]=imgSmall[y1:y,x1:x]
            cv2.rectangle(img,(x1,y1),(x,y),(0,0,255),1)
    # ??????????
    elif event==cv2.EVENT_LBUTTONUP:
        drawing==False
        x2,y2=x,y
        finishDraw = True
common.py 文件源码 项目:OpenCV-Snapchat-DogFilter 作者: sguduguntla 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def on_mouse(self, event, x, y, flags, param):
        pt = (x, y)
        if event == cv2.EVENT_LBUTTONDOWN:
            self.prev_pt = pt
        elif event == cv2.EVENT_LBUTTONUP:
            self.prev_pt = None

        if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON:
            for dst, color in zip(self.dests, self.colors_func()):
                cv2.line(dst, self.prev_pt, pt, color, 5)
            self.dirty = True
            self.prev_pt = pt
            self.show()


# palette data from matplotlib/_cm.py
common.py 文件源码 项目:OpenCV-Snapchat-DogFilter 作者: sguduguntla 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
            return
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)
common.py 文件源码 项目:memegenerator 作者: Huxwell 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def on_mouse(self, event, x, y, flags, param):
        pt = (x, y)
        if event == cv2.EVENT_LBUTTONDOWN:
            self.prev_pt = pt
        elif event == cv2.EVENT_LBUTTONUP:
            self.prev_pt = None

        if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON:
            for dst, color in zip(self.dests, self.colors_func()):
                cv2.line(dst, self.prev_pt, pt, color, 5)
            self.dirty = True
            self.prev_pt = pt
            self.show()


# palette data from matplotlib/_cm.py
common.py 文件源码 项目:memegenerator 作者: Huxwell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def onmouse(self, event, x, y, flags, param):
        x, y = np.int16([x, y]) # BUG
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                xo, yo = self.drag_start
                x0, y0 = np.minimum([xo, yo], [x, y])
                x1, y1 = np.maximum([xo, yo], [x, y])
                self.drag_rect = None
                if x1-x0 > 0 and y1-y0 > 0:
                    self.drag_rect = (x0, y0, x1, y1)
            else:
                rect = self.drag_rect
                self.drag_start = None
                self.drag_rect = None
                if rect:
                    self.callback(rect)
naiverstokes:fastmarch.py 文件源码 项目:inpainting 作者: kvfrans 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def on_mouse(self, event, x, y, flags, param):
            pt = (x, y)
            if event == cv2.EVENT_LBUTTONDOWN:
                self.prev_pt = pt
            elif event == cv2.EVENT_LBUTTONUP:
                self.prev_pt = None

            if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON:
                for dst, color in zip(self.dests, self.colors_func()):
                    cv2.line(dst, self.prev_pt, pt, color, 50)
                self.dirty = True
                self.prev_pt = pt
                self.show()
floodfill.py 文件源码 项目:python-opencv2 作者: bunkahle 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def onmouse(event, x, y, flags, param):
        global seed_pt
        if flags & cv2.EVENT_FLAG_LBUTTON:
            seed_pt = x, y
            update()
common.py 文件源码 项目:python-opencv2 作者: bunkahle 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def on_mouse(self, event, x, y, flags, param):
        pt = (x, y)
        if event == cv2.EVENT_LBUTTONDOWN:
            self.prev_pt = pt
        if self.prev_pt and flags & cv2.EVENT_FLAG_LBUTTON:
            for dst, color in zip(self.dests, self.colors_func()):
                cv2.line(dst, self.prev_pt, pt, color, 5)
            self.dirty = True
            self.prev_pt = pt
            self.show()
        else:
            self.prev_pt = None


# palette data from matplotlib/_cm.py
camshift.py 文件源码 项目:Artificial-Intelligence-with-Python 作者: PacktPublishing 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def mouse_event(self, event, x, y, flags, param):
        # Convert x and y coordinates into 16-bit numpy integers
        x, y = np.int16([x, y]) 

        # Check if a mouse button down event has occurred
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drag_start = (x, y)
            self.tracking_state = 0

        # Check if the user has started selecting the region
        if self.drag_start:
            if flags & cv2.EVENT_FLAG_LBUTTON:
                # Extract the dimensions of the frame
                h, w = self.frame.shape[:2]

                # Get the initial position
                xi, yi = self.drag_start

                # Get the max and min values
                x0, y0 = np.maximum(0, np.minimum([xi, yi], [x, y]))
                x1, y1 = np.minimum([w, h], np.maximum([xi, yi], [x, y]))

                # Reset the selection variable
                self.selection = None

                # Finalize the rectangular selection
                if x1-x0 > 0 and y1-y0 > 0:
                    self.selection = (x0, y0, x1, y1)

            else:
                # If the selection is done, start tracking  
                self.drag_start = None
                if self.selection is not None:
                    self.tracking_state = 1

    # Method to start tracking the object


问题


面经


文章

微信
公众号

扫码关注公众号