Commit cb1ae306 authored by AyeshaEwis's avatar AyeshaEwis

adding basic keys

parent 8d60bf43
......@@ -9,11 +9,81 @@ cap =cv2.VideoCapture(0)
#cap.set(4,720)
detector = HandDetector(detectionCon = 0.65)
keys =[["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], #LIST NO 1
["A", "S", "D", "F", "G", "H", "J", "K", "L", ";"], #LIST NO 2
["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"]] #LIST NO 3
final_text = ""
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),(100,0,100),cv2.FILLED)
# img, (initial loction),(size)
cv2.putText(img,button.text, (x+10, y+35),cv2.FONT_HERSHEY_PLAIN,2,(255,255,255),2)
return img
class Button():
def __init__(self,pos,text,size=[49,54]):
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([60*j+20,100*i+50],key ))
while True:
success ,img=cap.read()
img =cv2.flip(img ,1)
hands ,img = detector.findHands(img,flipType=False) #with draw
img = drawALL(img,buttonlist)
if hands:
#hand 1
hand1 = hands[0] #detecting only one hand
lmList1 = hand1["lmList"] #21 parameters,21 landmarks points
#lmList2 = hand1["lmList"]
bbox1 =hand1["bbox"] #bounding box info x,y,w,h
centerPoint1 =hand1["center"] #gives center of the hand cx and cy
handType1 =hand1["type"] #hand type left or right
if lmList1:
for button in buttonlist:
x,y = button.pos
w,h = button.size
if x< lmList1[8][0]<x+w and y<lmList1[8][1]< y+h: #index finger tip
cv2.rectangle(img, button.pos,(x+w,y+h),(195,0,195),cv2.FILLED)
# img, (initial loction),(size)
cv2.putText(img,button.text, (x+10, y+35),cv2.FONT_HERSHEY_PLAIN,2,(255,255,255),2)
length,info = detector.findDistance(lmList1[8],lmList1[12])
#l , _, _ =detector.findDistance(8,12,img)
# print(length)
#when clicked
if length<30:
cv2.rectangle(img, button.pos,(x+w,y+h),(0,255,0),cv2.FILLED)
# img, (initial loction),(size)
cv2.putText(img,button.text, (x+10, y+35),cv2.FONT_HERSHEY_PLAIN,2,(255,255,255),2)
final_text+=button.text
sleep(0.15) #how many times we clicked
#final text
cv2.rectangle(img, (50,370),(580,450),(255,255,255),cv2.FILLED)
# img, (initial loction),(size)
cv2.putText(img,final_text, (60, 430),cv2.FONT_HERSHEY_PLAIN,3,(0,0,0),3)
cv2.namedWindow("image", cv2.WINDOW_NORMAL)
# set your desired size
cv2.resizeWindow('image', 1266 , 668 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment