首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Python 3.7.9中使用opencv和mediapipe获取制作手部跟踪模块的错误

在Python 3.7.9中使用opencv和mediapipe获取制作手部跟踪模块的错误
EN

Stack Overflow用户
提问于 2021-10-30 17:50:56
回答 3查看 1.6K关注 0票数 0

每当我尝试运行我的代码时,我都会得到以下错误,我正在遵循手部跟踪的教程,我正确地遵循了步骤,但我仍然有一些错误。

视频链接:https://www.youtube.com/watch?v=01sAkU_NvOY&t=2100s

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "C:/Users/aryan/Desktop/user/Study/Com_vis/Hand_T_M.py", line 56, in <module>
    main()
  File "C:/Users/aryan/Desktop/user/Study/Com_vis/Hand_T_M.py", line 41, in main
    detector = handDetector()
  File "C:/Users/aryan/Desktop/user/Study/Com_vis/Hand_T_M.py", line 12, in __init__
    self.detectionCon, self.trackCon)
  File "C:\Users\aryan\Desktop\user\Study\Com_vis\venv\lib\site-packages\mediapipe\python\solutions\hands.py", line 127, in __init__
    outputs=['multi_hand_landmarks', 'multi_handedness'])
  File "C:\Users\aryan\Desktop\user\Study\Com_vis\venv\lib\site-packages\mediapipe\python\solution_base.py", line 260, in __init__
    for name, data in (side_inputs or {}).items()
  File "C:\Users\aryan\Desktop\user\Study\Com_vis\venv\lib\site-packages\mediapipe\python\solution_base.py", line 260, in <dictcomp>
    for name, data in (side_inputs or {}).items()
  File "C:\Users\aryan\Desktop\user\Study\Com_vis\venv\lib\site-packages\mediapipe\python\solution_base.py", line 513, in _make_packet
    return getattr(packet_creator, '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

Process finished with exit code 1

我无法弄清楚代码中的问题。我运行的是python 3.7.9,下面是我的代码。

文件名: Hand_T_M.py

代码语言:javascript
运行
复制
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(0)
    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()
EN

回答 3

Stack Overflow用户

发布于 2021-10-30 22:15:35

您需要使用正确的媒体接口,另请参阅this GitHub source code

代码语言:javascript
运行
复制
from mediapipe.python._framework_bindings import packet
票数 0
EN

Stack Overflow用户

发布于 2021-11-04 00:04:50

Python

  • 转至项目文件->设置->项目:-PyCharm ->单击到Python Python当前PyCharm mediapipe mediapipe以前的版本(在我的示例中为Python

或者,如果您可以使用pip命令执行此操作

  1. pip卸载mediapipe
  2. pip install mediapipe==0.8.8
票数 0
EN

Stack Overflow用户

发布于 2022-01-19 13:29:01

也许你可以试试这段代码。

代码语言:javascript
运行
复制
class handDetector():
    def __init__(self, mode=False, maxHands=3,complexity=1, detectionCon=0.5, trackCon = 0.5):
        self.mode = mode
        self.maxHands = maxHands
        self.complexity = complexity
        self.detectionCon = detectionCon
        self.trackCon = trackCon

        self.mpHands = mp.solutions.hands
        self.hands = self.mpHands.Hands(self.mode, self.maxHands,self.complexity, self.detectionCon, self.trackCon)
        self.mpDraw = mp.solutions.drawing_utils
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69780732

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档