Modules.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:apparent-age-gender-classification 作者: danielyou0230 项目源码 文件源码
def debug_face_landmark(file, output=False, output_name='output'):
    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(dat_face_landmark)

    image = cv2.imread(file)
    image = imutils.resize(image, width=500)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    img_size = gray.shape

    faces = detector(gray, 1)
    for (i, itr_face) in enumerate(faces):
        shape = predictor(gray, itr_face)
        shape = shape_to_np(shape)
        # convert dlib's rectangle to a OpenCV-style bounding box
        # [i.e., (x, y, w, h)], then draw the face bounding box
        (x, y, w, h) = rect_to_bb(itr_face, img_size, file)
        #print "landmark: ({:d}, {:d}) ({:d}, {:d})".format(x, y, w, h)

        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
        # show the face number
        cv2.putText(image, "Face #{}".format(i + 1), (x - 10, y - 10),
            cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

        # loop over the (x, y)-coordinates for the facial landmarks
        # and draw them on the image
        for (x, y) in shape:
            cv2.circle(image, (x, y), 1, (0, 0, 255), -1)

    # show the output image with the face detections + facial landmarks
    cv2.imshow(file, image)
    cv2.waitKey(0)
    if output:
        cv2.imwrite("../" + str(output_name + 1) + '.jpg', image)
    cv2.destroyAllWindows()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号