本文整理汇总了Python中dlib.get_frontal_face_detector方法的典型用法代码示例。如果您正苦于以下问题:Python dlib.get_frontal_face_detector方法的具体用法?Python dlib.get_frontal_face_detector怎么用?Python dlib.get_frontal_face_detector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dlib
的用法示例。
在下文中一共展示了dlib.get_frontal_face_detector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def test(image_path, model_path):
'''Test the given model by showing the detected landmarks.
- image_path: the path of an image. Should contain a face.
- model_path: the path of a shape predictor model.
'''
image = cv2.imread(image_path)
face_detector = dlib.get_frontal_face_detector()
dets = face_detector(image, 1)
predictor = dlib.shape_predictor(model_path)
for d in dets:
cv2.rectangle(image, (d.left(), d.top()), (d.right(), d.bottom()), 255, 1)
shape = predictor(image, d)
for i in range(shape.num_parts):
p = shape.part(i)
cv2.circle(image, (p.x, p.y), 2, 255, 1)
cv2.putText(image, str(i), (p.x + 4, p.y), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (255, 255, 255))
cv2.imshow("window", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
# uncomment to test
# test("test_image.jpg", "shape_predictor.dat")
示例2: detect_face_rect_of_pts
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def detect_face_rect_of_pts(img_path,pts):
detector = dlib.get_frontal_face_detector()
# detect face using dlib
im = cv2.imread(img_path);
dets = detector(im, 1)
selected_det = None
pts_center = np.mean(pts,axis=0)
for det in dets:
if pts_center[0]>det.left() and pts_center[0]<det.right() and\
pts_center[1]>det.top() and pts_center[1]<det.bottom():
selected_det = det
if selected_det is None:
return None
left = selected_det.left()
top = selected_det.top()
width = selected_det.width()
height = selected_det.height()
return [left,top,width,height]
示例3: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def __init__(self, usage):
self.usage = usage
if self.usage == 'train':
print('loading train samples')
self.image_folder = image_folder
if os.path.isfile('data/train_triplets.json'):
with open('data/train_triplets.json', 'r') as file:
self.samples = json.load(file)
else:
self.samples = get_random_triplets('train')
else:
print('loading valid samples(LFW)')
self.image_folder = lfw_folder
with open('data/lfw_val_triplets.json', 'r') as file:
self.samples = json.load(file)
self.detector = dlib.get_frontal_face_detector()
self.sp = dlib.shape_predictor(predictor_path)
示例4: detect_fiducial_points
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def detect_fiducial_points(img, predictor_path):
"""
Detect face landmarks and return the mean points of left and right eyes.
If there are multiple faces in one image, only select the first one.
"""
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
dets = detector(img, 1)
if len(dets) < 1:
return []
for k, d in enumerate(dets):
shape = predictor(img, d)
break
landmarks = []
for i in range(68):
landmarks.append([shape.part(i).x, shape.part(i).y])
landmarks = np.array(landmarks)
left_eye = landmarks[36:42]
right_eye = landmarks[42:48]
mouth = landmarks[48:68]
return np.array([np.mean(left_eye, 0), np.mean(right_eye, 0)]).astype('int')
示例5: startCapture
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def startCapture(self):
self.setText("请稍候,正在初始化数据和摄像头。。。")
try:
# 检测相关
self.detector = dlib.get_frontal_face_detector()
self.predictor = dlib.shape_predictor(
"Data/shape_predictor_68_face_landmarks.dat")
cascade_fn = "Data/lbpcascades/lbpcascade_frontalface.xml"
self.cascade = cv2.CascadeClassifier(cascade_fn)
if not self.cascade:
return QMessageBox.critical(self, "错误", cascade_fn + " 无法找到")
self.cap = cv2.VideoCapture(0)
if not self.cap or not self.cap.isOpened():
return QMessageBox.critical(self, "错误", "打开摄像头失败")
# 开启定时器定时捕获
self.timer = QTimer(self, timeout=self.onCapture)
self.timer.start(1000 / self.fps)
except Exception as e:
QMessageBox.critical(self, "错误", str(e))
示例6: get_landmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def get_landmarks(img, resource_dir, verbose=False):
# if not automatically downloaded, get it from:
# http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
predictor_path = resource_dir + "/dlib_models/shape_predictor_68_face_landmarks.dat"
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
lmarks = []
dets = detector(img, 1)
if verbose:
print("Number of faces detected: {}".format(len(dets)))
shapes = []
for k, det in enumerate(dets):
shape = predictor(img, det)
shapes.append(shape)
xy = _shape_to_np(shape)
lmarks.append(xy)
lmarks = np.asarray(lmarks, dtype='float32')
# display_landmarks(img, dets, shapes)
return lmarks
示例7: face_detection
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def face_detection(self, frame):
'''
Detect faces in a frame
Args:
frame (cv2 image): a normal frame grab from camera or video
Outputs:
rects (array): detected faces as rectangles
'''
if self.detector is None:
self.detector = dlib.get_frontal_face_detector()
if frame is None:
return
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#get all faces in the frame
rects = self.detector(gray, 0)
# to get the coords from a rect, use: (x, y, w, h) = face_utils.rect_to_bb(rects[0])
return rects
示例8: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def __init__(self, facePredictor):
"""
Instantiate an 'AlignDlib' object.
:param facePredictor: The path to dlib's
:type facePredictor: str
"""
assert facePredictor is not None
#pylint: disable=no-member
self.detector = dlib.get_frontal_face_detector()
self.predictor = dlib.shape_predictor(facePredictor)
示例9: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def __init__(self, device, path_to_detector=None, verbose=False):
super().__init__(device, verbose)
base_path = os.path.join(appdata_dir('face_alignment'), "data")
# Initialise the face detector
if 'cuda' in device:
if path_to_detector is None:
path_to_detector = os.path.join(
base_path, "mmod_human_face_detector.dat")
if not os.path.isfile(path_to_detector):
print("Downloading the face detection CNN. Please wait...")
path_to_temp_detector = os.path.join(
base_path, "mmod_human_face_detector.dat.download")
if os.path.isfile(path_to_temp_detector):
os.remove(os.path.join(path_to_temp_detector))
request_file.urlretrieve(
"https://www.adrianbulat.com/downloads/dlib/mmod_human_face_detector.dat",
os.path.join(path_to_temp_detector))
os.rename(os.path.join(path_to_temp_detector), os.path.join(path_to_detector))
self.face_detector = dlib.cnn_face_detection_model_v1(path_to_detector)
else:
self.face_detector = dlib.get_frontal_face_detector()
示例10: monkey_patch_face_detector
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def monkey_patch_face_detector(_):
detector = dlib.get_frontal_face_detector()
class Rect(object):
def __init__(self,rect):
self.rect=rect
def detect( *args ):
return [ Rect(x) for x in detector(*args) ]
return detect
示例11: get_one_image
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def get_one_image(self, x, detector):
path_name_x = self.path + self.path_array[x-1]
try:
img_x = cv2.imread(path_name_x)
except IndexError:
print(path_name_x)
print('error')
else:
img_x_rgb = cv2.cvtColor(img_x, cv2.COLOR_BGR2RGB) # 转为RGB图片
face_align_rgb_x = detector.align(size, img_x_rgb)
if face_align_rgb_x is None:
det = dlib.get_frontal_face_detector()
gray_img = cv2.cvtColor(img_x, cv2.COLOR_BGR2GRAY)
# 使用detector进行人脸检测
dets = det(gray_img, 1)
if len(dets) > 0:
x1 = dets[0].top() if dets[0].top() > 0 else 0
y1 = dets[0].bottom() if dets[0].bottom() > 0 else 0
x2 = dets[0].left() if dets[0].left() > 0 else 0
y2 = dets[0].right() if dets[0].right() > 0 else 0
face = img_x[x1:y1, x2:y2]
else:
face = cv2.resize(img_x, (size, size))
face_align_x = cv2.resize(face, (size, size))
else:
face_align_x = cv2.cvtColor(face_align_rgb_x, cv2.COLOR_RGB2BGR) # 转为BGR图片
x_img = np.array(face_align_x)
x_img = x_img.astype('float32') / 255.0
return x_img
示例12: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def __init__(self, facePredictor):
"""
Instantiate an 'AlignDlib' object.
:param facePredictor: The path to dlib's
:type facePredictor: str
"""
assert facePredictor is not None
self.detector = dlib.get_frontal_face_detector()
self.predictor = dlib.shape_predictor(facePredictor)
示例13: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def __init__(self, MDE: MainData):
self.md = MDE
self.detector = dlib.get_frontal_face_detector()
self.sp = dlib.shape_predictor("shape_predictor_5_face_landmarks.dat")
示例14: detector
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def detector(self):
"""
检测是否有人脸
:return:
"""
return get_frontal_face_detector()
开发者ID:tomoncle,项目名称:face-detection-induction-course,代码行数:8,代码来源:input_static_pic_to_gif2_for_class.py
示例15: __init__
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import get_frontal_face_detector [as 别名]
def __init__(self, saved=False):
self.saved = saved # 是否保存图片
self.listener = True # 启动参数
self.video_capture = cv2.VideoCapture(0) # 调用本地摄像头
self.doing = False # 是否进行面部面具
self.speed = 0.1 # 面具移动速度
self.detector = get_frontal_face_detector() # 面部识别器
self.predictor = shape_predictor("shape_predictor_68_face_landmarks.dat") # 面部分析器
self.fps = 4 # 面具存在时间基础时间
self.animation_time = 0 # 动画周期初始值
self.duration = self.fps * 4 # 动画周期最大值
self.fixed_time = 4 # 画图之后,停留时间
self.max_width = 500 # 图像大小
self.deal, self.text, self.cigarette = None, None, None # 面具对象