我试图将mediapipe中的face mesh模块转换为一个模块以供进一步使用,但我一直得到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()
1条答案
按热度按时间0lvr5msh1#
最好使用 named**parameters,而不是 positional parameters 来调用
FaceMesh
。当前代码在位置参数列表中至少缺少
refine_landmarks
布尔参数。在第14行中试试这个:
在我的测试中,您的代码开始处理帧。