Python dlib.image_window() Examples
The following are 3
code examples of dlib.image_window().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dlib
, or try the search function
.
Example #1
Source File: compare_similarity.py From WannaPark with GNU General Public License v3.0 | 5 votes |
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 #----------------------------------------------------------------------------------------
Example #2
Source File: facial_feature_detector.py From EmotionClassifier with GNU General Public License v3.0 | 5 votes |
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()
Example #3
Source File: face_detector.py From EmotionNet2 with GNU General Public License v3.0 | 4 votes |
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)