python - How to overlay facial keypoints from Dlib in an OpenCV window -


i'm working on facial recognition project dlib, , managed return me list of facial keypoints in addition formed image:

relevant code:

def get_landmarks(im):     rects = detector(im, 1)      if len(rects) > 1:         raise toomanyfaces     if len(rects) == 0:         raise nofaces      return numpy.matrix([[p.x, p.y] p in predictor(im, rects[0]).parts()])   f in glob.glob(os.path.join(faces_folder_path, "*")):     print("processing file: {}".format(f))     img = io.imread(f)      win.clear_overlay()     win.set_image(img)      dets = detector(img, 1)     print("number of faces detected: {}".format(len(dets)))     k, d in enumerate(dets):         # landmarks/parts face in box d.         shape = predictor(img, d)         lms = get_landmarks(img)         print ("detection {}: left: {} top: {} right: {} bottom: {}".format(k, d.left(), d.top(), d.right(), d.bottom()))         print ("part 0: {}, part 1: {} ...".format(shape.part(0), shape.part(1)))         newsection()         print ("keypoints:" + (str(lms)))         # draw face landmarks on screen.         win.add_overlay(shape) 

result:

enter image description here now, need overlay them image, , that's ran problem. overlay code got matthew earl on github:

def annotate_landmarks(im, landmarks):     im = im.copy()     idx, point in enumerate(landmarks):         pos = (point[0, 0], point[0, 1])         cv2.puttext(im, str(idx), pos,                     fontface=cv2.font_hershey_script_simplex,                     fontscale=0.4,                     color=(0, 0, 255))         cv2.circle(im, pos, 3, color=(0, 255, 255))     return im 

isn't integrating right rest of code:

win.add_overlay(dets) iwl = annotate_landmarks(img, lms) cv2.imshow("landmarks", iwl) dlib.hit_enter_to_continue() 

and when try display it, gives me tiny gray window nothing in it:

imb = im.copy() idx, point in enumerate(lms):     pos = (point[0, 0], point[0, 1])     cv2.puttext(imb, str(idx), pos,                 fontface=cv2.font_hershey_script_simplex,                 fontscale=0.4,                 color=(0, 0, 255))     cv2.circle(im, pos, 3, color=(0, 255, 255))      width = 1000     height = 1000      cv2.namedwindow('image', cv2.window_normal)     cv2.imshow('image', img)     cv2.resizewindow('image', width, height)   

can show me i'm doing wrong here? need display points on image, this

edit: rest of code:

import sys import os import dlib import cv2 import glob import numpy skimage import io    predictor_path = sys.argv[1] faces_folder_path = sys.argv[2]  detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(predictor_path) win = dlib.image_window()   predictor_path = sys.argv[1] faces_folder_path = sys.argv[2]  detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(predictor_path) win = dlib.image_window() def newsection():  def terminal_size():         import fcntl, termios, struct      h, w, hp, wp = struct.unpack('hhhh',          fcntl.ioctl(0, termios.tiocgwinsz,             struct.pack('hhhh', 0, 0, 0, 0)))         return w  ter_int = terminal_size()  print ("\n" + ("_" * (int(ter_int))) + "\n\n")   def get_landmarks(im):  rects = detector(im, 1)      if len(rects) > 1:       raise toomanyfaces     if len(rects) == 0:         raise nofaces   return numpy.matrix([[p.x, p.y] p in predictor(im, rects[0]).parts()])    f in glob.glob(os.path.join(faces_folder_path, "*")):  print("processing file: {}".format(f))  img = io.imread(f)     win.clear_overlay() #    win.set_image(img)      dets = detector(img, 1)  print("number of faces detected: {}".format(len(dets)))     k, d in enumerate(dets):         # landmarks/parts face in box d.         shape = predictor(img, d)         lms = get_landmarks(img)         print ("detection {}: left: {} top: {} right: {} bottom: {}".format(k, d.left(), d.top(), d.right(), d.bottom()))         print ("part 0: {}, part 1: {} ...".format(shape.part(0), shape.part(1)))         newsection()         print ("keypoints:" + (str(lms)))         # draw face landmarks on screen. #        win.add_overlay(shape)        win.add_overlay(dets) #    iwl = annotate_landmarks(img, lms) #    cv2.imshow("landmarks", iwl)     dlib.hit_enter_to_continue()  imb = im.copy() idx, point in enumerate(lms):  pos = (point[0, 0], point[0, 1])  cv2.puttext(imb, str(idx), pos,                 fontface=cv2.font_hershey_script_simplex,                 fontscale=0.4,                 color=(0, 0, 255))   cv2.circle(im, pos, 3, color=(0, 255, 255))    width = 1000   height = 1000    cv2.namedwindow('image', cv2.window_normal)    cv2.imshow('image', imb)     cv2.resizewindow('image', width, height)