Richard8Yang / mediapipe_ios_test

0 stars 1 forks source link

How to get the Face Landmark、Hand Landmark and Body Landmark with the Framework? #1

Open Epoch2022-iOS opened 1 year ago

Epoch2022-iOS commented 1 year ago

Hello, I'm developer with an iOS application, Now I need Use MediaPipe Holistic To Tracking human body、face and hands, I try to Run the Example Demo and get the realtime pixelBuffer, But I can't get the Face Landmark、Hand Landmark and Body Landmark with the code.

I need your help now to get that landmark.

Before that, I found one that could be accessed Face pose_transform_matrix Demo,get face pose_transform_matrix demo link

language:Swift/Objective-C Xcode Version:14.0.1 Device:IPhone 12 Pro Max

Richard8Yang commented 1 year ago

I use a custom built mediapipe framework in this demo. Looks like only output video is exported, but the landmarks are not yet. I'm going to add the landmarks output and update the repo these days.

Epoch2022-iOS commented 1 year ago

thanks, we need output the data with funtion: - (void)mediapipeGraph:(MPPGraph*)graph didOutputPacket:(const ::mediapipe::Packet&)packet fromStream:(const std::string&)streamName{···detail method··}

detail method: `if (streamName == kMultiFaceGeometryStream) { if (packet.IsEmpty()) { NSLog(@"没有检测到脸部"); return; } const auto& multiFaceGeometry = packet.Get<std::vector<::mediapipe::face_geometry::FaceGeometry>>();

    for (int faceIndex = 0; faceIndex < multiFaceGeometry.size(); ++faceIndex) {
        const auto& faceGeometry = multiFaceGeometry[faceIndex];
        const auto& t = faceGeometry.pose_transform_matrix().packed_data();
        const auto& matrix = simd_matrix(
            (simd_float4){ t[0],  t[1],  t[2],  t[3] },
            (simd_float4){ t[4],  t[5],  t[6],  t[7] },
            (simd_float4){ t[8],  t[9],  t[10], t[11] },
            (simd_float4){ t[12], t[13], t[14], t[15] }
        );

        [_delegate tracker: self didOutputTransform: matrix withFace: faceIndex];
    }

}else if (streamName == kLandmarksOutputStream) {
    if (packet.IsEmpty()) {
        NSLog(@"没有检测到手部");
        return;
    }

    const auto& multiHandLandmarks = packet.Get<std::vector<::mediapipe::NormalizedLandmarkList>>();
    NSLog(@"[TS:%lld] 手部特征点: %lu", packet.Timestamp().Value(),
        multiHandLandmarks.size());

    for (int handIndex = 0; handIndex < multiHandLandmarks.size(); ++handIndex) {
        const auto& landmarks = multiHandLandmarks[handIndex];

        NSLog(@"\t手部特征点[%d]: %d", handIndex, landmarks.landmark_size());

        for (int i = 0; i < landmarks.landmark_size(); ++i) {
            NSLog(@"\t\tLandmark[%d]: (%f, %f, %f)", i, landmarks.landmark(i).x(),
                landmarks.landmark(i).y(), landmarks.landmark(i).z());
        }
    }
}`

for pose_transform_matrix and hand landmarks

if you can update , We would appreciate it very much. and We're willing to pay for it!