当前位置: 首页>>代码示例>>Python>>正文


Python Display.leftButtonUpPosition方法代码示例

本文整理汇总了Python中SimpleCV.Display.leftButtonUpPosition方法的典型用法代码示例。如果您正苦于以下问题:Python Display.leftButtonUpPosition方法的具体用法?Python Display.leftButtonUpPosition怎么用?Python Display.leftButtonUpPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleCV.Display的用法示例。


在下文中一共展示了Display.leftButtonUpPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_bounding_box

# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import leftButtonUpPosition [as 别名]
def get_bounding_box(keyword, url, filename):
    # get the image
    img = Image(url)

    # resize the image so things aren't so slow, if necessary
    w, h = img.size()
    if w > 1200 or h > 1200:
        maxdim = max(w, h)
        ratio = math.ceil(maxdim/800.0)
        print "   resizing..."
        img = img.resize(w=int(w/ratio), h=int(h/ratio))
    else:
        ratio = 1

    # get the canvas
    disp = Display((800, 800))
    # text overlay
    textlayer = DrawingLayer(img.size())
    textlayer.setFontSize(30)
    cx, cy = 10, 10
    for xoff in range(-2, 3):
        for yoff in range(-2, 3):
            textlayer.text(keyword, (cx + xoff, cy + yoff), color=Color.BLACK)
    textlayer.text(keyword, (cx, cy), color=Color.WHITE)

    # two points to declare a bounding box
    point1 = None
    point2 = None
    while disp.isNotDone():
        cursor = (disp.mouseX, disp.mouseY)
        if disp.leftButtonUp:
            if point1 and point2:
                point1 = None
                point2 = None
            if point1:
                point2 = disp.leftButtonUpPosition()
            else:
                point1 = disp.leftButtonUpPosition()
        bb = None
        if point1 and point2:
            bb = disp.pointsToBoundingBox(point1, point2)
        elif point1 and not point2:
            bb = disp.pointsToBoundingBox(point1, cursor)

        img.clearLayers()
        drawlayer = DrawingLayer(img.size())
        if bb:
            drawlayer.rectangle((bb[0], bb[1]), (bb[2], bb[3]), color=Color.RED)

        # keyboard commands
        if pygame.key.get_pressed()[pygame.K_s]:
            # skip for now
            raise Skip()
        elif pygame.key.get_pressed()[pygame.K_b]:
            # mark it as an invalid picture
            raise BadImage()
        elif pygame.key.get_pressed()[pygame.K_RETURN]:
            if point1 and point2:
                bb = disp.pointsToBoundingBox(scale(ratio, point1), scale(ratio, point2))
                return bb
            elif not point1 and not point2:
                bb = disp.pointsToBoundingBox((0, 0), (w, h))
                return bb


        drawlayer.line((cursor[0], 0), (cursor[0], img.height), color=Color.BLUE)
        drawlayer.line((0, cursor[1]), (img.width, cursor[1]), color=Color.BLUE)
        #drawlayer.circle(cursor, 2, color=Color.BLUE, filled=True)
        img.addDrawingLayer(textlayer)
        img.addDrawingLayer(drawlayer)
        img.save(disp)
开发者ID:stephenroller,项目名称:imsgrounded,代码行数:73,代码来源:annotation.py

示例2:

# 需要导入模块: from SimpleCV import Display [as 别名]
# 或者: from SimpleCV.Display import leftButtonUpPosition [as 别名]
# main loop #

while not disp.isDone():

    img = cam.getImage()
    img = img.flipHorizontal()  # just for my convenience - simulates mirror :)

    if inVideoMode:
        (orig_h, orig_w) = (img.height, img.width)  # required for VideoStream

    px = disp.mouseX
    py = disp.mouseY

    left_down = disp.leftButtonDownPosition()  # grab coordinates for event press
    left_up = disp.leftButtonUpPosition()  # grab coordinates for event release

    if left_down is not None:  # left mouse button pressed
        # start drawing rectangle
        (lx, ly) = left_down

    if left_up is not None:  # left mouse button released
        # stop drawing rectangle, go into zoom mode
        (lx, ly) = (None, None)
        inZoomMode = True if not inZoomMode else False  # enter zooming mode
        zoom = (sx, sy, w, h)

    if inZoomMode:

        img = img.crop(zoom[0], zoom[1], zoom[2], zoom[3])
开发者ID:mkos,项目名称:cv.ex,代码行数:31,代码来源:feedzoom.py


注:本文中的SimpleCV.Display.leftButtonUpPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。