本文整理汇总了Python中dlib.image_window方法的典型用法代码示例。如果您正苦于以下问题:Python dlib.image_window方法的具体用法?Python dlib.image_window怎么用?Python dlib.image_window使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dlib
的用法示例。
在下文中一共展示了dlib.image_window方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_landmarks
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import image_window [as 别名]
def display_landmarks(img, dets, shapes):
win = dlib.image_window()
win.clear_overlay()
win.set_image(img)
for shape in shapes:
win.add_overlay(shape)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
示例2: get_face
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import image_window [as 别名]
def get_face(filename):
# Create a HOG face detector using the built-in dlib class
predictor_model = "shape_predictor_68_face_landmarks.dat"
face_detector = dlib.get_frontal_face_detector()
face_pose_predictor = dlib.shape_predictor(predictor_model)
face_aligner = openface.AlignDlib(predictor_model)
win = dlib.image_window()
# Load the image into an array
image = io.imread(filename)
# Run the HOG face detector on the image data.
# The result will be the bounding boxes of the faces in our image.
detected_faces = face_detector(image, 1)
# Open a window on the desktop showing the image
win.set_image(image)
# Loop through each face we found in the image
for i, face_rect in enumerate(detected_faces):
# Detected faces are returned as an object with the coordinates
# of the top, left, right and bottom edges
face1 = image[face_rect.top():face_rect.bottom(), face_rect.left():face_rect.right()]
# Draw a box around each face we found
win.add_overlay(face_rect)
# Get the the face's pose
pose_landmarks = face_pose_predictor(image, face_rect)
alignedFace = face_aligner.align(534, image, face_rect, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
# Draw the face landmarks on the screen.
win.add_overlay(pose_landmarks)
return face1, alignedFace
#----------------------------------------------------------------------------------------
示例3: transform
# 需要导入模块: import dlib [as 别名]
# 或者: from dlib import image_window [as 别名]
def transform(args, files):
detector = dlib.get_frontal_face_detector()
if args.window:
win = dlib.image_window()
progress = 1
count = len(files)
for line in files:
print("Processing file: {} {}/{}".format(line, progress, count))
progress += 1
img = io.imread(line)
dets, scores, idx = detector.run(img, 1, args.threshold)
print("Number of faces detected: {}".format(len(dets)))
if args.ignore_multi and len(dets) > 1:
print("Skipping image with more then one face")
continue
if len(dets) == 0:
print('Skipping image as no faces found')
continue
d = dets[0]
(ymax, xmax, _) = img.shape
g = args.grow
l, t, r, b = max(d.left()-g, 0), max(d.top()-g, 0), \
min(d.right()+g, xmax), min(d.bottom()+g, ymax)
# Proportion check
if ((r-l)*(b-t))/(xmax * ymax) < args.min_proportion:
print('Image proportion too small, skipping')
if args.window:
win.clear_overlay()
win.set_image(img)
win.add_overlay(dets)
dlib.hit_enter_to_continue()
img = img[np.arange(t, b),:,:]
img = img[:, np.arange(l, r), :]
if args.resize:
img = skimage.transform.resize(img,
(args.row_resize, args.col_resize))
io.imsave(args.o + '/' + os.path.basename(line), img)