python-PIL 画出带有角度的椭圆

  • 最近在学习FDDB的人脸识别库,发现他们的标记是用椭圆来标记的,而且还是有角度的椭圆。
  • 在PIL库中好像并没有画出带有角度椭圆的函数,所以在StackOverflow上找到了如下代码:
def ellipse_with_angle(im,x,y,major,minor,angle,color):
    # take an existing image and plot an ellipse centered at (x,y) with a
    # defined angle of rotation and major and minor axes.
    # center the image so that (x,y) is at the center of the ellipse
    x -= int(major/2)
    y -= int(major/2)

    # create a new image in which to draw the ellipse
    im_ellipse = Image.new('RGBA', (major,major), (255,255,255,0))
    draw_ellipse = ImageDraw.Draw(im_ellipse, "RGBA")

    # draw the ellipse
    ellipse_box = (0,int(major/2-minor/2),major,int(major/2-minor/2)+minor)
    draw_ellipse.ellipse(ellipse_box, fill=color)

    # rotate the new image
    rotated = im_ellipse.rotate(angle)
    rx,ry = rotated.size

    # paste it into the existing image and return the result
    im.paste(rotated, (x,y,x+rx,y+ry), mask=rotated)
    return im
  • 效果还不错,如下图所示:
    image

  • 其实用matplotlib.patches.Ellipse也可以画出来,不过没办法转化成矩阵的形式,我主要是想判断selective search方法提取出来的方框判断是否是脸,给他们打上label。

  • 实验室就我一个人在瞎搞人脸识别,不知道我这样做的做法对不对,总感觉我姿势不对。。。
  • 如果有大神觉得有问题,请告诉我正确姿势。。谢谢
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值