不仅仅是#cv2putText,添加print(totalFingers)你能得到这个值吗?我不想在图像中显示数字
我的代码如下。
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:列表索引超出范围
发布于 2021-08-04 07:34:49
错误:totalFingers仅定义为if lmList:。但是,看起来lmList为False/empty/None,并且您尝试使用未定义的totalFingers。
Example 1:
lmList = [2]
if lmList:
totalFingers = 7
print(totalFingers)
Example 2:
# this is the bug
lmList = None
if lmList:
totalFingers = 7
print(totalFingers)https://stackoverflow.com/questions/68647055
复制相似问题