mediapipe icon indicating copy to clipboard operation
mediapipe copied to clipboard

Can you output the confidence of each key point? Please let us know if you can. Thank you.

Open lucker26 opened this issue 1 year ago • 1 comments

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

windows11

Python Version

3.8

MediaPipe Model Maker version

No response

Task name (e.g. Image classification, Gesture recognition etc.)

手势识别

Describe the actual behavior

想要输出每个关键点的置信度

Describe the expected behaviour

得到每个关键点的置信度

Standalone code/steps you may have used to try to get what you need

import cv2
import mediapipe as mp
import csv
import h5py
from datetime import datetime

mp_hands = mp.solutions.hands
hands = mp_hands.Hands(static_image_mode=False,
                       max_num_hands=4,
                       min_detection_confidence=0.5,
                       min_tracking_confidence=0.5)

mpDraw = mp.solutions.drawing_utils

def process_frame(img, csv_writer):
    img = cv2.flip(img, 1)
    img_RGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    results = hands.process(img_RGB)
    if results.multi_hand_landmarks:
        for hand_idx in range(len(results.multi_hand_landmarks)):
            hand_21 = results.multi_hand_landmarks[hand_idx]
            mpDraw.draw_landmarks(img, hand_21, mp_hands.HAND_CONNECTIONS, mp.solutions.drawing_styles.get_default_hand_landmarks_style(),
                                              mp.solutions.drawing_styles.get_default_hand_connections_style())
            if csv_writer is not None:
                row = [datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")]
                #print(row)
                for lm in hand_21.landmark:
                    confidence = lm.presence
                    row += [lm.x*img.shape[1], lm.y*img.shape[0]]
                    print(confidence)
                csv_writer.writerow(row)
                   
    return img

csv_file = open('hand_poses.csv', mode='w', newline='')
csv_writer = csv.writer(csv_file)
headers = ['timestamp']

for i in range(21):
    headers += [f'x_{i}', f'y_{i}']
csv_writer.writerow(headers)

cv2.VideoCapture(-1).release()
cap = cv2.VideoCapture(0)
cap.open(0)

while cap.isOpened():
    success, frame = cap.read()
    if not success:
        print('Error')
        break
    frame = process_frame(frame, csv_writer)
    cv2.imshow('my_window', frame)
    if cv2.waitKey(1) in [ord('q'), 27]:
        break

csv_file.close()
cap.release()
cv2.destroyAllWindows()

Other info / Complete Logs

No response

lucker26 avatar Nov 10 '23 03:11 lucker26

hi @lucker26 In what format the confidence output is expected, should we store in the hand_pose.csv ?

RomitSingh1999 avatar Feb 15 '24 15:02 RomitSingh1999

Hi @lucker26,

Apologies for the delay in response. Could you please confirm whether you still require assistance in resolving this issue or if it has been resolved from your end?

Thank you!!

kuaashish avatar Mar 27 '24 06:03 kuaashish

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

github-actions[bot] avatar Apr 04 '24 01:04 github-actions[bot]

This issue was closed due to lack of activity after being marked stale for past 7 days.

github-actions[bot] avatar Apr 12 '24 01:04 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Apr 12 '24 01:04 google-ml-butler[bot]