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


Python Draw.ellipse方法代码示例

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


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

示例1: generate_captcha

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import ellipse [as 别名]
def generate_captcha(directory="tmp", letters=ascii_uppercase+digits,
        length=3, font_size=30, lines=5, mode="ellipse", font="FreeSerif.ttf"):
    """ Returns a tuple : (path, code) """
    dimensions = ((length + 1) * font_size, int(font_size * 2))
    path = "%s%s" % (os.path.join(directory, "".join(choice(ascii_letters) for
        i in xrange(7))), ".png")
    code = "".join(choice(letters) for i in range(length))
    background_color = tuple( [randrange(190, 230) for i in xrange(3)] )
    master = new_image("RGB", dimensions, background_color)

    # On colle les lettres
    for i, l in enumerate(code):
        img, mask = generate_letter(l, font_size, font)
        for _ in xrange(3):
            # On colle plusieurs fois pour plus de netteté
            master.paste(img, (font_size / 2 + font_size * i , font_size / 3),
                    mask)

    # Et on dessine quelques jolies lignes
    draw = Draw(master)
    for i in xrange(lines):
        color = tuple( [randrange(128, 190) for i in xrange(3)] )
        #pen = Pen("black", opacity=64)
        #pen.color = color
        w = dimensions[0]
        h = dimensions[1]
        geom = (randrange(0, int(w * 3. / 4)), randrange(0, h),
                randrange(int(w * 1. / 4), w), randrange(0, h))
        if mode == "mixed":
            mode_ = choice( ("ellipse", "line") )
        else:
            mode_ = mode
        if mode_ == "ellipse":
            draw.ellipse(geom, None, color)
        else:
            draw.line(geom, color, 1)
    with open(path, "w") as f:
        master.save(f)
    return (path, code)
开发者ID:jeanbon,项目名称:pycoblog,代码行数:41,代码来源:captcha.py

示例2: make_sure_path_exists

# 需要导入模块: from PIL.ImageDraw import Draw [as 别名]
# 或者: from PIL.ImageDraw.Draw import ellipse [as 别名]
make_sure_path_exists(overlay_path)

# Superimpose smoothed midlines on the (cropped) original image sequence
for i in range(Nf):
    shift = -offsets[i]
#    im = Image.open(original_images.format(i+1))
#    im = im.crop((0, 680, 2260, 680+810)) 
    im = open_png(sillhouette_path.format(i+1))
    im = Image.fromarray(im.astype(np.uint8)).convert('RGB')
    d = Draw(im)
    y = smid[:,i].astype(int)+shift[1]
    x = (np.arange(smid.shape[0])*end[i]/float(smid.shape[0]-1)).astype(int)+shift[0]
    d.line(zip(x,y), fill=(255,0,0), width=3 )
    tp = tip_locations[i]
    d.ellipse((tp[0]-1, tp[1]-1, tp[0]+1, tp[1]+1), fill=(0,0,255))
    im.save(overlay_path+'orig_{}.png'.format(i))


# Calculate scaling between transformed and y-coordinate
# in pixels - dy/di
sc = end / float(smid.shape[0]-1)

# Evaluate derivatives of the smoothed midline - dx/dy and d^2 x / dy^2
# Use scaling factor to give in terms of pixel coordinates
d = u(range(new_mid.shape[0]), range(new_mid.shape[1]), dx=1)/sc
dd = u(range(new_mid.shape[0]), range(new_mid.shape[1]), dx=2)/sc/sc


# Calculate distance 
# ds = ds / di. Use d^2 d/dy^2 = 1 + (dx/dy)^2 and dy/di = sc 
开发者ID:tuanthng,项目名称:RootAnalysis,代码行数:32,代码来源:optical_flow_analysis_d4.py


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