首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python中的手形检测器

Python中的手形检测器
EN

Stack Overflow用户
提问于 2021-08-04 07:26:47
回答 1查看 294关注 0票数 0

不仅仅是#cv2putText,添加print(totalFingers)你能得到这个值吗?我不想在图像中显示数字

我的代码如下。

代码语言:javascript
复制
    from cvzone.HandTrackingModule import HandDetector
import cv2
import numpy as np

cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
detector = HandDetector(detectionCon=0.5, maxHands=1)

while True:
    # Get image frame
    success, img = cap.read()

    # Find the hand and its landmarks
    img = detector.findHands(img)
    lmList, bboxInfo = detector.findPosition(img)

    lmList =[2]
    if lmList:
        bbox = bboxInfo[0]['bbox']
        fingers = detector.fingersUp()
        totalFingers = fingers.count (1)

       # cv2.putText(img, f'Fingers:{totalFingers}', (bbox[0] + 200, bbox[1] - 30), cv2.FONT_HERSHEY_PLAIN, 2, (0, 255, 0), 2)

    # 顯示
    cv2. imshow("Image", img)
    print()
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release(totalFingers)
cv2.destroyAllWindows()

bbox = bboxInfo IndexError:列表索引超出范围

EN

回答 1

Stack Overflow用户

发布于 2021-08-04 07:34:49

错误:totalFingers仅定义为if lmList:。但是,看起来lmList为False/empty/None,并且您尝试使用未定义的totalFingers。

代码语言:javascript
复制
Example 1:

    lmList = [2]
    if lmList:
       totalFingers = 7
    print(totalFingers)

Example 2:
    # this is the bug 
    lmList = None
    if lmList:
       totalFingers = 7
    print(totalFingers)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68647055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档