无法分割框架并仍然将其用于地标

Unable to slice the frame and still use it for the landmarks

大家好,希望你们一切都好。我发现很难在 python 中使用 dlib 作为 faces = detector(gray) 来获取 x、y、h、w。这是下面的代码。提前谢谢你。

#load the detector
detector = dlib.get_frontal_face_detector()
#load the predictor
predictor = dlib.shape_predictor('shape_predictor/shape_predictor_68_face_landmarks.dat')
while True:
frame = webcam.read()
frame = imutils.resize(frame, width=450)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
 faces = detector(gray)
 for face in faces:
 #face landmarks
 landmarks = predictor(gray, face)
        
 x, y = face.left(), face.top()
 x1, y1 = face.right(), face.bottom()
 frame_img = frame[x,y,x1,y1]
 print(frame_img)

我认为你的错误在于这个表达式:frame[x,y,x1,y1]。尝试将其替换为:

frame_img = frame[y:y1,x:x1]