資源簡介
使用python dlib+openCV實現人臉融合,通用語python2和python3
代碼片段和文件信息
#!/usr/bin/python3
#?Copyright?(c)?2015?Matthew?Earl
#?
#?Permission?is?hereby?granted?free?of?charge?to?any?person?obtaining?a?copy
#?of?this?software?and?associated?documentation?files?(the?“Software“)?to?deal
#?in?the?Software?without?restriction?including?without?limitation?the?rights
#?to?use?copy?modify?merge?publish?distribute?sublicense?and/or?sell
#?copies?of?the?Software?and?to?permit?persons?to?whom?the?Software?is
#?furnished?to?do?so?subject?to?the?following?conditions:
#?
#?????The?above?copyright?notice?and?this?permission?notice?shall?be?included
#?????in?all?copies?or?substantial?portions?of?the?Software.
#?
#?????THE?SOFTWARE?IS?PROVIDED?“AS?IS“?WITHOUT?WARRANTY?OF?ANY?KIND?EXPRESS
#?????OR?IMPLIED?INCLUDING?BUT?NOT?LIMITED?TO?THE?WARRANTIES?OF
#?????MERCHANTABILITY?FITNESS?FOR?A?PARTICULAR?PURPOSE?AND?NONINFRINGEMENT.?IN
#?????NO?EVENT?SHALL?THE?AUTHORS?OR?COPYRIGHT?HOLDERS?BE?LIABLE?FOR?ANY?CLAIM
#?????DAMAGES?OR?OTHER?LIABILITY?WHETHER?IN?AN?ACTION?OF?CONTRACT?TORT?OR
#?????OTHERWISE?ARISING?FROM?OUT?OF?OR?IN?CONNECTION?WITH?THE?SOFTWARE?OR?THE
#?????USE?OR?OTHER?DEALINGS?IN?THE?SOFTWARE.
“““
This?is?the?code?behind?the?Switching?Eds?blog?post:
????http://matthewearl.github.io/2015/07/28/switching-eds-with-python/
See?the?above?for?an?explanation?of?the?code?below.
To?run?the?script?you‘ll?need?to?install?dlib?(http://dlib.net)?including?its
Python?bindings?and?OpenCV.?You‘ll?also?need?to?obtain?the?trained?model?from
sourceforge:
????http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
Unzip?with?‘bunzip2‘?and?change?‘PREDICTOR_PATH‘?to?refer?to?this?file.?The
script?is?run?like?so:
????./faceswap.py??
If?successful?a?file?‘output.jpg‘?will?be?produced?with?the?facial?features
from?‘‘?replaced?with?the?facial?features?from?‘‘.
“““
import?cv2
import?dlib
import?numpy
import?sys
PREDICTOR_PATH?=?“/home/work/python/ttt/shape_predictor_68_face_landmarks.dat“
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
]
#?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_
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7617??2018-09-11?14:47??face.py
?????文件????????135??2018-09-11?14:52??readme.txt
????.......??99693937??2018-01-28?21:15??shape_predictor_68_face_landmarks.dat
-----------?---------??----------?-----??----
?????????????99701689????????????????????3
評論
共有 條評論