Python cv2 模块,EVENT_LBUTTONUP 实例源码

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

项目:MultiObjectTracker    作者:alokwhitewolf    | 项目源码 | 文件源码
def run(im):
    im_disp = im.copy()
    window_name = "Draw line here."
    cv2.namedWindow(window_name,cv2.WINDOW_AUTOSIZE)
    cv2.moveWindow(window_name, 910, 0)

    print " Drag across the screen to set lines.\n Do it twice"
    print " After drawing the lines press 'r' to resume\n"

    l1 = np.empty((2, 2), np.uint32)
    l2 = np.empty((2, 2), np.uint32)

    list = [l1,l2]

    mouse_down = False
    def callback(event, x, y, flags, param):
        global trigger, mouse_down

        if trigger<2:
            if event == cv2.EVENT_LBUTTONDOWN:
                mouse_down = True
                list[trigger][0] = (x, y)

            if event == cv2.EVENT_LBUTTONUP and mouse_down:
                mouse_down = False
                list[trigger][1] = (x,y)
                cv2.line(im_disp, (list[trigger][0][0], list[trigger][0][1]),
                         (list[trigger][1][0], list[trigger][1][1]), (255, 0, 0), 2)
                trigger += 1
        else:
            pass
    cv2.setMouseCallback(window_name, callback)
    while True:
        cv2.imshow(window_name,im_disp)
        key = cv2.waitKey(10) & 0xFF

        if key == ord('r'):
            # Press key `q` to quit the program
            return list
            exit()
项目:DrosophilaCooperative    作者:avaccari    | 项目源码 | 文件源码
def mouseInteraction(self, event, x, y, flags, params):
        if self.userInteraction is True:
            if event == cv2.EVENT_LBUTTONDOWN:
                self.refPt = [(x, y)]
                self.workingFrame[y, x] = [0, 0, 255]
                self.showFrame(self.selectionWindow, self.workingFrame)
            elif event == cv2.EVENT_LBUTTONUP:
                self.undoFrames.append(self.workingFrame.copy())
                self.refPt.append((x, y))
                if self.refPt[0][0] != self.refPt[1][0] and self.refPt[0][1] != self.refPt[1][1]:
                    area = trackedArea(self.refPt)
                    area.setStackSize(30)
                    area.setTemplate(self.processedFrame)
#                    area.initKalman()
                    corn = area.getCorners()
                    self.trackedAreasList.append(area)

                    cv2.rectangle(self.workingFrame,
                                  corn[0], corn[1],
                                  (0, 0, 255), 1)

                    self.showFrame(self.selectionWindow, self.workingFrame)
项目:CE264-Computer_Vision    作者:RobinCPC    | 项目源码 | 文件源码
def brush_circle(event, x, y, flags, param):
    global ix, iy, drawing, mode, r,g,b,radius

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True  # start to draw when L button down
        ix, iy = x, y
    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing == True and mode == True:
            cv2.circle(img, (x,y), radius, (b, g, r), -1)
    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False     # end drawing when L button up
        if mode == True:
            cv2.circle(img, (x,y), radius, (b, g, r), -1)



# Create a black image, a window
项目:piwall-cvtools    作者:infinnovation    | 项目源码 | 文件源码
def on_mouse(event, x, y, flags, params):
    # global img
    t = time()

    if event == cv2.EVENT_LBUTTONDOWN:
        print 'Start Mouse Position: '+str(x)+', '+str(y)
        sbox = [x, y]
        boxes.append(sbox)
             # print count
             # print sbox

    elif event == cv2.EVENT_LBUTTONUP:
        print 'End Mouse Position: '+str(x)+', '+str(y)
        ebox = [x, y]
        boxes.append(ebox)
        print boxes
        crop = img[boxes[-2][1]:boxes[-1][1],boxes[-2][0]:boxes[-1][0]]

        cv2.imshow('crop',crop)
        k =  cv2.waitKey(0)
        if ord('r')== k:
            cv2.imwrite('Crop'+str(t)+'.jpg',crop)
            print "Written to file"
项目:python-examples-cv    作者:tobybreckon    | 项目源码 | 文件源码
def on_mouse(event, x, y, flags, params):

    global boxes;
    global selection_in_progress;

    current_mouse_position[0] = x;
    current_mouse_position[1] = y;

    if event == cv2.EVENT_LBUTTONDOWN:
        boxes = [];
        # print 'Start Mouse Position: '+str(x)+', '+str(y)
        sbox = [x, y];
        selection_in_progress = True;
        boxes.append(sbox);

    elif event == cv2.EVENT_LBUTTONUP:
        # print 'End Mouse Position: '+str(x)+', '+str(y)
        ebox = [x, y];
        selection_in_progress = False;
        boxes.append(ebox);

#####################################################################

# controls
项目:python-examples-cv    作者:tobybreckon    | 项目源码 | 文件源码
def on_mouse(event, x, y, flags, params):

    global boxes;
    global selection_in_progress;

    current_mouse_position[0] = x;
    current_mouse_position[1] = y;

    if event == cv2.EVENT_LBUTTONDOWN:
        boxes = [];
        # print 'Start Mouse Position: '+str(x)+', '+str(y)
        sbox = [x, y];
        selection_in_progress = True;
        boxes.append(sbox);

    elif event == cv2.EVENT_LBUTTONUP:
        # print 'End Mouse Position: '+str(x)+', '+str(y)
        ebox = [x, y];
        selection_in_progress = False;
        boxes.append(ebox);
#####################################################################

# return centre of a set of points representing a rectangle
项目:OPEN_CV    作者:animeshsrivastava24    | 项目源码 | 文件源码
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)
项目: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)
项目:python-opencv2    作者:bunkahle    | 项目源码 | 文件源码
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)
项目:Interactive-object-tracking    作者:abhishekarya286    | 项目源码 | 文件源码
def click_and_crop(event, x, y, flags, param):

    # grab references to the global variables
    global refPt, cropping

    # if the left mouse button was clicked, record the starting
    # (x, y) coordinates and indicate that cropping is being
    # performed
    if event == cv2.EVENT_LBUTTONDOWN:
        refPt = [(x, y)]
        cropping = True

    # check to see if the left mouse button was released
    elif event == cv2.EVENT_LBUTTONUP:
        # record the ending (x, y) coordinates and indicate that
        # the cropping operation is finished
        refPt.append((x, y))
        cropping = False

        # draw a rectangle around the region of interest
        cv2.rectangle(img_copy, refPt[0], refPt[1], (0, 255, 0), 2)
        cv2.imshow("image", img_copy)
        cv2.waitKey(0)
项目:Interactive-object-tracking    作者:abhishekarya286    | 项目源码 | 文件源码
def click_and_crop(event, x, y, flags, param):

    # grab references to the global variables
    global refPt, cropping

    # if the left mouse button was clicked, record the starting
    # (x, y) coordinates and indicate that cropping is being
    # performed
    if event == cv2.EVENT_LBUTTONDOWN:
        refPt = [(x, y)]
        cropping = True

    # check to see if the left mouse button was released
    elif event == cv2.EVENT_LBUTTONUP:
        # record the ending (x, y) coordinates and indicate that
        # the cropping operation is finished
        refPt.append((x, y))
        cropping = False

        # draw a rectangle around the region of interest
        cv2.rectangle(img_copy, refPt[0], refPt[1], (0, 255, 0), 2)
        cv2.imshow("image", img_copy)
        cv2.waitKey(0)
项目:emojivis    作者:JustinShenk    | 项目源码 | 文件源码
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
项目:Kinect-ASUS-Xtion-Pro-Live-Calibration-Tutorials    作者:taochenshh    | 项目源码 | 文件源码
def draw_rect(self,event,x,y,flags,param):
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drawing = True
            self.rect_done = False
            self.ix1 = x
            self.iy1 = y

        elif event == cv2.EVENT_MOUSEMOVE:
            if self.drawing == True:
                self.ix2 = x
                self.iy2 = y


        elif event == cv2.EVENT_LBUTTONUP:
            self.drawing = False
            self.ix2 = x
            self.iy2 = y
            cv2.rectangle(self.rgb_image,(self.ix1,self.iy1),(self.ix2,self.iy2),(0,255,0),2)
            center_point = self.get_center_point()
            cv2.circle(self.rgb_image, tuple(center_point.astype(int)), 3, (0,0,255),-1)
            cv2.imshow('RGB Image', self.rgb_image)
            cv2.waitKey(5)
            self.rect_done = True
项目: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()
项目:Python-Learner    作者:fire717    | 项目源码 | 文件源码
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
项目:OpenCV-Snapchat-DogFilter    作者:sguduguntla    | 项目源码 | 文件源码
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
项目:awesome-opencv-scripts    作者:hs105    | 项目源码 | 文件源码
def click_and_crop(event, x, y, flags, param):
    # grab references to the global variables
    global refPt, cropping

    # if the left mouse button was clicked, record the starting
    # (x, y) coordinates and indicate that cropping is being
    # performed
    if event == cv2.EVENT_LBUTTONDOWN:
        refPt = [(x, y)]
        cropping = True

    # check to see if the left mouse button was released
    elif event == cv2.EVENT_LBUTTONUP:
        # record the ending (x, y) coordinates and indicate that
        # the cropping operation is finished
        refPt.append((x, y))
        cropping = False

        # draw a rectangle around the region of interest
        cv2.rectangle(image, refPt[0], refPt[1], (0, 255, 0), 2)
        cv2.imshow("image", image)
项目:memegenerator    作者:Huxwell    | 项目源码 | 文件源码
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
项目:event-Python    作者:gorchard    | 项目源码 | 文件源码
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
项目:CE264-Computer_Vision    作者:RobinCPC    | 项目源码 | 文件源码
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)  # -1 for last argument like CV_FILLED
            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)
项目:general-deep-image-completion    作者:adamstseng    | 项目源码 | 文件源码
def draw(event, x, y, flags, param):
    global ix, iy, drawing

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix, iy = x, y
    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing:
            cv2.line(img, (ix, iy), (x, y), (0.9, 0.01, 0.9), pen_size)
            ix, iy = x, y
    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        cv2.line(img, (ix, iy), (x, y), (0.9, 0.01, 0.9), pen_size)
项目:general-deep-image-completion    作者:adamstseng    | 项目源码 | 文件源码
def draw(event, x, y, flags, param):
    global ix, iy, drawing

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix, iy = x, y
    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing:
            cv2.line(img, (ix, iy), (x, y), (0.9, 0.01, 0.9), pen_size)
            ix, iy = x, y
    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        cv2.line(img, (ix, iy), (x, y), (0.9, 0.01, 0.9), pen_size)
项目:PyIntroduction    作者:tody411    | 项目源码 | 文件源码
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


# ?????????
项目: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)
项目:canshi    作者:hungsing92    | 项目源码 | 文件源码
def click_and_crop(event, x, y, flags, param):
    global bbs, x_upper, id

    if event == cv2.EVENT_LBUTTONDOWN:
        if x_upper:
            bbs.append([x,y,0,0, 0,0,0,0])
        else:
            bbs[-1][4] = x
            bbs[-1][5] = y

    elif event == cv2.EVENT_LBUTTONUP:
        if x_upper:
            bbs[-1][2] = abs(x - bbs[-1][0])            
            bbs[-1][3] = abs(y - bbs[-1][1])
            bbs[-1][0] = min(x, bbs[-1][0])
            bbs[-1][1] = min(y, bbs[-1][1])
            cv2.rectangle(image, (bbs[-1][0],bbs[-1][1]), (bbs[-1][0]+bbs[-1][2],bbs[-1][1]+bbs[-1][3]), (0,0,255), 2)
            #cv2.putText(image, 'Upper %d' % id, (bbs[-1][0],bbs[-1][1]), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0,0,255))
        else:
            bbs[-1][6] = abs(x - bbs[-1][4])
            bbs[-1][7] = abs(y - bbs[-1][5])
            bbs[-1][4] = min(x, bbs[-1][4])
            bbs[-1][5] = min(y, bbs[-1][5])
            cv2.rectangle(image, (bbs[-1][4],bbs[-1][5]), (bbs[-1][4]+bbs[-1][6],bbs[-1][5]+bbs[-1][7]), (0,255,0), 2)
            cv2.putText(image, 'Body %d' % id, (bbs[-1][4],bbs[-1][5]), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0,255,0))


        cv2.imshow("image", image)        
        x_upper = not x_upper
项目:ATX    作者:NetEaseGame    | 项目源码 | 文件源码
def make_mouse_callback(imgs, ref_pt):
    # initialize the list of reference points and boolean indicating
    # whether cropping is being performed or not
    cropping = [False]
    clone = imgs[0]

    def _click_and_crop(event, x, y, flags, param):
        # grab references to the global variables
        # global ref_pt, cropping

        # if the left mouse button was clicked, record the starting
        # (x, y) coordinates and indicate that cropping is being
        # performed
        if event == cv2.EVENT_LBUTTONDOWN:
            ref_pt[0] = (x, y)
            cropping[0] = True

        # check to see if the left mouse button was released
        elif event == cv2.EVENT_LBUTTONUP:
            # record the ending (x, y) coordinates and indicate that
            # the cropping operation is finished
            ref_pt[1] = (x, y)
            cropping[0] = False

            # draw a rectangle around the region of interest
            imgs[1] = image = clone.copy()
            cv2.rectangle(image, ref_pt[0], ref_pt[1], (0, 255, 0), 2)
            cv2.imshow("image", image)
        elif event == cv2.EVENT_MOUSEMOVE and cropping[0]:
            img2 = clone.copy()
            cv2.rectangle(img2, ref_pt[0], (x, y), (0, 255, 0), 2)
            imgs[1] = image = img2
            cv2.imshow("image", image)
    return _click_and_crop
项目:AutomatorX    作者:xiaoyaojjian    | 项目源码 | 文件源码
def make_mouse_callback(imgs, ref_pt):
    # initialize the list of reference points and boolean indicating
    # whether cropping is being performed or not
    cropping = [False]
    clone = imgs[0]

    def _click_and_crop(event, x, y, flags, param):
        # grab references to the global variables
        # global ref_pt, cropping

        # if the left mouse button was clicked, record the starting
        # (x, y) coordinates and indicate that cropping is being
        # performed
        if event == cv2.EVENT_LBUTTONDOWN:
            ref_pt[0] = (x, y)
            cropping[0] = True

        # check to see if the left mouse button was released
        elif event == cv2.EVENT_LBUTTONUP:
            # record the ending (x, y) coordinates and indicate that
            # the cropping operation is finished
            ref_pt[1] = (x, y)
            cropping[0] = False

            # draw a rectangle around the region of interest
            imgs[1] = image = clone.copy()
            cv2.rectangle(image, ref_pt[0], ref_pt[1], (0, 255, 0), 2)
            cv2.imshow("image", image)
        elif event == cv2.EVENT_MOUSEMOVE and cropping[0]:
            img2 = clone.copy()
            cv2.rectangle(img2, ref_pt[0], (x, y), (0, 255, 0), 2)
            imgs[1] = image = img2
            cv2.imshow("image", image)
    return _click_and_crop
项目: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)
项目:traffic-light-detection    作者:ranveeraggarwal    | 项目源码 | 文件源码
def click_and_crop(event, x, y, flags, param):
    # grab references to the global variables
    global refPt, cropping, i

    # if the left mouse button was clicked, record the starting
    # (x, y) coordinates and indicate that cropping is being
    # performed
    if event == cv2.EVENT_LBUTTONDOWN:
        if refPt == []:
            refPt = [(x, y)]
        else:
            refPt.append((x,y))
        cropping = True
        i += 1

    if event == cv2.EVENT_MOUSEMOVE and cropping:
        image2 = image.copy()
        cv2.rectangle(image2, refPt[2*i-2], (x,y), (0,255,0), 2)
        cv2.imshow("image",image2)

    # check to see if the left mouse button was released
    elif event == cv2.EVENT_LBUTTONUP:
        # record the ending (x, y) coordinates and indicate that
        # the cropping operation is finished
        refPt.append((x, y))
        cropping = False

        # draw a rectangle around the region of interest
        cv2.rectangle(image, refPt[2*i-2], refPt[2*i-1], (0, 255, 0), 2)
        # cv2.rectangle(image2, refPt[2*i-2], refPt[2*i-1], (0, 255, 0), 2)
        cv2.imshow("image", image)

# construct the argument parser and parse the arguments
项目: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
项目:inpainting    作者:kvfrans    | 项目源码 | 文件源码
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()
项目:srcsim2017    作者:ZarjRobotics    | 项目源码 | 文件源码
def handle_mouse(event, x, y, flags, param):
    global details
    global cloud
    global ME
    if event == cv2.EVENT_LBUTTONUP:
        point = PointStamped()
        point.header = cloud.header
        point.point.x = details[y, x][0]
        point.point.y = details[y, x][1]
        point.point.z = details[y, x][2]

        print x, y, details[y,x]
        result = ME.transform.tf_buffer.transform(point, 'rightIndexFingerPitch1Link')
        print result

#leftimg,_ = ME.eyes.get_images()
#img = zarj.navigation.PERSPECTIVE_AHEAD.build_rangefinding_image(leftimg)
#cv2.imshow("leftimg", img)

#img = zarj.navigation.PERSPECTIVE_AHEAD.build_rangefinding_image(raw_img)
项目:Course-Projects    作者:manujagobind    | 项目源码 | 文件源码
def draw(event, x, y, flags, param):
    global drawing, ix, iy, shape, canvas, brush

    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix, iy = x, y
    elif event == cv2.EVENT_MOUSEMOVE:
        if drawing == True:
            if shape == 1:
                cv2.circle(canvas, (x, y), pencil, color, -1)
            elif shape == 2:
                cv2.circle(canvas, (x, y), brush, color, -1)
            elif shape == 3:
                cv2.circle(canvas, (x, y), eraser, (255, 255, 255), -1)
            elif shape == 5:
                cv2.rectangle(canvas, (ix, iy), (x, y), color, -1)
            elif shape == 6:
                cv2.circle(canvas, (x, y), calc_radius(x, y), color, -1)
    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if shape == 1:
            cv2.circle(canvas, (x, y), pencil, color, -1)
        elif shape == 2:
            cv2.circle(canvas, (x, y), brush, color, -1)
        elif shape == 3:
            cv2.circle(canvas, (x, y), eraser, (255, 255, 255), -1)
        elif shape == 4:
            cv2.line(canvas, (ix, iy), (x, y), color, pencil)
        elif shape == 5:
            cv2.rectangle(canvas, (ix, iy), (x, y), color, -1)
        elif shape == 6:
            cv2.circle(canvas, (x, y), calc_radius(x, y), color, -1)
项目:Opencv-Python-Examples-    作者:arijitx    | 项目源码 | 文件源码
def draw_circle(event,x,y,flags,param):
    global ix,iy,drawing,mode
    global img
    im=img.copy()
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        ix,iy = x,y

    elif event == cv2.EVENT_LBUTTONUP:
        drawing = False
        if mode == True:
            cv2.rectangle(im,(ix,iy),(x,y),(0,255,0),1)
        cv2.imshow('image',im)
        cv2.imshow('res',color_picker([(ix,iy),(x,y)]))
项目:FaceSwap    作者:Aravind-Suresh    | 项目源码 | 文件源码
def markPoint(event, x, y, flags, param):
    global idx
    global data
    global input

    if event == cv2.EVENT_LBUTTONUP:
        data.append((x, y))
        cv2.circle(input, (x, y), 3, (0,0,255), 2)
        cv2.putText(input, str(idx), (x, y+4), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (0, 0, 0), 2, cv2.LINE_AA)
        cv2.imshow("Mark points", input)
        idx = idx + 1
项目:srcsim2017    作者:ZarjRobotics    | 项目源码 | 文件源码
def handle_mouse(self, event, x, y, flags, param):
        if event == cv2.EVENT_LBUTTONUP:
            print x
            print y
            print self.img[y, x]
项目:srcsim2017    作者:ZarjRobotics    | 项目源码 | 文件源码
def handle_mouse(self, event, x, y, flags, param):
        if event == cv2.EVENT_LBUTTONUP:
            point = PointStamped()
            point.header = self.cloud.header
            point.point.x = self.details[y, x][0]
            point.point.y = self.details[y, x][1]
            point.point.z = self.details[y, x][2]

            print x, y, self.details[y,x]
            result = self.zarj.transform.tf_buffer.transform(point, 'rightIndexFingerPitch1Link')
            print result
项目:FindYourCandy    作者:BrainPad    | 项目源码 | 文件源码
def mouse_event(event, x, y, flags, param):
    global should_exit
    if event == cv2.EVENT_LBUTTONUP:
        print("mouse_event:L-click")
        should_exit = True
项目:OpenCV-Drawing-withTrackbar    作者:farcompen    | 项目源码 | 文件源码
def sekil_ciz(event, x, y, flags, param):
    global ix, iy
    if event == cv2.EVENT_LBUTTONDOWN:
        ix, iy = x, y
    elif event == cv2.EVENT_LBUTTONUP:
        cv2.line(resim, (ix, iy), (x, y), (mavi_position, yesil_position, kirmizi_position), 3)
项目:ghetto_omr    作者:pohzhiee    | 项目源码 | 文件源码
def draw_rectangle(event,x,y,flags,param):
    if event == cv2.EVENT_LBUTTONDOWN:
        drawing = True
        param.drawing=True
        param.setxy(x,y)
        param.printxy()

    elif event == cv2.EVENT_MOUSEMOVE:
        if param.drawing == True:
            a=layering(param.layer_data,param.layer_index)
            img_temp_rect=a.copy()
            img_temp_rect=cv2.rectangle(img_temp_rect,(param.ix,param.iy),(x,y),(0,255,0),2)
            cv2.imshow('image',img_temp_rect)


    elif event == cv2.EVENT_LBUTTONUP:
        param.drawing = False
        shape_dimension1 = np.asarray((param.ix,param.iy))
        shape_dimension2=np.asarray((x,y))

        param.layer_data.resize(param.layer_data.shape[0]+1,4)

        k = param.layer_data.shape
        param.layer_data[k[0]-1, 0] = 1
        param.layer_data[k[0]-1, 1] = shape_dimension1
        param.layer_data[k[0]-1, 2] = shape_dimension2
        param.layer_data[k[0]-1,3]=param.layer_index+1
        param.layer_index=param.layer_index+1
        print param.layer_data
        a=layering(param.layer_data,param.layer_index)
项目:Kinect-ASUS-Xtion-Pro-Live-Calibration-Tutorials    作者:taochenshh    | 项目源码 | 文件源码
def draw_rect(self,event,x,y,flags,param):
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drawing = True
            self.rect_done = False
            self.ix1 = x
            self.iy1 = y

        elif event == cv2.EVENT_MOUSEMOVE:
            if self.drawing == True:
                self.ix2 = x
                self.iy2 = y


        elif event == cv2.EVENT_LBUTTONUP:
            self.drawing = False
            self.ix2 = x
            self.iy2 = y

            tempimg = self.rgb_image.copy()
            cv2.rectangle(tempimg,(self.ix1,self.iy1),(self.ix2,self.iy2),(0,255,0),2)
            center_point = self.get_center_point()

            cv2.circle(tempimg, tuple(center_point.astype(int)), 3, (0,0,255),-1)
            cv2.imshow('RGB Image', tempimg)
            cv2.waitKey(5)
            self.rect_done = True
项目:Kinect-ASUS-Xtion-Pro-Live-Calibration-Tutorials    作者:taochenshh    | 项目源码 | 文件源码
def draw_rect(self,event,x,y,flags,param):
        if event == cv2.EVENT_LBUTTONDOWN:
            self.drawing = True
            self.rect_done = False
            self.ix1 = x
            self.iy1 = y

        elif event == cv2.EVENT_MOUSEMOVE:
            if self.drawing == True:
                self.ix2 = x
                self.iy2 = y


        elif event == cv2.EVENT_LBUTTONUP:
            self.drawing = False
            self.ix2 = x
            self.iy2 = y

            tempimg = self.rgb_image.copy()
            cv2.rectangle(tempimg,(self.ix1,self.iy1),(self.ix2,self.iy2),(0,255,0),2)
            center_point = self.get_center_point()

            cv2.circle(tempimg, tuple(center_point.astype(int)), 3, (0,0,255),-1)
            cv2.imshow('RGB Image', tempimg)
            cv2.waitKey(5)
            self.rect_done = True
项目:thesis_scripts    作者:PhilippKopp    | 项目源码 | 文件源码
def click(event, x, y, flags, param):
    global current_landmark

    if event == cv2.EVENT_LBUTTONUP:
        current_landmark = [x, y]
项目:thesis_scripts    作者:PhilippKopp    | 项目源码 | 文件源码
def click(event, x, y, flags, param):
    global upper_left_point
    global lower_right_point
    global current_mouse_pos

    if event == cv2.EVENT_LBUTTONDOWN:
        upper_left_point = [x, y]

    if event == cv2.EVENT_LBUTTONUP:
        lower_right_point = [x, y]

    if event == cv2.EVENT_MOUSEMOVE:
        current_mouse_pos = [x, y]
项目:PyDLSSVM    作者:djosix    | 项目源码 | 文件源码
def reset_tracker(event, x, y, flags, param):
    global tracker, init_rect, is_cropping
    if event == cv2.EVENT_LBUTTONDOWN and not is_cropping:
        is_cropping = True
        init_rect[0:2] = [x, y]
    elif event == cv2.EVENT_LBUTTONUP and is_cropping:
        is_cropping = False
        init_rect[2:4] = [x, y]
        init_rect[0::2].sort()
        init_rect[1::2].sort()
        init_rect[2:4] -= init_rect[0:2]
        if all(init_rect[2:4] > [5, 5]):
            print("Reset target:", init_rect)
            tracker.set_target(init_rect)
项目:CVMazeRunner    作者:M-Niedoba    | 项目源码 | 文件源码
def get_mouse_point(event,x,y,flags,param):
    global point
    if event == cv2.EVENT_LBUTTONUP:
        print("Point {0},{1} selected".format(x,y))
        point = (x,y)
项目:hazcam    作者:alex-sherman    | 项目源码 | 文件源码
def on_click(plane, event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONUP:
        print((x, y), plane.get_plane_point(x, y))
项目: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()
项目: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
项目:ATX    作者:NetEaseGame    | 项目源码 | 文件源码
def on_mouse(event, x, y, flags, param):
        layout, downpos, ismove = param

        # record downpos
        if event == cv2.EVENT_LBUTTONDOWN:
            print 'click at', x*2, y*2 # picture is half-sized.
            param[1] = (x, y)
            param[2] = False
            return
        # check if is moving
        if event == cv2.EVENT_MOUSEMOVE:
            if ismove: return
            if downpos is None:
                param[2] = False
                return
            _x, _y = downpos
            if (_x-x)**2 + (_y-y)**2 > 64:
                param[2] = True
            return
        if event != cv2.EVENT_LBUTTONUP:
            return

        # update layout.highlight
        b = layout.tree.bounds
        l, t = b.left, b.top
        w, h = b.right - b.left, b.bottom - b.top
        highlight = np.zeros((h, w, 3), np.uint8)

        if downpos and ismove: # drag
            node = layout.find_scrollable_node(x*2+l, y*2+t)
            print 'scroll to', x*2, y*2
            if node:
                b = node.bounds
                print 'scrollable node', b, node.index, node.className,
                print 'resource_id:', node.resourceId,
                print 'text:', node.text.encode(encoding, 'ignore'),
                print 'desc:', node.description.encode(encoding, 'ignore')
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,255,255), 4)
        else:
            node = layout.find_clickable_node(x*2+l, y*2+t)
            if node:
                b = node.bounds
                print 'clickable node', b, node.index, node.className,
                print 'resource_id:', node.resourceId,
                print 'text:', node.text.encode(encoding, 'ignore'),
                print 'desc:', node.description.encode(encoding, 'ignore')
                print device(className=node.className, index=node.index).info
                cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,0,255), 4)
                cond, order = layout.find_selector(node)
                if cond:
                    print 'selector', cond, order
                    subnode = layout._filter_nodes(cond)[order or 0]
                    b = subnode.bounds
                    cv2.rectangle(highlight, (b.left-l, b.top-t), (b.right-l, b.bottom-t), (0,180,255), 4)

        param[0].highlight = highlight
        param[1], param[2] = None, False