google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.5k stars 5.15k forks source link

results.multi_hand_landmarks looks like have no landmark attribute #4985

Closed an1ya1 closed 11 months ago

an1ya1 commented 11 months ago

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

None

OS Platform and Distribution

Windows11

Mobile device if the issue happens on mobile device

LG gram style

Browser and version if the issue happens on browser

No response

Programming Language and version

Python

MediaPipe version

0.8.6.2

Bazel version

No response

Solution

HandTrack

Android Studio, NDK, SDK versions (if issue is related to building in Android environment)

No response

Xcode & Tulsi version (if issue is related to building for iOS)

No response

Describe the actual behavior

detect the handpose

Describe the expected behaviour

to change the media's volume

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

I define a function in a HandTrackModule.py:
##############################################
def findPosition(self,img,handNo=0,draw=True):
        xList = []
        yList = []
        bbox = []
        self.lmList = []
        myHand = []
        # myHand = self.results.multi_hand_landmarks[0]

        if self.results and self.results.multi_hand_landmarks:
            myHand = self.results.multi_hand_landmarks[handNo]
        for id, lm in enumerate(myHand.landmark):
            # print(id, lm)
            h, w, c = img.shape
            cx, cy = int(lm.x * w), int(lm.y * h)
            xList.append(cx)
            yList.append(cy)
            # print(id, cx, cy)
            self.lmList.append([id, cx, cy])
            if draw:
                cv2.circle(img, (cx, cy), 5, (255, 0, 255), cv2.FILLED)
        xmin, xmax = min(xList), max(xList)
        ymin, ymax = min(yList), max(yList)
        bbox = xmin, ymin, xmax, ymax

        if draw:
            cv2.rectangle(img, (bbox[0] - 20, bbox[1] - 20),
            (bbox[2] + 20, bbox[3] + 20), (0, 255, 0), 2)

        return self.lmList, bbox
###############################################
then i use the functhion in VolumeHandControl.py just like:
##############################################
detector = htm.handDetector(detectionCon=0.7)
while True:
    success,img = cap.read()
    img = detector.findHands(img)
    lmList = detector.findPosition(img,draw=False)
##################################
But something went wrong, 
In prompt,it occurs File "d:\handTrackProject\HandTrackingModule.py", line 40, in findPosition
    for id,lm in enumerate(myHand.landmark):
AttributeError: 'list' object has no attribute 'landmark'

Other info / Complete Logs

No response

an1ya1 commented 11 months ago

I also use opencv4.5.1.48

an1ya1 commented 11 months ago

HandTrack.zip There are two python files in the zip file.One is the HandTrackingModule.py and the other one is the VolumeHandControl.py

kuaashish commented 11 months ago

Hi @an1ya1,

From the code snippet you provided, it appears you are using the legacy hands solution. Please note that this solution has been upgraded and is now integrated into the Hand Landmarker Task API, as explained in the documentation(We have discontinued support for upgraded legacy solutions, and we are no longer maintaining them).

The upgraded Task API's are designed to offer better performance compared to the legacy solutions and are easier to adopt for your use case. We encourage you to explore our new Hand Task API following the guidelines provided here. You can find the Python guide here, along with a Python notebook example. Additionally, Please let us know if you observe similar behaviour in the new Task API as well.

Thank you!!

an1ya1 commented 11 months ago

I am so grateful for you. I will try again 🥰

an1ya1 commented 11 months ago

Hi @an1ya1,

From the code snippet you provided, it appears you are using the legacy hands solution. Please note that this solution has been upgraded and is now integrated into the Hand Landmarker Task API, as explained in the documentation(We have discontinued support for upgraded legacy solutions, and we are no longer maintaining them).

The upgraded Task API's are designed to offer better performance compared to the legacy solutions and are easier to adopt for your use case. We encourage you to explore our new Hand Task API following the guidelines provided here. You can find the Python guide here, along with a Python notebook example. Additionally, Please let us know if you observe similar behaviour in the new Task API as well.

Thank you!!

I have read the guideline ,If should i use a model to make the performance better ,do you mean the api is the model 🤔 ?

kuaashish commented 11 months ago

Hi @an1ya1,

I did not quite get your recent question. Can you explain what you mean by "do you mean the API is the model" so I can understand it better?

Thank you

an1ya1 commented 11 months ago

Hi @an1ya1,

I did not quite get your recent question. Can you explain what you mean by "do you mean the API is the model" so I can understand it better?

Thank you

Do I need to download a new model to detect the posture of the hand?Because I haven't downloaded the model file before this

kuaashish commented 11 months ago

Hi @an1ya1,

Yes, Please download the task file from the provided link here(Click HandLandmarker (full)), input the path of file to model, and execute the example to identify hand landmarks.

Thank you!

an1ya1 commented 11 months ago

Hi @an1ya1,

Yes, Please download the task file from the provided link here(Click HandLandmarker (full)), input the path of file to model, and execute the example to identify hand landmarks.

Thank you!

OK,I understand it

kuaashish commented 11 months ago

Hi @an1ya1,

Could you kindly inform me if the issue is now resolved on your end? If so, may we proceed to mark it as resolved and close the matter?

Thank you

an1ya1 commented 11 months ago

Hi @an1ya1,

Could you kindly inform me if the issue is now resolved on your end? If so, may we proceed to mark it as resolved and close the matter?

Thank you

Yes,I have solved it.thank you 😊

google-ml-butler[bot] commented 11 months ago

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