You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mediapipe人脸与姿态检测模块调用时出现TypeError位置参数缺失问题求助

Fixing TypeError: findFaces() missing 1 required positional argument: 'vid'

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 16:57:35