我正在嘗試使用兩只手放大圖片(手勢控制的影像縮放),但是在嘗試使用兩只手時出現此錯誤,但我不知道為什么。在制作我的程式時,我遵循了本教程:https : //www.youtube.com/watch?v=VPaFV3QBsEw&t=675s。這很奇怪,因為這個程式對他有用。
這是我得到的錯誤:
hands, img = detector.findHands(img)
ValueError: too many values to unpack (expected 2)
這是我的代碼:
import cv2
from cvzone.HandTrackingModule import HandDetector
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
detector = HandDetector(detectionCon=0.7)
startDist = None
scale = 0
cx, cy = 500,500
while True:
success, img = cap.read()
hands, img = detector.findHands(img)
img1 = cv2.imread("kung_fu_panda.png")
if len(hands) == 2:
if detector.fingersUp(hands[0]) == [1, 1, 0, 0, 0] and \
detector.fingersUp(hands[1]) == [1, 1, 0, 0, 0]:
lmList1 = hands[0]["lmList"]
lmList2 = hands[1]["lmList"]
# point 8 is the tip of the index finger
if startDist is None:
length, info, img = detector.findDistance(hands[0]["center"], hands[1]["center"], img)
startDist = length
length, info, img = detector.findDistance(hands[0]["center"], hands[1]["center"], img)
scale = int((length - startDist) // 2)
cx, cy = info[4:]
print(scale)
else:
startDist = None
try:
h1, w1, _= img1.shape
newH, newW = ((h1 scale)//2)*2, ((w1 scale)//2)*2
img1 = cv2.resize(img1, (newW,newH))
img[cy-newH//2:cy newH//2, cx-newW//2:cx newW//2] = img1
except:
pass
cv2.imshow("Image", img)
cv2.waitKey(1)
uj5u.com熱心網友回復:
cvzone 庫每次都會不斷更新他們的庫。正如您在視頻開頭所看到的,當他匯入 cvzone 包時,他使用的是 cvzone 1.5.0 版。
我在其他版本中嘗試了您的代碼,但遇到了與您類似的錯誤,但在 1.5.0 版中,您的代碼運行良好。
您可以在此處使用我的回答將專案中 cvzone 庫的版本更改為 1.5.0。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/321299.html
下一篇:基于多種條件過濾像素
