extract_signals.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目: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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号