Commit e7325629 authored by AyeshaEwis's avatar AyeshaEwis

completed keyboard

parent cb1ae306
from time import sleep from time import sleep
import cv2 import cv2
from cv2 import imread from cv2 import imread
...@@ -8,7 +9,62 @@ cap =cv2.VideoCapture(0) ...@@ -8,7 +9,62 @@ cap =cv2.VideoCapture(0)
#cap.set(3,1280) #cap.set(3,1280)
#cap.set(4,720) #cap.set(4,720)
detector = HandDetector(detectionCon = 0.65) detector = HandDetector(detectionCon = 0.8)
img1 =cv2.imread("Alphabet\q.png")
ox,oy =20 ,50 #ox->originx
img2 =cv2.imread("Alphabet\w.png")
ox2,oy2 =80 ,50 #ox->originx
img3 =cv2.imread("Alphabet\e.png")
ox3,oy3 =140 ,50 #ox->originx
img4 =cv2.imread("Alphabet\\r.png")
ox4,oy4 =200 ,50 #ox->originx
img5 =cv2.imread("Alphabet\\t.png")
ox5,oy5 =260 ,50 #ox->originx
img6 =cv2.imread("Alphabet\y.png")
ox6,oy6 =320,50 #ox->originx
img7 =cv2.imread("Alphabet\\u.png")
ox7,oy7 =380 ,50 #ox->originx
img8 =cv2.imread("Alphabet\i.png")
ox8,oy8 =440 ,50 #ox->originx
img9 =cv2.imread("Alphabet\o.png")
ox9,oy9 =500 ,50 #ox->originx
img10 =cv2.imread("Alphabet\p.png")
ox10,oy10 =560 ,50 #ox->originx
img11 =cv2.imread("Alphabet\\a.png")
ox11,oy11 =20 ,150 #ox->originx
img12 =cv2.imread("Alphabet\s.png")
ox12,oy12 =80 ,150 #ox->originx
img13 =cv2.imread("Alphabet\d.png")
ox13,oy13 =140 ,150 #ox->originx
img14 =cv2.imread("Alphabet\\f.png")
ox14,oy14 =200 ,150 #ox->originx
img15 =cv2.imread("Alphabet\g.png")
ox15,oy15 =260 ,150 #ox->originx
img16 =cv2.imread("Alphabet\h.png")
ox16,oy16 =320,150 #ox->originx
img17 =cv2.imread("Alphabet\j.png")
ox17,oy17 =380 ,150 #ox->originx
img18 =cv2.imread("Alphabet\k.png")
ox18,oy18 =440 ,150 #ox->originx
img19 =cv2.imread("Alphabet\l.png")
ox19,oy19 =500 ,150 #ox->originx
img20 =cv2.imread("Alphabet\z.png")
ox20,oy20 =20 ,250 #ox->originx
img21 =cv2.imread("Alphabet\\x.png")
ox21,oy21 =80 ,250 #ox->originx
img22 =cv2.imread("Alphabet\c.png")
ox22,oy22 =140 ,250 #ox->originx
img23 =cv2.imread("Alphabet\\v.png")
ox23,oy23 =200 ,250 #ox->originx
img24 =cv2.imread("Alphabet\\b.png")
ox24,oy24 =260 ,250 #ox->originx
img25 =cv2.imread("Alphabet\\n.png")
ox25,oy25 =320,250 #ox->originx
img26 =cv2.imread("Alphabet\m.png")
ox26,oy26 =380 ,250 #ox->originx
keys =[["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], #LIST NO 1 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 ["A", "S", "D", "F", "G", "H", "J", "K", "L", ";"], #LIST NO 2
...@@ -41,13 +97,104 @@ for i in range(len(keys)) : ...@@ -41,13 +97,104 @@ for i in range(len(keys)) :
for j, key in enumerate(keys[i]) : for j, key in enumerate(keys[i]) :
buttonlist.append(Button([60*j+20,100*i+50],key )) buttonlist.append(Button([60*j+20,100*i+50],key ))
while True: while True:
success ,img=cap.read() success ,img=cap.read()
img =cv2.flip(img ,1) img =cv2.flip(img ,1)
hands ,img = detector.findHands(img,flipType=False) #with draw hands ,img = detector.findHands(img,flipType=False) #with draw
img = drawALL(img,buttonlist) img = drawALL(img,buttonlist)
if hands: cv2.rectangle(img, (30,350), (100,310),(100,0,100), cv2.FILLED)
cv2.putText(img, 'clr', (40, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
cv2.rectangle(img, (150,350), (450,310),(100,0,100), cv2.FILLED)
cv2.putText(img, 'Space', (250, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
cv2.rectangle(img, (600,350), (500,310),(100,0,100), cv2.FILLED)
cv2.putText(img, '<--', (520, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
h,w,_ =img1.shape
img[oy:oy+h,ox:ox+w] = img1
h2,w2,_ =img2.shape
img[oy2:oy2+h2,ox2:ox2+w2] = img2
h3,w3,_ =img3.shape
img[oy3:oy3+h3,ox3:ox3+w3] = img3
h4,w4,_ =img4.shape
img[oy4:oy4+h4,ox4:ox4+w4] = img4
h5,w5,_ =img5.shape
img[oy5:oy5+h5,ox5:ox5+w5] = img5
h6,w6,_ =img6.shape
img[oy6:oy6+h6,ox6:ox6+w6] = img6
h7,w7,_ =img7.shape
img[oy7:oy7+h7,ox7:ox7+w7] = img7
h8,w8,_ =img8.shape
img[oy8:oy8+h8,ox8:ox8+w8] = img8
h9,w9,_ =img9.shape
img[oy9:oy9+h9,ox9:ox9+w9] = img9
h10,w10,_ =img10.shape
img[oy10:oy10+h10,ox10:ox10+w10] = img10
h11,w11,_ =img11.shape
img[oy11:oy11+h11,ox11:ox11+w11] = img11
h12,w12,_ =img12.shape
img[oy12:oy12+h12,ox12:ox12+w12] = img12
h13,w13,_ =img13.shape
img[oy13:oy13+h13,ox13:ox13+w13] = img13
h14,w14,_ =img14.shape
img[oy14:oy14+h14,ox14:ox14+w14] = img14
h15,w15,_ =img15.shape
img[oy15:oy15+h15,ox15:ox15+w15] = img15
h16,w16,_ =img16.shape
img[oy16:oy16+h16,ox16:ox16+w16] = img16
h17,w17,_ =img17.shape
img[oy17:oy17+h17,ox17:ox17+w17] = img17
h18,w18,_ =img18.shape
img[oy18:oy18+h18,ox18:ox18+w18] = img18
h19,w19,_ =img19.shape
img[oy19:oy19+h19,ox19:ox19+w19] = img19
h20,w20,_ =img20.shape
img[oy20:oy20+h20,ox20:ox20+w20] = img20
h21,w21,_ =img21.shape
img[oy21:oy21+h21,ox21:ox21+w21] = img21
h22,w22,_ =img22.shape
img[oy22:oy22+h22,ox22:ox22+w22] = img22
h23,w23,_ =img23.shape
img[oy24:oy24+h23,ox23:ox23+w23] = img23
h24,w24,_ =img24.shape
img[oy24:oy24+h24,ox24:ox24+w24] = img24
h25,w25,_ =img25.shape
img[oy25:oy25+h25,ox25:ox25+w25] = img25
h26,w26,_ =img26.shape
img[oy26:oy26+h26,ox26:ox26+w26] = img26
if hands:
#hand 1 #hand 1
hand1 = hands[0] #detecting only one hand hand1 = hands[0] #detecting only one hand
lmList1 = hand1["lmList"] #21 parameters,21 landmarks points lmList1 = hand1["lmList"] #21 parameters,21 landmarks points
...@@ -55,9 +202,64 @@ if hands: ...@@ -55,9 +202,64 @@ if hands:
bbox1 =hand1["bbox"] #bounding box info x,y,w,h bbox1 =hand1["bbox"] #bounding box info x,y,w,h
centerPoint1 =hand1["center"] #gives center of the hand cx and cy centerPoint1 =hand1["center"] #gives center of the hand cx and cy
handType1 =hand1["type"] #hand type left or right handType1 =hand1["type"] #hand type left or right
#print((lmList1),lmList1)
#print(bbox1)
# print(centerPoint1)
# print(handType1)
b1,b2,b3,b4 =bbox1
#print(bbox1)
print(b1,b2,b3,b4)
if b3>80 and b4>100:
if lmList1: if lmList1:
for button in buttonlist:
x1,y1 = 30,310
w1,h1 = 100,350
#checking the x and y position
if 30 < lmList1[8][0]<100 and 310<lmList1[8][1]< 350: #index finger tip
cv2.rectangle(img, (30,350), (100,310),(195,0,195), cv2.FILLED)
cv2.putText(img, 'clr', (40, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
length1,info1 = detector.findDistance(lmList1[8],lmList1[12])
#print(lmList1[8][1])
#print(length1)
if length1<30:
cv2.rectangle(img, (30,350), (100,310),(0,255,0), cv2.FILLED)
cv2.putText(img, 'clr', (40, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
final_text=''
sleep(0.15) #how many times we clicked
if 150 < lmList1[8][0]<450 and 310<lmList1[8][1]<350: #index finger tip
cv2.rectangle(img, (150,350), (450,310),(195,0,195), cv2.FILLED)
cv2.putText(img, 'Space', (250, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
length2,info2 = detector.findDistance(lmList1[8],lmList1[12])
#print(lmList1[8][1])
if length2<30:
cv2.rectangle(img, (150,350), (450,310),(0,255,0), cv2.FILLED)
cv2.putText(img, 'Space', (250, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
final_text +=' '
sleep(0.15) #how many times we clicked
if 495 < lmList1[8][0]<600 and 310<lmList1[8][1]< 350: #index finger tip
cv2.rectangle(img, (600,350), (500,310),(195,0,195), cv2.FILLED)
cv2.putText(img, '<--', (520, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
length3,info3 = detector.findDistance(lmList1[8],lmList1[12])
print(lmList1[8][0])
if length3<30:
cv2.rectangle(img, (600,350), (500,310),(0,255,0), cv2.FILLED)
cv2.putText(img, '<--', (520, 340), cv2.FONT_HERSHEY_PLAIN, 2,(255,255,255), 2)
final_text = final_text[:-1]
sleep(0.15) #how many times we clicked
for button in buttonlist:
x,y = button.pos x,y = button.pos
w,h = button.size w,h = button.size
...@@ -77,15 +279,28 @@ if hands: ...@@ -77,15 +279,28 @@ if hands:
final_text+=button.text final_text+=button.text
sleep(0.15) #how many times we clicked sleep(0.15) #how many times we clicked
#space button
# space_text=" "
# cv2.rectangle(img, (80,350),(300,310),(195,0,195),cv2.FILLED)
# # img, (initial loction),(size)
# cv2.putText(img,space_text, (60, 390),cv2.FONT_HERSHEY_PLAIN,2,(255,255,255),2)
#final text #final text
cv2.rectangle(img, (50,370),(580,450),(255,255,255),cv2.FILLED) cv2.rectangle(img, (50,370),(580,450),(255,255,255),cv2.FILLED)
# img, (initial loction),(size) # img, (initial loction),(size)
cv2.putText(img,final_text, (60, 430),cv2.FONT_HERSHEY_PLAIN,3,(0,0,0),3) cv2.putText(img,final_text, (60, 430),cv2.FONT_HERSHEY_PLAIN,3,(0,0,0),3)
# hands = detector.findHands(img,draw=False) #no draw
# print(len(hands))
# lmList ,bboxInfo = detector.findHands(img)
cv2.namedWindow("image", cv2.WINDOW_NORMAL) cv2.namedWindow("image", cv2.WINDOW_NORMAL)
# set your desired size # set your desired size
cv2.resizeWindow('image', 1266 , 668 ) cv2.resizeWindow('image', 1266 , 668 )
cv2.imshow("image",img) cv2.imshow("image",img)
#cv2.geometry('1485x500') #cv2.geometry('1485x500')
......
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