本文整理匯總了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 # 麵具對象