Python cv2 模块,EVENT_RBUTTONDOWN 实例源码

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

项目:MultiObjectTracker    作者:alokwhitewolf    | 项目源码 | 文件源码
def get_points(event,x,y,flags,param):
    global lpnts,rpnts

    if event == cv2.EVENT_LBUTTONDOWN:
        lpnts = np.append(lpnts, np.array([[x, y]]), axis=0)
        cv2.polylines(img, [lpnts], False, (0, 0, 255))



    if event == cv2.EVENT_RBUTTONDOWN:
        rpnts = np.append(rpnts, np.array([[x, y]]), axis=0)
        cv2.polylines(img, [rpnts], False, (255, 0, 0))

        if rpnts.size>2:
            check(lpnts, rpnts[-1], rpnts[-2])



#check if the new point crosses a line
项目: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)
项目:car-detection    作者:mmetcalfe    | 项目源码 | 文件源码
def annotate_mouse_callback(event, x, y, flags, annotator):
    winName = annotator.winName

    # If adding a bounding box:
    if annotator.editing:
        # Set top left corner of rectangle:
        if event == cv2.EVENT_LBUTTONDOWN:
            annotator.rect_tl = (x, y)

        # Set bottom right corner of rectangle:
        elif event == cv2.EVENT_RBUTTONDOWN:
            annotator.rect_br = (x, y)

    # If deleting a bounding box:
    elif annotator.deleting:
        if event == cv2.EVENT_LBUTTONDOWN:
            print 'Delete at {}'.format((x, y))
            annotator.delete_rectangles_at_point((x, y))
            annotator.deleting = False

    annotator.update_display()
项目:pynephoscope    作者:neXyon    | 项目源码 | 文件源码
def imageMouseCallback(self, event, x, y, flags, param):
        if event == cv2.EVENT_LBUTTONDOWN:
            x, y = self.calibrator.findImageStar(x, y)

            correspondence = self.findCorrespondence(x, y)

            if correspondence is None:
                if self.calibrator.setCorrespondencePos(self.selected_star, (x, y)):
                    self.selected_star = self.calibrator.findEmptyPos()
                else:
                    self.selected_star = self.calibrator.addCorrespondence((x, y), None)
            else:
                self.selected_star = correspondence

            self.render()

        elif event == cv2.EVENT_RBUTTONDOWN:
            self.deleteSelectedStar()
项目:pynephoscope    作者:neXyon    | 项目源码 | 文件源码
def skyMouseCallback(self, event, x, y, flags, param):
        if event == cv2.EVENT_LBUTTONDOWN:
            res = self.renderer.findStar(x, y, self.circle_radius)

            if res is None:
                return

            altaz = (res[0], res[1])
            correspondence = self.calibrator.findAltAzCorrespondence(altaz)

            if correspondence is None:
                if self.calibrator.setCorrespondenceAltaz(self.selected_star, altaz):
                    self.selected_star = self.calibrator.findEmptyAltAz()
                else:
                    self.selected_star = self.calibrator.addCorrespondence(None, altaz)
            else:
                self.selected_star = correspondence

            self.render()
        elif event == cv2.EVENT_RBUTTONDOWN:
            self.deleteSelectedStar()
项目:video_labeler    作者:hahnyuan    | 项目源码 | 文件源码
def video_click(self,e, x, y, flags, param):
        if e == cv2.EVENT_LBUTTONDOWN:
            self.video_stat.is_drug = 1
            self.video_stat.p0 = (x, y)
            print("rect start", x, y)
        elif e == cv2.EVENT_LBUTTONUP:
            self.video_stat.is_drug = 0
            self.video_stat.p1 = (x, y)
            print("rect end", x, y)
            self.video_stat.append_box(self.label_stat.get_label_name())
        elif e== cv2.EVENT_RBUTTONDOWN:
            self.video_stat.remove_point_box((x,y))
        self.video_stat.p=(x,y)
项目: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)
项目:Kaggle_the_Nature_Conservancy_Fisheries_Monitoring    作者:Sapphirine    | 项目源码 | 文件源码
def click_and_crop(event, x, y, flags, param):
    global refPt, cropping
    if event == cv2.EVENT_LBUTTONDOWN:    # indicates that the left mouse button is pressed
        refPt = [(x, y)]
        cropping = True
    elif event == cv2.EVENT_RBUTTONDOWN:   # indicates that the right mouse button is pressed
        refPt.append((x, y))
        cropping = False
        cv2.rectangle(image, refPt[0], refPt[1], (0, 255, 0), 2)
        cv2.imshow("image", image)


# <=====================================================================================>
# Here is the process to crop the window and get the position of the graph
# after the classification of the fish boat
项目: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)
项目:ConditionalGAN    作者:seungjooli    | 项目源码 | 文件源码
def test(m):
    class DrawingState:
        def __init__(self):
            self.x_prev = 0
            self.y_prev = 0
            self.drawing = False
            self.update = True

    def interactive_drawing(event, x, y, flags, param):
        image = param[0]
        state = param[1]
        if event == cv2.EVENT_LBUTTONDOWN:
            state.drawing = True
            state.x_prev, state.y_prev = x, y
        elif event == cv2.EVENT_MOUSEMOVE:
            if state.drawing:
                cv2.line(image, (state.x_prev, state.y_prev), (x, y), (1, 1, 1), 1)
                state.x_prev = x
                state.y_prev = y
                state.update = True
        elif event == cv2.EVENT_LBUTTONUP:
            state.drawing = False
        elif event == cv2.EVENT_RBUTTONDOWN:
            image.fill(0)
            state.update = True

    cv2.namedWindow('Canvas')
    image_input = np.zeros((FLAGS.input_height, FLAGS.input_width, 3), np.float32)
    state = DrawingState()
    cv2.setMouseCallback('Canvas', interactive_drawing, [image_input, state])
    while cv2.getWindowProperty('Canvas', 0) >= 0:
        if state.update:
            reshaped_image_input = np.array([image_input])
            image_output = m.test(reshaped_image_input)
            concatenated = np.concatenate((image_input, image_output[0]), axis=1)
            color_converted = cv2.cvtColor(concatenated, cv2.COLOR_RGB2BGR)
            cv2.imshow('Canvas', color_converted)
            state.update = False

        k = cv2.waitKey(1) & 0xFF
        if k == 27:  # esc
            break
    cv2.destroyAllWindows()