google-ai-edge / mediapipe

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

My code wont work after install mediapipe #2912

Closed ruadoVn closed 2 years ago

ruadoVn commented 2 years ago

Please make sure that this is a bug and also refer to the troubleshooting, FAQ documentation before raising any issues.

System information (Please provide as much relevant information as possible)

Describe the current behavior: The program wont work and this the log Traceback (most recent call last): File "/run/media/ruadovn/CODE/Python/SoundControl/test.py", line 16, in detector=htm.handDetector(detectionCon=0.55) File "/run/media/ruadovn/CODE/Python/SoundControl/hand.py", line 19, in init self.hands = self.mpHands.Hands(self.mode, self.maxHands, File "/run/media/ruadovn/CODE/Python/SoundControl/venv3.9/lib/python3.9/site-packages/mediapipe/python/solutions/hands.py", line 114, in init super().init( File "/run/media/ruadovn/CODE/Python/SoundControl/venv3.9/lib/python3.9/site-packages/mediapipe/python/solution_base.py", line 258, in init self._input_side_packets = { File "/run/media/ruadovn/CODE/Python/SoundControl/venv3.9/lib/python3.9/site-packages/mediapipe/python/solution_base.py", line 259, in name: self._make_packet(self._side_input_type_info[name], data) File "/run/media/ruadovn/CODE/Python/SoundControl/venv3.9/lib/python3.9/site-packages/mediapipe/python/solution_base.py", line 513, in _make_packet return getattr(packetcreator, 'create' + packet_data_type.value)(data) TypeError: create_int(): incompatible function arguments. The following argument types are supported:

  1. (arg0: int) -> mediapipe.python._framework_bindings.packet.Packet

Invoked with: 0.55 Describe the expected behavior: The program must run Standalone code to reproduce the issue: Provide a reproducible test case that is the bare minimum necessary to replicate the problem. If possible, please share a link to Colab/repo link /any notebook: """ Hand Module

"""

import cv2 import mediapipe as mp import time

class handDetector(): def init(self, mode=False, maxHands=2, detectionCon=0.5, trackCon=0.5): self.mode = mode self.maxHands = maxHands self.detectionCon = detectionCon self.trackCon = trackCon

    self.mpHands = mp.solutions.hands
    self.hands = self.mpHands.Hands(self.mode, self.maxHands,
                                    self.detectionCon, self.trackCon)
    self.mpDraw = mp.solutions.drawing_utils

def findHands(self, img, draw=True):
    imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    self.results = self.hands.process(imgRGB)
    # print(results.multi_hand_landmarks)

    if self.results.multi_hand_landmarks:
        for handLms in self.results.multi_hand_landmarks:
            if draw:
                self.mpDraw.draw_landmarks(img, handLms,
                                           self.mpHands.HAND_CONNECTIONS)
    return img

def findPosition(self, img, handNo=0, draw=True):

    lmList = []
    if 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)
            # print(id, cx, cy)
            lmList.append([id, cx, cy])
            if draw:
                cv2.circle(img, (cx, cy), 15, (255, 0, 255), cv2.FILLED)

    return lmList

def main(): pTime = 0 cTime = 0 cap = cv2.VideoCapture(1) detector = handDetector() while True: success, img = cap.read() img = detector.findHands(img) lmList = detector.findPosition(img) if len(lmList) != 0: print(lmList[4])

    cTime = time.time()
    fps = 1 / (cTime - pTime)
    pTime = cTime

    cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3,
                (255, 0, 255), 3)

    cv2.imshow("Image", img)
    cv2.waitKey(1)

if name == "main": main() Other info / Complete Logs : Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached

sgowroji commented 2 years ago

Because Hand's init method now has 5 params (see https://github.com/google/mediapipe/blob/master/mediapipe/python/solutions/hands.py#L89) and the third parameter is model_complexity, which is an int. Please modify your code accordingly.

google-ml-butler[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

google-ml-butler[bot] commented 2 years ago

Closing as stale. Please reopen if you'd like to work on this further.

google-ml-butler[bot] commented 2 years ago

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

yoyojacky commented 2 years ago

python 3.10 mediapipe : 0.8.9.1 Same result : D:\Pycharm-Projects\venv\Scripts\python.exe D:/Pycharm-Projects/Opencv-Sample/020-HandDetectionGame.py Traceback (most recent call last): File "D:\Pycharm-Projects\Opencv-Sample\020-HandDetectionGame.py", line 9, in detector = htm.handDetector() File "D:\Pycharm-Projects\Opencv-Sample\HandTrackingModule.py", line 13, in init self.hands = self.mpHands.Hands(self.mode, self.maxHands, self.detectionCon, self.trackCon) File "D:\Pycharm-Projects\venv\lib\site-packages\mediapipe\python\solutions\hands.py", line 114, in init super().init( File "D:\Pycharm-Projects\venv\lib\site-packages\mediapipe\python\solution_base.py", line 258, in init self._input_side_packets = { File "D:\Pycharm-Projects\venv\lib\site-packages\mediapipe\python\solution_base.py", line 259, in name: self._make_packet(self._side_input_type_info[name], data) File "D:\Pycharm-Projects\venv\lib\site-packages\mediapipe\python\solution_base.py", line 513, in _make_packet return getattr(packetcreator, 'create' + packet_data_type.value)(data) TypeError: create_int(): incompatible function arguments. The following argument types are supported:

  1. (arg0: int) -> mediapipe.python._framework_bindings.packet.Packet

Invoked with: 0.5 [ WARN:0@2.635] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (539) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback