91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 74.11MB
    文件類型: .zip
    金幣: 2
    下載: 2 次
    發布日期: 2021-12-21
  • 語言: Python
  • 標簽: python??dlib??

資源簡介

如題,基于python和dlib的換臉工程。詳細請參考博客:http://blog.csdn.net/hongbin_xu/article/details/78878745。

資源截圖

代碼片段和文件信息

#coding=utf-8??
import?cv2
import?dlib
import?os
import?numpy?as?np
import?glob

current_path?=?os.getcwd()
predictor_68_points_path?=?current_path?+?‘/model/shape_predictor_68_face_landmarks.dat‘
predictor_5_points_path?=?current_path?+?‘/model/shape_predictor_5_face_landmarks.dat‘
predictor_path?=?predictor_68_points_path#?選取人臉68個特征點檢測器
face_path?=?current_path?+?‘/faces/‘

SCALE_FACTOR?=?1?
FEATHER_AMOUNT?=?11

FACE_POINTS?=?list(range(17?68))
MOUTH_POINTS?=?list(range(48?61))
RIGHT_BROW_POINTS?=?list(range(17?22))
LEFT_BROW_POINTS?=?list(range(22?27))
RIGHT_EYE_POINTS?=?list(range(36?42))
LEFT_EYE_POINTS?=?list(range(42?48))
NOSE_POINTS?=?list(range(27?35))
JAW_POINTS?=?list(range(0?17))

#?Points?used?to?line?up?the?images.
ALIGN_POINTS?=?(LEFT_BROW_POINTS?+?RIGHT_EYE_POINTS?+?LEFT_EYE_POINTS?+
???????????????????????????????RIGHT_BROW_POINTS?+?NOSE_POINTS?+?MOUTH_POINTS)

#?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
]

detector?=?dlib.get_frontal_face_detector()
predictor?=?dlib.shape_predictor(predictor_path)

class?TooManyFaces(Exception):
pass

class?NoFace(Exception):
pass

def?get_landmark(image):
face_rect?=?detector(image?1)

if?len(face_rect)?>?1:
print(‘Too?many?faces.We?only?need?no?more?than?one?face.‘)
raise?TooManyFaces
elif?len(face_rect)?==?0:
print(‘No?face.We?need?at?least?one?face.‘)
raise?NoFace
else:
print(‘left?{0};?top?{1};?right?{2};?bottom?{3}‘.format(face_rect[0].left()?face_rect[0].top()?face_rect[0].right()?face_rect[0].bottom()))
#?box?=?face_rect[0]
#?shape?=?predictor(image?box)
#?return?np.matrix([[p.x?p.y]?for?p?in?shape.parts()])
return?np.matrix([[p.x?p.y]?for?p?in?predictor(image?face_rect[0]).parts()])

def?test_get_landmark():
for?img_path?in?glob.glob(os.path.join(face_path?“*.jpg“)):
print(“Processing?file:?{}“.format(img_path))
img?=?cv2.imread(img_path?cv2.IMREAD_COLOR)
img?=?cv2.cvtColor(img?cv2.COLOR_BGR2RGB)
landmarks?=?get_landmark(img)
print?landmarks

def?transformation_from_points(points1?points2):
points1?=?points1.astype(np.float64)
points2?=?points2.astype(np.float64)

c1?=?np.mean(points1?axis=0)
c2?=?np.mean(points2?axis=0)
points1?-=?c1
points2?-=?c2

s1?=?np.std(points1)
s2?=?np.std(points2)
points1?/=?s1
points2?/=?s2

U?S?Vt?=?np.linalg.svd(points1.T?*?points2)
R?=?(U?*?Vt).T

return?np.vstack([np.hstack(((s2?/?s1)?*?R?c2.T?-?(s2?/?s1)?*?R?*?c1.T))?np.matrix([0.?0.?1.])])

def?warp_image(image?M?dshape):
output_image?=?np.zeros(dshape?dtype=image.dtype)
cv2.warpAffine(image?M[:2]?(dshape[1]?dshape[0])?dst=output_image?flags=cv2.WARP_INVERSE_MAP?borderMode=cv2.BORDER_TRANSPARENT)
return?output_image

def?test_warp_image():
jobs_image_path?=?os.path.join(face_path?“jobs2.jpg“)
obama_image_path?=?os.path.join

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-12-19?13:31??change_face\
?????文件????????7672??2017-12-19?13:30??change_face\FaceChanger.py
?????文件????????8436??2017-12-19?13:31??change_face\FaceChanger.pyc
?????文件???????10108??2017-12-23?12:46??change_face\change_face.py
?????文件????????5207??2017-12-17?14:11??change_face\change_face.pyc
?????目錄???????????0??2017-12-23?11:48??change_face\faces\
?????文件???????16149??2017-12-19?13:41??change_face\faces\ibrahimovic.jpg
?????文件???????10777??2017-12-18?21:26??change_face\faces\jobs.jpg
?????文件???????11933??2017-09-15?22:42??change_face\faces\jobs2.jpg
?????文件????????9861??2017-12-19?13:36??change_face\faces\messi.jpg
?????文件???????31096??2017-11-22?12:05??change_face\faces\messi2.jpg
?????文件???????35925??2017-09-15?21:19??change_face\faces\obama.jpg
?????文件???????23230??2017-11-22?14:15??change_face\faces\obama2.jpg
?????文件???????14799??2017-12-19?13:40??change_face\faces\pique.jpg
?????文件???????54033??2017-09-15?19:57??change_face\faces\silicon_valley.jpg
?????文件???????16930??2017-12-19?13:38??change_face\faces\suarez.jpg
?????文件????????8383??2017-12-18?22:14??change_face\faceswap.py
?????目錄???????????0??2017-11-12?13:29??change_face\model\
?????文件?????9150489??2017-11-12?13:29??change_face\model\shape_predictor_5_face_landmarks.dat
?????文件????99693937??2017-03-09?08:34??change_face\model\shape_predictor_68_face_landmarks.dat
?????文件???????22661??2017-12-23?13:06??change_face\output.jpg
?????文件?????????118??2017-12-23?13:02??change_face\test_FaceChanger.py

評論

共有 條評論