作家
登录

小200行Python代码做了一个换脸程序

作者: 来源: 2018-03-22 17:06:36 阅读 我要评论

  •   
  •     for group in OVERLAY_POINTS: 
  •         draw_convex_hull(im, 
  •                          landmarks[group], 
  •                          color=1) 
  •   
  •     im = numpy.array([im, im, im]).transpose((1, 2, 0)) 
  •   
  •     im = (cv2.GaussianBlur(im, (FEATHER_AMOUNT, FEATHER_AMOUNT), 0) > 0) * 1.0 
  •     im = cv2.GaussianBlur(im, (FEATHER_AMOUNT, FEATHER_AMOUNT), 0) 
  •   
  •     return im 
  •   
  • def transformation_from_points(points1, points2): 
  •     ""
  •     Return an affine transformation [s * R | T] such that: 
  •         sum ||s*R*p1,i + T - p2,i||^2 
  •     is minimized. 
  •     ""
  •     # Solve the procrustes problem by subtracting centroids, scaling by the 
  •     # standard deviation, and then using the SVD to calculate the rotation. See 
  •     # the following for more details: 
  •     #   https://en.wikipedia.org/wiki/Orthogonal_Procrustes_problem 
  •   
  •     points1 = points1.astype(numpy.float64) 
  •     points2 = points2.astype(numpy.float64) 
  •   
  •     c1 = numpy.mean(points1, axis=0) 
  •     c2 = numpy.mean(points2, axis=0) 
  •     points1 -= c1 
  •     points2 -= c2 
  •   
  •     s1 = numpy.std(points1) 
  •     s2 = numpy.std(points2) 
  •     points1 /= s1 
  •     points2 /= s2 
  •   
  •     U, S, Vt = numpy.linalg.svd(points1.T * points2) 
  •   
  •     # The R we seek is in fact the transpose of the one given by U * Vt. This 
  •     # 

      推荐阅读

      蜜月期还没过完 苹果就要和三星分手了

    全平易近充电节 | 3月26日~30日 2000位IT行业拭魅战专家邀请你一路充电进修! 作为手机阵营的两大年夜巨擘,苹不雅和三星因为一部iPhone X走在了一路,两边都大年夜中获得了本身想要的器械>>>详细阅读


    本文标题:小200行Python代码做了一个换脸程序

    地址:http://www.17bianji.com/lsqh/40825.html

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)