def draw_landmarks( image: np.ndarray, landmark_list: landmark_pb2.NormalizedLandmarkList, connections: Optional[List[Tuple[int, int]]] = None, landmark_drawing_spec: Union[DrawingSpec, Mapping[int, DrawingSpec]] = DrawingSpec( color=RED_COLOR), connection_drawing_spec: Union[DrawingSpec, Mapping[Tuple[int, int], DrawingSpec]] = DrawingSpec()):
这个是0.8版本的mediapipe的def_landmarks的函数使用方法,这个版本的FACECONNECTIONS使用不了。
import cv2 import mediapipe as mp import time cap =cv2.VideoCapture(0) ptime=0 mpDraw=mp.solutions.drawing_utils mpfacemesh=mp.solutions.face_mesh facemesh=mpfacemesh.FaceMesh(static_image_mode=True,max_num_faces=1,refine_landmarks=True,min_detection_confidence=0.5) draw_spec=mpDraw.DrawingSpec(thickness=2,circle_radius=1,color=[0,155,0]) while True: success,img =cap.read() imgRGB=cv2.cvtColor(img,cv2.COLOR_BGR2RGB) results=facemesh.process(imgRGB) if results.multi_face_landmarks: for facelms in results.multi_face_landmarks: mpDraw.draw_landmarks( image=img, landmark_list=facelms, connections=mpfacemesh.FACEMESH_CONTOURS, landmark_drawing_spec=draw_spec, connection_drawing_spec=draw_spec ) ctime=time.time() fps=1/(ctime-ptime) ptime=ctime cv2.putText(img,str(int(fps)),(20,70),cv2.FONT_HERSHEY_PLAIN,2,(0,0,255),3) cv2.imshow("face",img) cv2.waitKey(1)
你可以参考我的进行修改