Liu Bin 20000 vocabulary 02

2023-01-23   ES  

dlib.shape_predictor(args[‘shape_predictor’])
ARGS [‘Shape_predictor’] location information
Return to the trained face 68 feature point detector

predictor(gray, rect)
Gray input 8 -bit grayscale or RGB image
RECT Start the location information of the boundary frame of the internal face detection
Return to the location of 68 feature points

import dlib
import cv2

img = cv2.imread("image.jpg")

gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

detector = dlib.get_frontal_face_detector() 

dets = detector(gray_img, 1)

# Use a model to build a feature extractor
predictor = dlib.shape_predictor('data/data_dlib/shape_predictor_68_face_landmarks.dat/shape_predictor_68_face_landmarks.dat')

for i, d in enumerate(dets):
 # Use Predictor to perform a key point for face to detect Shape as the result of returning
    shape = predictor(gray_img, d)
    
    for index, pt in enumerate(shape.parts()):
        print('Part {}: {}'.format(index, pt))
        pt_pos = (pt.x, pt.y)
        cv2.circle(img, pt_pos, 1, (255, 0, 0), 2)
        # Use CV2.Puttext to mark the serial number
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(img, str(index+1),pt_pos,font, 0.3, (0, 0, 255), 1, cv2.LINE_AA)
 
cv2.imshow('img', img)
k = cv2.waitKey()
cv2.destroyAllWindows()

source

Related Posts

Use monodevelop in Ubuntu to develop .NET development

Easytouch3.1 Add step

RecylerView’s basic usage

jackson manual

Liu Bin 20000 vocabulary 02

Random Posts

Jiugong reunion

Knowledge accumulation: Java SpringBoot Multi -threaded JOB transmitted Header solution to solve the problem of header loss, springcloud feign transmission Header

Filbeat+Logstash configuration 2

MySQL uses mysqlbulkloader batch insertion

Android View’s fingers drag the suspended circle effect of iOS