我用手部跟踪模块和媒体管道编写的代码出错了

Posted

技术标签:

【中文标题】我用手部跟踪模块和媒体管道编写的代码出错了【英文标题】:The code I wrote with hand tracking module and mediapipe gives an error 【发布时间】:2022-01-21 00:26:53 【问题描述】:

当我合上手时,我正在关闭/打开视频的声音,但我在第一个代码中出现错误,这是什么原因?

我收到以下错误:

raceback (most recent call last):
  File "c:\Users\yegen\Desktop\ses denemeeeeee\sesdeneme2.py", line 15, in <module>    
    detector = htm.handDetector(detectionCon=0.5)
  File "c:\Users\yegen\Desktop\ses denemeeeeee\elizlememodulu.py", line 11, in __init__
    self.hands = self.mpHands.Hands(self.mode, self.maxHands,
  File "C:\Users\yegen\AppData\Local\Programs\Python\Python39\lib\site-packages\mediapipe\python\solutions\hands.py", line 114, in __init__  
    super().__init__(
  File "C:\Users\yegen\AppData\Local\Programs\Python\Python39\lib\site-packages\mediapipe\python\solution_base.py", line 258, in __init__    
    self._input_side_packets = 
  File "C:\Users\yegen\AppData\Local\Programs\Python\Python39\lib\site-packages\mediapipe\python\solution_base.py", line 259, in <dictcomp>  
    name: self._make_packet(self._side_input_type_info[name], data)
  File "C:\Users\yegen\AppData\Local\Programs\Python\Python39\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
[ WARN:0] global D:\a\opencv-python\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

这是我的代码:

import cv2
import time
import numpy as np 
import handtrackingmodule as htm
import math


###############################
wCam, hCam = 640, 480
###############################
cap = cv2.VideoCapture(0)
cap.set(3, wCam)
cap.set(4, hCam)

detector = htm.handDetector(detectionCon=0.5)

while True:
    success, img = cap.read()
    img = detector.findHands(img)
    
    cv2.imshow("İmg", img)
    cv2.waitKey(1)

【问题讨论】:

【参考方案1】:

试试这个

import cv2
import time
import numpy as np 
import handtrackingmodule as htm
import math


###############################
wCam, hCam = 640, 480
###############################
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
cap.set(3, wCam)
cap.set(4, hCam)

detector = htm.handDetector(detectionCon=0.5)

while True:
    success, img = cap.read()
    img = detector.findHands(img)
    
    cv2.imshow("İmg", img)
    cv2.waitKey(1)

cv2.destroyAllWindows()

【讨论】:

以上是关于我用手部跟踪模块和媒体管道编写的代码出错了的主要内容,如果未能解决你的问题,请参考以下文章

使用HTTP模块时出错 - 检测到的ASP.NET设置不适用于集成管理管道模式

Python:Scikit Learn MLPClassifier 放入管道时出错

android中没有Surface View的媒体管道中的地标扣除

将 Perl 与 xm_perl 模块一起使用时出错

在 pydroid3 中使用键盘模块和编写命令时出错

从共享文件夹导入 Angular 自定义管道时出错