作家
登录

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

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

  •   
  • # Points from the second image to overlay on the first. The convex hull of each 
  • # element will be overlaid. 
  • OVERLAY_POINTS = [ 
  •     LEFT_EYE_POINTS + RIGHT_EYE_POINTS + LEFT_BROW_POINTS + RIGHT_BROW_POINTS, 
  •     NOSE_POINTS + MOUTH_POINTS, 
  •   
  • # Amount of blur to use during colour correction, as a fraction of the 
  • # pupillary distance. 
  • COLOUR_CORRECT_BLUR_FRAC = 0.6 
  •   
  • detector = dlib.get_frontal_face_detector() 
  • predictor = dlib.shape_predictor(PREDICTOR_PATH) 
  •   
  • class TooManyFaces(Exception): 
  •     pass 
  •   
  • class NoFaces(Exception): 
  •     pass 
  •   
  • def get_landmarks(im): 
  •     rects = detector(im, 1) 
  •   
  •     if len(rects) > 1: 
  •         raise TooManyFaces 
  •     if len(rects) == 0: 
  •         raise NoFaces 
  •   
  •     return numpy.matrix([[p.x, p.y] for p in predictor(im, rects[0]).parts()]) 
  •   
  • def annotate_landmarks(im, landmarks): 
  •     im = im.copy() 
  •     for idx, point in enumerate(landmarks): 
  •         pos = (point[0, 0], point[0, 1]) 
  •         cv2.putText(im, str(idx), pos, 
  •                     fontFace=cv2.FONT_HERSHEY_SCRIPT_SIMPLEX, 
  •                     fontScale=0.4, 
  •                     color=(0, 0, 255)) 
  •         cv2.circle(im, pos, 3, color=(0, 255, 255)) 
  •     return im 
  •   
  • def draw_convex_hull(im, points, color): 
  •     points = cv2.convexHull(points) 
  •     cv2.fillConvexPoly(im, points, color=color) 
  •   
  • def get_face_mask(im, landmarks): 
  •     im = numpy.zeros(im.shape[:2], dtype=numpy.float64) 

      推荐阅读

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

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


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

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

  • 关键词: 探索发现

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

    网友点评
    自媒体专栏

    评论

    热度

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