From 48ebedb015543f37d8f243862e783ee628ed78df Mon Sep 17 00:00:00 2001 From: Amir Kaseb <109258480+AmirKaseb@users.noreply.github.com> Date: Sat, 26 Aug 2023 02:35:19 +0300 Subject: [PATCH] Add files via upload --- __pycache__/controller.cpython-311.pyc | Bin 0 -> 3050 bytes __pycache__/controller.cpython-38.pyc | Bin 0 -> 952 bytes controller.py | 49 ++++++++++++++ main.py | 90 +++++++++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 __pycache__/controller.cpython-311.pyc create mode 100644 __pycache__/controller.cpython-38.pyc create mode 100644 controller.py create mode 100644 main.py diff --git a/__pycache__/controller.cpython-311.pyc b/__pycache__/controller.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..87440d4f37804b9260de4a7b5c221906d12083c6 GIT binary patch literal 3050 zcmeHI!E4h{7=LM+m$Y50&O@tgkb{>V6uaudqQY2*9$b6ayp+I*eQz!&R-plXz<>i+z?|n)p z^9Q;U1>idy_{Q&d25}C6_W%LJ>7W8oq{2l222UbB5OW_X;tOq_Rd~$r(rjTvd;lqo zL`DNhI1(uYkm5)r3?QYENHKtnA!!>_;)q)W*;tRgSjmmfl^62QAu8nZ1#=i@_G4~8 zUZ+t&g zuqGiL*&fSURxA;A^z_(S(;N2K$<$*89J3td6SXgTK!&xmGYZ#3hDycceG;bxX| z1>3Y$-D26~y;8NHJhU*e6vJFq4W(SeMWQ{$@>O}EJTEU{wYp00%1b$=h^;l-tSb-Z zi}IXVvx%wem?+hQ?zQ@+%hQFBNt!xIn{|n<)&U)HqM>eWI2+%j?@wXv9!$)fKCzQ8$V0 zin9c*Yc@*b)}Rec46Al+A#e=Y(cpVWk=}3#4BUVXx?wZ={B5pgwD|? W?zP}l8%{YwKYE2r_d(bV*Zm6vbH}Ct literal 0 HcmV?d00001 diff --git a/__pycache__/controller.cpython-38.pyc b/__pycache__/controller.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..980fa4d9bb4dcbb5cba7a1bb2566c5e841bd9b9c GIT binary patch literal 952 zcmb7@Pfy!06u@mKPSViAuDkWx3!;S{h!_HuNgVhyY1_rB#6oRQMruc{(L}Z5J^&w~ z9QOgnhsl*wuN*n;*(p&qjcGW_dp}41y}ZQ9=T<95Fy8ileR=02^k65;!-L5loRd!w zIN~@*3~|D+KrcZxMkmZ4 zoF4b50Z+P{iE_EO$lXQWfJ}L^ov0DE&SF@$Z4Tg^6fpY^ZC(+*YtRgHXb~erYVvCG zYogC|i{(1l1njA^$!l!+2(Ab2{U2^s<)3$!_u%^AKECKyRsPbooPtZQ$Su|z|6x~k z>SvZaUo-uVv%(t1%|)iisYzKlQsY8t!@_;duQRC_ zJy)sbEW8xvtjMGe!O;yH?60O*Y-rkGi@9f93Ttq!jCRI~U*}@izR-zX77?Gsq;87* E24;-Oy#N3J literal 0 HcmV?d00001 diff --git a/controller.py b/controller.py new file mode 100644 index 0000000..b43ef47 --- /dev/null +++ b/controller.py @@ -0,0 +1,49 @@ +import pyfirmata + +comport='COM3' + +board=pyfirmata.Arduino(comport) + +led_1=board.get_pin('d:13:o') +led_2=board.get_pin('d:12:o') +led_3=board.get_pin('d:11:o') +led_4=board.get_pin('d:10:o') +led_5=board.get_pin('d:9:o') + +def led(total): + if total==0: + led_1.write(0) + led_2.write(0) + led_3.write(0) + led_4.write(0) + led_5.write(0) + elif total==1: + led_1.write(1) + led_2.write(0) + led_3.write(0) + led_4.write(0) + led_5.write(0) + elif total==2: + led_1.write(1) + led_2.write(1) + led_3.write(0) + led_4.write(0) + led_5.write(0) + elif total==3: + led_1.write(1) + led_2.write(1) + led_3.write(1) + led_4.write(0) + led_5.write(0) + elif total==4: + led_1.write(1) + led_2.write(1) + led_3.write(1) + led_4.write(1) + led_5.write(0) + elif total==5: + led_1.write(1) + led_2.write(1) + led_3.write(1) + led_4.write(1) + led_5.write(1) diff --git a/main.py b/main.py new file mode 100644 index 0000000..42ecc6e --- /dev/null +++ b/main.py @@ -0,0 +1,90 @@ +import cv2 +import mediapipe as mp +import time +import controller as cnt + + +time.sleep(2.0) + +mp_draw=mp.solutions.drawing_utils +mp_hand=mp.solutions.hands + + +tipIds=[4,8,12,16,20] + +video=cv2.VideoCapture(0) + +with mp_hand.Hands(min_detection_confidence=0.5, + min_tracking_confidence=0.5) as hands: + while True: + ret,image=video.read() + image=cv2.cvtColor(image, cv2.COLOR_BGR2RGB) + image.flags.writeable=False + results=hands.process(image) + image.flags.writeable=True + image=cv2.cvtColor(image, cv2.COLOR_RGB2BGR) + lmList=[] + if results.multi_hand_landmarks: + for hand_landmark in results.multi_hand_landmarks: + myHands=results.multi_hand_landmarks[0] + for id, lm in enumerate(myHands.landmark): + h,w,c=image.shape + cx,cy= int(lm.x*w), int(lm.y*h) + lmList.append([id,cx,cy]) + mp_draw.draw_landmarks(image, hand_landmark, mp_hand.HAND_CONNECTIONS) + fingers=[] + if len(lmList)!=0: + if lmList[tipIds[0]][1] > lmList[tipIds[0]-1][1]: + fingers.append(1) + else: + fingers.append(0) + for id in range(1,5): + if lmList[tipIds[id]][2] < lmList[tipIds[id]-2][2]: + fingers.append(1) + else: + fingers.append(0) + total=fingers.count(1) + cnt.led(total) + if total==0: + cv2.rectangle(image, (20, 300), (270, 425), (0, 255, 0), cv2.FILLED) + cv2.putText(image, "0", (45, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.putText(image, "LED", (100, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + elif total==1: + cv2.rectangle(image, (20, 300), (270, 425), (0, 255, 0), cv2.FILLED) + cv2.putText(image, "1", (45, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.putText(image, "LED", (100, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + elif total==2: + cv2.rectangle(image, (20, 300), (270, 425), (0, 255, 0), cv2.FILLED) + cv2.putText(image, "2", (45, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.putText(image, "LED", (100, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + elif total==3: + cv2.rectangle(image, (20, 300), (270, 425), (0, 255, 0), cv2.FILLED) + cv2.putText(image, "3", (45, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.putText(image, "LED", (100, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + elif total==4: + cv2.rectangle(image, (20, 300), (270, 425), (0, 255, 0), cv2.FILLED) + cv2.putText(image, "4", (45, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.putText(image, "LED", (100, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + elif total==5: + cv2.rectangle(image, (20, 300), (270, 425), (0, 255, 0), cv2.FILLED) + cv2.putText(image, "5", (45, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.putText(image, "LED", (100, 375), cv2.FONT_HERSHEY_SIMPLEX, + 2, (255, 0, 0), 5) + cv2.imshow("Frame",image) + k=cv2.waitKey(1) + if k==ord('q'): + break +video.release() +cv2.destroyAllWindows() +