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


Python Image.clearLayers方法代码示例

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


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

示例1: visualize_consumer

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import clearLayers [as 别名]
def visualize_consumer(to):
    """A consumer that visualizes the data on an image

    :param TrackerOut to: A TrackerOut objects that receives data
    """
    img = Image((600, 600))
    while True:
        to.flush()
        img.clearLayers()
        for pos, timestamp in to:
            for finger in pos:
                if finger is not None:
                    img.dl().rectangle2pts((finger[0]-4, finger[1]-4),
                                           (finger[0]+4, finger[1]+4),
                                           color=Color.RED,
                                           filled=True)
            print "{}: {}".format(int(timestamp), pos)
            img.show()
        to.clear()
    del img
开发者ID:DenerosArmy,项目名称:asterisk,代码行数:22,代码来源:util.py

示例2: get_bounding_box

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import clearLayers [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

示例3: __init__

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import clearLayers [as 别名]
class Window2:
    generation = 0

    def __init__(self, filename, scale=1):
        filename = os.path.expanduser(filename)
        self.img = Image(filename)
        self.max_x, self.max_y = self.img.width, self.img.height
        self.scale = scale

        self.array_map = np.array([[0 for y in range(self.max_y)] for x in range(self.max_x)])
        for x in range(self.max_x):
            for y in range(self.max_y):
                pixel = self.img.getPixel(x, y)
                self.array_map[x][y] = (pixel == (255, 255, 255))

        # scale image
        self.img = self.img.resize(self.img.width*scale, self.img.height*scale)
        self.img_size = self.img.width, self.img.height

        self.display = Display(self.img_size)
        self.img.save(self.display)

    def dot(self, p, color=Color.WHITE, size=0):
        x, y = p[0], p[1]
        #print "Drawing robot particle at {}, {}".format(x, y)
        if x < 0 or x >= self.max_x:
            print "Oh my god! x=", x
            raise RuntimeError
        if y < 0 or y >= self.max_y:
            print "Oh shit! y=", y
            raise RuntimeError
        else:
            self.img.dl().circle(center=(x*self.scale, y*self.scale), radius=size, color=color, width=1, filled=True)

    def dot_red(self, p, color=Color.RED):
        self.dot(p, color, 2)

    def dots(self, coords, color=Color.WHITE, size=0):
        for (x, y) in coords:
            self.dot((x, y), color, size)

    def clear(self):
        self.img = Image(self.img_size)
        #self.display.clear()
        self.img.save(self.display)

    def clear_dl(self):
        self.img.clearLayers()
        self.img.save(self.display)

    def show(self):
        self.img.save(self.display)
        self.generation += 1
        print "Generation = {}".format(self.generation)
        self.wait_for_mouse()
        print "Mouse pressed!"

    def draw_robot(self, position, orientation):
        color = Color.RED
        #self.img.drawRectangle(p[0], p[1], 20, 40, color, 1)
        self.dot(position, color, 2)

        length = 20
        bx = int(round(position[0] + cos(orientation) * length))
        by = int(round(position[1] + sin(orientation) * length))

        self.vector(position, orientation, length, detect_collision=False, color=color)
        self.vector((bx, by), orientation - 3*pi/4, length=8, detect_collision=False, color=color)
        self.vector((bx, by), orientation + 3*pi/4, length=8, detect_collision=False, color=color)

    def vector(self, x, orientation, length, detect_collision=True, color=Color.FORESTGREEN):
        bx = int(round(x[0] + cos(orientation) * length))
        by = int(round(x[1] + sin(orientation) * length))
        #self.dot_red((bx, by))
        return self.line(x, (bx, by), detect_collision=detect_collision, color=color)
        #return bx, by

    # a = startpunkt, b = endpunkt
    #@profile
    def line(self, a, b, detect_collision=True, color=Color.BLUE):
        """http://en.wikipedia.org/wiki/Bresenham's_line_algorithm"""

        # performance => use local vars
        max_x = self.max_x
        max_y = self.max_y
        array_map = self.array_map

        x0, y0 = a
        x1, y1 = b
        dx = abs(x1-x0)
        dy = -abs(y1-y0)
        if x0 < x1:
            sx = 1
        else:
            sx = -1

        if y0 < y1:
            sy = 1
        else:
            sy = -1
#.........这里部分代码省略.........
开发者ID:tyunkeow,项目名称:raspi_python,代码行数:103,代码来源:robot_window.py


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