Mediapipe人脸与姿态检测模块调用时出现TypeError位置参数缺失问题求助
What's Causing the Error?
This is a classic class instantiation mistake. In your main() function, you have:
detector = FaceDetector
This line assigns the class itself to detector, not an instance of the class. When you call detector.findFaces(vid), Python tries to pass the class as the self parameter (which all instance methods require), but then expects the vid parameter as the next argument—hence the error saying vid is missing.
The Fix
All you need to do is add parentheses to create an instance of FaceDetector:
detector = FaceDetector()
Now detector is a proper instance of your class. When you call detector.findFaces(vid), Python automatically passes the instance as the self parameter, and your vid argument is correctly recognized as the second parameter the method needs.
Bonus Check
I noticed a minor inconsistency in your code: in the error trace, you had vid = detector.findFaces(vid), but in your code snippet it's vid, bboxs = detector.findFaces(vid). Either way, once you fix the instantiation, this line will work as intended since your findFaces method returns both the video frame and bounding boxes.
Fixed main() Function
Here's the corrected main() function for clarity:
def main(): cap = cv.VideoCapture(0) pTime = 0 detector = FaceDetector() # Critical: parentheses added here while True: suc, vid = cap.read() vid, bboxs = detector.findFaces(vid) cTime = time.time() fps = 1 / (cTime - pTime) pTime = cTime cv.putText(vid, f'FPS:{int(fps)}', (20, 70), cv.FONT_HERSHEY_PLAIN, 3, (0, 255, 0), 2) cv.imshow("VIDEO", vid) if cv.waitKey(1) & 0xFF == ord('q'): break
This same issue is almost certainly affecting your pose estimation module too—double-check that you're creating an instance of that class with parentheses instead of just assigning the class itself.
内容的提问来源于stack exchange,提问作者Franklyn

