diff --git a/code/backend_reconnaissance/hand_detector.py b/code/backend_reconnaissance/hand_detector.py index 8f78b55..929a8c7 100644 --- a/code/backend_reconnaissance/hand_detector.py +++ b/code/backend_reconnaissance/hand_detector.py @@ -18,7 +18,7 @@ class HandDetector(): min_detection_confidence=0.5, min_tracking_confidence=0.5) #Paramètres - self.BUFFER_LENGTH = 30 + self.BUFFER_LENGTH = 60 self.DETECTION_THRESHOLD = 3/4 self.resultBuffer = [] @@ -31,10 +31,13 @@ class HandDetector(): i=0 j=0 for cpt in range (0,4): + V1=[handLandmarks[(4*cpt)+5][0]-handLandmarks[(4*cpt)+0][0],handLandmarks[(4*cpt)+5][1]-handLandmarks[(4*cpt)+0][1]] + V2=[handLandmarks[(4*cpt)+8][0]-handLandmarks[(4*cpt)+5][0],handLandmarks[(4*cpt)+8][1]-handLandmarks[(4*cpt)+5][1]] + j1=np.dot(V1,V2) V1=[handLandmarks[(4*cpt)+6][0]-handLandmarks[(4*cpt)+5][0],handLandmarks[(4*cpt)+6][1]-handLandmarks[(4*cpt)+5][1]] V2=[handLandmarks[(4*cpt)+8][0]-handLandmarks[(4*cpt)+6][0],handLandmarks[(4*cpt)+8][1]-handLandmarks[(4*cpt)+6][1]] - j=np.dot(V1,V2) - if (j>0.005): + j2=np.dot(V1,V2) + if (j1>0 and j2>0): return etatDuPouce[0] V1=[handLandmarks[4][0]-handLandmarks[1][0],handLandmarks[4][1]-handLandmarks[1][1]] V2=[handLandmarks[2][0]-handLandmarks[1][0],handLandmarks[2][1]-handLandmarks[1][1]] @@ -67,20 +70,24 @@ class HandDetector(): for landmarks in hand_landmarks.landmark: handLandmarks.append([landmarks.x, landmarks.y]) #On ajoute la position de chaque mains a une liste - handsPositions.append(self.reconnaissancePouce(handLandmarks)) + handsPositions.append([self.reconnaissancePouce(handLandmarks), handLandmarks]) #On calcule le résultat suivant la position des deux mains if(len(handsPositions) == 2): - if(handsPositions[0] == handsPositions[1]): + if(handsPositions[0][0] == handsPositions[1][0]): thumbState = handsPositions[0] - elif(handsPositions[0] == "neutre"): + handLandmarks = handsPositions[0][1] + elif(handsPositions[0][0] == "neutre"): thumbState = handsPositions[1] - elif(handsPositions[1] == "neutre"): - thumbState = handsPositions[0] + handLandmarks = handsPositions[1][1] + elif(handsPositions[1][0] == "neutre"): + thumbState = handsPositions[0][0] + handLandmarks = handsPositions[0][1] else: thumbState = "neutre" else: - thumbState = handsPositions[0] + thumbState = handsPositions[0][0] + handsLandmarks = handsPositions[0][1] self.resultBuffer.append(thumbState) if(len(self.resultBuffer) > self.BUFFER_LENGTH): @@ -101,3 +108,7 @@ class HandDetector(): return False +if __name__ == "__main__": + h = HandDetector() + while(1): + print(h.detect()) diff --git a/code/backend_reconnaissance/recording.wav b/code/backend_reconnaissance/recording.wav index b73dffa..6620e26 100644 Binary files a/code/backend_reconnaissance/recording.wav and b/code/backend_reconnaissance/recording.wav differ