Dersler

View on GitHub
import cv2
import mediapipe as mp
mp.__version__
'0.10.14'
image = cv2.imread("image.jpg")
image=cv2.resize(image, dsize=None,fx=0.3, fy=0.3)
cv2.imshow('Image',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
mp_face_mesh = mp.solutions.face_mesh
face_mesh = mp_face_mesh.FaceMesh(
    static_image_mode=False,  # False for video/webcam
    max_num_faces=1,         # Adjust for multiple faces
    refine_landmarks=True,   # Get more detailed landmarks (468 points)
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5
)

cap = cv2.VideoCapture(0) 
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    # BGR to RGB
    rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    
    # detect face landmarks
    results = face_mesh.process(rgb_frame)

    if results.multi_face_landmarks:
        for face_landmarks in results.multi_face_landmarks:
            # Draw 468 landmarks
            for landmark in face_landmarks.landmark:
                x = int(landmark.x * frame.shape[1])
                y = int(landmark.y * frame.shape[0])
                cv2.circle(frame, (x, y), 1, (0, 255, 0), -1)  # Green dot

    cv2.imshow('Face Landmarks', frame)

    # press 'q' to exit 
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
import cv2
import mediapipe as mp


mp_pose = mp.solutions.pose
mp_drawing = mp.solutions.drawing_utils  # For drawing landmarks

pose = mp_pose.Pose(
    static_image_mode=False,       # False for video/webcam
    model_complexity=1,            # 0=Fast, 1=Medium, 2=High accuracy
    smooth_landmarks=True,         # Smoothens pose landmarks
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5
)

cap = cv2.VideoCapture(0) 
while cap.isOpened():
    success, frame = cap.read()
    if not success:
        break
    rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    
    results = pose.process(rgb_frame)

    # Draw pose landmarks on the frame
    if results.pose_landmarks:
        mp_drawing.draw_landmarks(
            frame,
            results.pose_landmarks,
            mp_pose.POSE_CONNECTIONS,  # Draws connections between landmarks
            landmark_drawing_spec=mp_drawing.DrawingSpec(
                color=(0, 255, 0),    # Landmark color (Green)
                thickness=2,
                circle_radius=2
            ),
            connection_drawing_spec=mp_drawing.DrawingSpec(
                color=(255, 0, 0),    # Connection line color (Blue)
                thickness=2
            )
        )

    cv2.imshow('Pose Estimation', frame)

    # press 'q' to exit 
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

Kaynaklar