From 0492042bac8850a34b961128563be04fae7e87f8 Mon Sep 17 00:00:00 2001 From: Jehan Patel <90050088+JehanPatel@users.noreply.github.com> Date: Wed, 29 Sep 2021 23:01:59 +0530 Subject: [PATCH] Add files via upload --- AI keyboard.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 AI keyboard.py diff --git a/AI keyboard.py b/AI keyboard.py new file mode 100644 index 0000000..af64161 --- /dev/null +++ b/AI keyboard.py @@ -0,0 +1,87 @@ +import cv2 +from cvzone.HandTrackingModule import HandDetector +from time import sleep +from pynput import keyboard +from pynput.keyboard import Controller + + +cap = cv2.VideoCapture(0) +cap.set(3,1280) +cap.set(4,720) + +detector = HandDetector(detectionCon=0.8, maxHands=2) + +keys =[["Q","W","E","R","T","Y","U","I","O","P"], + ["A","S","D","F","G","H","J","K","L",";"], + ["Z","X","C","V","B","N","M",",",".","/"]] + +finalText ="" + +keyboard = Controller() + +def drawALL(img,buttonList): + + for button in buttonList: + x,y = button.pos + w,h = button.size + cv2.rectangle(img, button.pos,( x+w, y+h ),(255,0,255), cv2.FILLED) + cv2.putText(img,button.text,(x+20,y+65), + cv2.FONT_HERSHEY_PLAIN, 4,(255,255,255),4) + + return img + +class Button(): + def __init__(self,pos, text, size = [85,85]): + self.pos = pos + self.size = size + self.text = text + + + + + +buttonList = [] +for i in range(len(keys)): + for j, key in enumerate(keys[i]): + buttonList.append(Button([100*j+50,100*i+50], key)) + + #44.03 + +while True: + success, img = cap.read() + img = detector.findHands(img) + lmList, bboxInfo = detector.findPosition(img) + img = drawALL(img, buttonList) + + if lmList: + for button in buttonList: + x,y=button.pos + w,h=button.size + + if x