Subway sufers

 import cv2

import numpy as np
import pyautogui
import HandTrakingModule as htm

wCam, hCam = 640480
cap = cv2.VideoCapture(0)

wScr, hScr = pyautogui.size()
hScr = hScr + 1200
wScr = wScr + 1500
detector = htm.handDetector(maxHands=1)

frameR = 100
smoothening = 10
plocX, plocY = 00
clocX, clocY = 00

while True:
    success, img = cap.read()
    img = detector.findHands(img, draw=True)
    lmList = detector.findPosition(img)
   
    if len(lmList) != 0:
        x1, y1 = lmList[8][1:]
        x2, y2 = lmList[12][1:]
        x3, y3 = lmList[4][1:]  
       
        tipIds = [48121620]
        fingers = []
      
        if lmList[tipIds[0]][1] > lmList[tipIds[0] - 1][1]:
            fingers.append(1)
        else:
            fingers.append(0)

        for id in range(15):
            if lmList[tipIds[id]][2] < lmList[tipIds[id] - 2][2]:
                fingers.append(1)
            else:
                fingers.append(0)
               
        if fingers[1] == 1 and fingers[2] == 1:
            cx, cy = (x1 + x2) // 2, (y1 + y2) // 2
            r, t = 92
        

            x3 = np.interp(x1, (frameR, wCam - frameR), (0, wScr))
            y3 = np.interp(y1, (frameR, hCam - frameR), (0, hScr))

            clocX = plocX + (x3 - plocX) / smoothening
            clocY = plocY + (y3 - plocY) / smoothening
             
            if -55 > (clocX - plocX):
 
                            pyautogui.press('right')
                                        
            if  -55 > (plocX - clocX):
                      
                            pyautogui.press('left')
                        
                     
            if -39 > (clocY - plocY):
            
                        pyautogui.press('up')
                        

            if -30 > (plocY - clocY):
                        pyautogui.press('down')
                        

            cv2.circle(img, (x1, y1), 10, (00255), cv2.FILLED)
            plocX, plocY = clocX, clocY
                    
 
    cv2.waitKey(1)

Comments

Popular posts from this blog