【问题标题】:TypeError: create_bool(): incompatible function arguments. The following argument types are supported: need someone's reviewTypeError: create_bool(): 不兼容的函数参数。支持以下参数类型:需要某人的评论
【发布时间】:2022-07-01 16:25:57
【问题描述】:

我正在尝试将面部网格模块从 mediapipe 转换为模块以供进一步使用,但我不断收到 TypeError: create_bool(): 不兼容的函数参数。支持以下参数类型:

以下是我的完整错误信息

Traceback (most recent call last):
  File "D:\Yashas Files\Sem 2\MP\FaceMeshModule.py", line 49, in <module>
    main()
  File "D:\Yashas Files\Sem 2\MP\FaceMeshModule.py", line 35, in main
    detector = FaceMeshDetector()
  File "D:\Yashas Files\Sem 2\MP\FaceMeshModule.py", line 14, in __init__
    self.faceMesh = self.mpFaceMesh.FaceMesh(self.staticMode, self.noFaces, self.minDetectCon, self.minTrackCon)
  File "D:\Yashas Files\Sem 2\MP\venv\lib\site-packages\mediapipe\python\solutions\face_mesh.py", line 94, in __init__
    super().__init__(
  File "D:\Yashas Files\Sem 2\MP\venv\lib\site-packages\mediapipe\python\solution_base.py", line 274, in __init__
    self._input_side_packets = {
  File "D:\Yashas Files\Sem 2\MP\venv\lib\site-packages\mediapipe\python\solution_base.py", line 275, in <dictcomp>
    name: self._make_packet(self._side_input_type_info[name], data)
  File "D:\Yashas Files\Sem 2\MP\venv\lib\site-packages\mediapipe\python\solution_base.py", line 533, in _make_packet
    return getattr(packet_creator, 'create_' + packet_data_type.value)(data)
TypeError: create_bool(): incompatible function arguments. The following argument types are supported:
    1. (arg0: bool) -> mediapipe.python._framework_bindings.packet.Packet

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

这是完整的代码:我也通过添加模型复杂性进行了检查,但没有用。

import cv2
import mediapipe as mp
import time

class FaceMeshDetector():
    def __init__(self,staticMode=False, noFaces=2, minDetectCon=0.5, minTrackCon=0.5):
        self.staticMode = staticMode
        self.noFaces = noFaces
        self.minDetectCon = minDetectCon
        self.minTrackCon = minTrackCon

        self.mpDraw = mp.solutions.drawing_utils
        self.mpFaceMesh = mp.solutions.face_mesh
        self.faceMesh = self.mpFaceMesh.FaceMesh(self.staticMode, self.noFaces, self.minDetectCon, self.minTrackCon)
        self.drawingSpec = self.mpDraw.DrawingSpec(thickness=1, circle_radius=1)

    def findFaces(self, img, draw=True):
        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        self.results = self.faceMesh.process(imgRGB)

        if self.results.multi_face_landmarks:
            for id, faceLm in enumerate(self.results.multi_face_landmarks):
                self.mpDraw.draw_landmarks(img, faceLm, self.mpFaceMesh.FACEMESH_TESSELATION)
                #for id,lm in enumerate(faceLm.landmark):
                 #  ih, iw, ic = img.shape
                  #  x,y = int(lm.x * iw), int(lm.y * ih)
                   # #print(id,x,y)
        return img



def main():
    cap = cv2.VideoCapture(0)
    pTime = 0
    detector = FaceMeshDetector()
    while True:
        success, img = cap.read()
        img = detector.findFaces(img)

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

        cv2.putText(img, f'FPS: {int(fps)}', (10, 70), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0, 0), 2)

        cv2.imshow("Image", img)
        cv2.waitKey(1)
if __name__ == "__main__":
    main()

【问题讨论】:

  • 您好,欢迎来到堆栈溢出,请提供完整的错误输出,以便更好地了解错误发生的位置。
  • 将代码放入正确的缩进 - 目前我们无法运行它,也无法说出错误的缩进在哪里。

标签: python opencv mediapipe


【解决方案1】:

最好使用命名参数而不是位置参数调用FaceMesh

您当前的代码在位置参数列表中至少缺少refine_landmarks 布尔参数。

在第 14 行试试这个:

self.faceMesh = self.mpFaceMesh.FaceMesh(
    static_image_mode=self.staticMode,
    max_num_faces=self.noFaces,
    min_detection_confidence=self.minDetectCon,
    min_tracking_confidence=self.minTrackCon)

在我的测试中,您的代码开始处理帧。

【讨论】:

  • 没用,同样报错
  • @Yashas BM:我在第 14 行添加了一个如何使用命名参数的代码示例。请检查!
  • @Yashas BM:这解决了你的问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-09
  • 2018-09-07
  • 1970-01-01
  • 2021-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多