Python cv2 模块,EVENT_RBUTTONUP 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用cv2.EVENT_RBUTTONUP

项目:Opencv_learning    作者:wjb711    | 项目源码 | 文件源码
def draw_circle(event,x,y,flags,param):
    global drawing,drawing1
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
    if event == cv2.EVENT_RBUTTONDOWN:
        drawing1 = True
    if event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            cv2.circle(img,(x,y),5,(0,0,255),-1)
        if drawing1 == True:
            cv2.circle(img,(x,y),5,(0,255,0),-1)
    if event == cv2.EVENT_LBUTTONUP:
        drawing = False
    if event == cv2.EVENT_RBUTTONUP:
        drawing1 = False
    #print (drawing)
项目:dlcv_for_beginners    作者:frombeijingwithlove    | 项目源码 | 文件源码
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()
项目:ShadowRemoval    作者:Orcuslc    | 项目源码 | 文件源码
def init_mask(self, event, x, y, flags, param):
        self._thickness = 3 # The thickness in drawing;
        self._WHITE = [255, 255, 255] # Pure white;

        # Draw a point on the image;
        if event == cv2.EVENT_RBUTTONDOWN:
            if self._drawing == True:
                cv2.circle(self.img, (x, y), self._thickness, self._WHITE, -1)
                self.mask[y-self._thickness:y+self._thickness, x-self._thickness:x+self._thickness] = self._SHADOW
                self._shadow_seed = self.img[y-self._thickness:y+self._thickness, x-self._thickness:x+self._thickness].copy()

        elif event == cv2.EVENT_RBUTTONUP:
            if self._drawing == True:
                self._drawing = False
                self._drawn = True
                cv2.circle(self.img, (x, y), self._thickness, self._WHITE, -1)
项目:lqRRT    作者:jnez71    | 项目源码 | 文件源码
def do_draw(self, event, x, y, flags, param):
        draw_vals = {1: 100, 2: 0}

        if event == cv2.EVENT_LBUTTONUP or event == cv2.EVENT_RBUTTONUP:
            self.drawing = 0
        elif event == cv2.EVENT_LBUTTONDOWN:
            self.drawing = 1
        elif event == cv2.EVENT_RBUTTONDOWN:
            self.drawing = 2
        elif self.drawing != 0:
            cv2.circle(self.img, (x, y), 5, draw_vals[self.drawing], -1)
项目:party-pi    作者:JustinShenk    | 项目源码 | 文件源码
def mouse(self, event, x, y, flags, param):
        """ Listen for mouse.

        """
        if event == cv2.EVENT_MOUSEMOVE:
            self.currPosX, self.currPosY = x, y
            # print "curposX,Y", x, y

        elif event == cv2.EVENT_LBUTTONUP:
            self.click_point_x, self.click_point_y = x, y
            if self.curr_level == 0:
                self.easy_mode = True
                self.curr_level = 1
            if self.curr_level == 2:
                self.reset()

        elif event == cv2.EVENT_RBUTTONUP:
            self.click_point_right_x, self.click_point_right_y = x, y
            if self.present_mode:
                self.reset()
                self.easy_mode = False
                self.curr_level = 1
项目:GoogleVideo    作者:bw4sz    | 项目源码 | 文件源码
def Crop(img,title):


    def onmouse(event,x,y,flags,param):
        global ix,iy,roi,drawing        

        # Draw Rectangle
        if event == cv2.EVENT_RBUTTONDOWN:
            drawing = True
            ix,iy = x,y

        elif event == cv2.EVENT_MOUSEMOVE:
            if drawing == True:
                cv2.rectangle(img,(ix,iy),(x,y),BLUE,-1)
                rect = (ix,iy,abs(ix-x),abs(iy-y))

        elif event == cv2.EVENT_RBUTTONUP:
            drawing = False
            cv2.rectangle(img,(ix,iy),(x,y),BLUE,-1)
            rect = (ix,iy,x,y)
            roi.extend(rect)

    cv2.namedWindow(title,cv2.WINDOW_NORMAL)
    cv2.setMouseCallback(title,onmouse)

    print ("Right click and hold to draw a single rectangle ROI, beginning at the top left corner of the desired area. A blue box should appear. Hit esc to exit screen. Window can be resized by selecting borders.")
    while True:
            cv2.namedWindow(title,cv2.WINDOW_NORMAL)                 
            cv2.imshow(title,img)
            k = cv2.waitKey(1) & 0xFF
            if k == 27:
                    break

    cv2.destroyAllWindows()

    print(roi)
    return(roi)
项目:GoogleVideo    作者:bw4sz    | 项目源码 | 文件源码
def Crop(img,title):


    def onmouse(event,x,y,flags,param):
        global ix,iy,roi,drawing        

        # Draw Rectangle
        if event == cv2.EVENT_RBUTTONDOWN:
            drawing = True
            ix,iy = x,y

        elif event == cv2.EVENT_MOUSEMOVE:
            if drawing == True:
                cv2.rectangle(img,(ix,iy),(x,y),BLUE,-1)
                rect = (ix,iy,abs(ix-x),abs(iy-y))

        elif event == cv2.EVENT_RBUTTONUP:
            drawing = False
            cv2.rectangle(img,(ix,iy),(x,y),BLUE,-1)
            rect = (ix,iy,x,y)
            roi.extend(rect)

    cv2.namedWindow(title,cv2.WINDOW_NORMAL)
    cv2.setMouseCallback(title,onmouse)

    print ("Right click and hold to draw a single rectangle ROI, beginning at the top left corner of the desired area. A blue box should appear. Hit esc to exit screen. Window can be resized by selecting borders.")
    while True:
            cv2.namedWindow(title,cv2.WINDOW_NORMAL)                 
            cv2.imshow(title,img)
            k = cv2.waitKey(1) & 0xFF
            if k == 27:
                    break

    cv2.destroyAllWindows()

    print(roi)
    return(roi)
项目:piwall-cvtools    作者:infinnovation    | 项目源码 | 文件源码
def mouse_callback(event, x, y, flags, param):
    global refPt, image, tiles, wall, selected_tile, l_mouse_button_down, mouse_over_tile,\
        clone, offsets

    if event == cv2.EVENT_LBUTTONDOWN:
        l_mouse_button_down = True
        refPt = [(x, y)]
        if not draw_tile:
            if find_hovered_tile(x,y):
                mouse_over_tile = True
                offsets = (x - selected_tile.wx - selected_tile.l, y-selected_tile.wy - selected_tile.t)
            else:
                mouse_over_tile = False

    elif event == cv2.EVENT_LBUTTONUP:
        l_mouse_button_down = False
        if draw_tile:
            #Restrict to create tiles that are at least 100 sqpixel big
            if (abs(refPt[0][0] - x) * abs(refPt[0][1] - y) >= 100):
                newTile = Tile(abs(refPt[0][0] - x), abs(refPt[0][1] - y))
                wall.add_tile(newTile, min(refPt[0][0], x), min(refPt[0][1], y))
                wall.draw(image)
                tiles.append(newTile)
        else:
            print("dragging the tile")

    elif event == cv2.EVENT_RBUTTONUP:
        if find_hovered_tile(x,y):
            tile_popup()

    elif event == cv2.EVENT_MOUSEMOVE:
        # TODO: Implement the t r b resize too
        if l_mouse_button_down and mouse_over_tile and x >= selected_tile.wx and x <= selected_tile.wx + 5:
            new_w = selected_tile.w + selected_tile.wx + selected_tile.l - x
            # TODO: Fix when the bezel is resized to the left
            print(
            "selected_tile.w = {} selected_tile.wx = {} x = {} new_w = {}".format(selected_tile.w, selected_tile.wx, x,
                                                                                  new_w))
            if new_w >= MINIMUM_RESIZE_WIDTH:
                selected_tile.w = new_w
                selected_tile.wx = x - selected_tile.l
                image = clone.copy()
                wall.draw(image)
                print("RESIZING")
        elif l_mouse_button_down and mouse_over_tile and not draw_tile:
            selected_tile.wx = x - offsets[0]
            selected_tile.wy = y - offsets[1]
            image = clone.copy()
            wall.draw(image)
        #TODO: Implement an else that will start drawing the tile while in the draw mode