未验证 提交 8ff47a50 编写于 作者: L LielinJiang 提交者: GitHub

fix type and lazy import dlib (#109)

上级 4baea348
......@@ -17,7 +17,7 @@ import os.path as osp
import numpy as np
from PIL import Image
import dlib
from paddle.utils import try_import
import cv2
from ..image import resize_by_max
from paddle.utils.download import get_weights_path_from_url
......@@ -26,6 +26,7 @@ LANDMARKS_WEIGHT_URL = 'https://paddlegan.bj.bcebos.com/models/lms.dat'
def detect(image: Image):
dlib = try_import('dlib')
image = np.asarray(image)
h, w = image.shape[:2]
image = resize_by_max(image, 361)
......@@ -43,6 +44,7 @@ def detect(image: Image):
def crop(image: Image, face, up_ratio, down_ratio, width_ratio):
dlib = try_import('dlib')
width, height = image.size
face_height = face.height()
face_width = face.width()
......@@ -96,6 +98,7 @@ def crop(image: Image, face, up_ratio, down_ratio, width_ratio):
def crop_by_image_size(image: Image, face):
dlib = try_import('dlib')
center = face.center()
width, height = image.size
if width > height:
......@@ -123,6 +126,7 @@ def crop_by_image_size(image: Image, face):
def landmarks(image: Image, face):
dlib = try_import('dlib')
weight_path = get_weights_path_from_url(LANDMARKS_WEIGHT_URL)
predictor = dlib.shape_predictor(weight_path)
shape = predictor(np.asarray(image), face).parts()
......@@ -130,6 +134,7 @@ def landmarks(image: Image, face):
def crop_from_array(image: np.array, face):
dlib = try_import('dlib')
ratio = 0.20 / 0.85 # delta_size / face_size
height, width = image.shape[:2]
face_height = face.height()
......
......@@ -4,4 +4,3 @@ scikit-image>=0.14.0
scipy>=1.1.0
opencv-python
imageio-ffmpeg
dlib
......@@ -15,7 +15,7 @@
from setuptools import setup
from io import open
with open('requirments.txt', encoding="utf-8-sig") as f:
with open('requirements.txt', encoding="utf-8-sig") as f:
requirements = f.readlines()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册