import cv2
from cvzone.HandTrackingModule import HandDetector
import math
import numpy as np
import cvzone
cap=cv2.VideoCapture(2)
cap.set(3,1280)
cap.set(4,720)
detector=HandDetector(detectionCon=0.8,maxHands=1)
#游戏
cx,cy=250,250
x=[400,445,400,360,300,245,200,170,145,130,112,103,93,87,80,75,70,67,62,59,57] #下面计算出的distance
y=[0,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100] #手与摄像头的距离
coff=np.polyfit(x,y,2)
#其中x,y表示需要拟合的坐标点,大小需要一样,2表示多项式拟合的次数 返回值p表示多项式拟合的系数,系数从高到低排列,二次函数为2
while True:
success,img=cap.read()
# hands,img=detector.findHands(img) #显示收节点
hands=detector.findHands(img,draw=False) #不显示节点
if hands:
lmList=hands[0]['lmList']
x,y,w,h=hands[0]['bbox']
x1,y1=lmList[5][0:2]
x2,y2=lmList[17][0:2]
distance=int(math.sqrt((y2-y1)**2+(x2-x1)**2))
A,B,C=coff
测手掌离摄像头距离
最新推荐文章于 2024-07-20 17:12:48 发布