From e05e2888755b49789f8bfa3b825263b028986f2b Mon Sep 17 00:00:00 2001 From: Michal Maciaszek Date: Mon, 28 Dec 2020 23:43:48 +0100 Subject: [PATCH 1/4] gestures google --- gestures/google_solution.py | 35 ++++++++++++++++++ .../__pycache__/__init__.cpython-38.pyc | Bin 167 -> 0 bytes .../__pycache__/settings.cpython-38.pyc | Bin 3530 -> 0 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1110 -> 0 bytes .../__pycache__/wsgi.cpython-38.pyc | Bin 580 -> 0 bytes .../user/__pycache__/__init__.cpython-38.pyc | Bin 176 -> 0 bytes .../app/user/__pycache__/admin.cpython-38.pyc | Bin 217 -> 0 bytes .../user/__pycache__/models.cpython-38.pyc | Bin 2416 -> 0 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1028 -> 0 bytes .../0002_auto_20201130_2119.cpython-38.pyc | Bin 545 -> 0 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 187 -> 0 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 184 -> 0 bytes .../__pycache__/admin.cpython-38.pyc | Bin 225 -> 0 bytes .../__pycache__/models.cpython-38.pyc | Bin 1267 -> 0 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1055 -> 0 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 195 -> 0 bytes 16 files changed, 35 insertions(+) create mode 100644 gestures/google_solution.py delete mode 100644 rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc delete mode 100644 rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc diff --git a/gestures/google_solution.py b/gestures/google_solution.py new file mode 100644 index 0000000..75fa9dd --- /dev/null +++ b/gestures/google_solution.py @@ -0,0 +1,35 @@ +import cv2 +import mediapipe as mp +mp_drawing = mp.solutions.drawing_utils +mp_hands = mp.solutions.hands + +hands = mp_hands.Hands( + min_detection_confidence=0.5, min_tracking_confidence=0.5) +cap = cv2.VideoCapture(0) +while cap.isOpened(): + success, image = cap.read() + + # Flip the image horizontally for a later selfie-view display, and convert + # the BGR image to RGB. + image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) + # To improve performance, optionally mark the image as not writeable to + # pass by reference. + image.flags.writeable = False + results = hands.process(image) + + + # Draw the hand annotations on the image. + image.flags.writeable = True + image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) + if results.multi_hand_landmarks: + for hand_landmarks in results.multi_hand_landmarks: + mp_drawing.draw_landmarks( + image, hand_landmarks, mp_hands.HAND_CONNECTIONS) + #print(hand_landmarks) ## spójrz na to + + cv2.imshow('MediaPipe Hands', image) + if cv2.waitKey(5) & 0xFF == 27: + break +hands.close() +cap.release() + diff --git a/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 5271ef2b19a2717c110213199c81991c4c533c4e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 167 zcmWIL<>g`kf_ndR@gVv!h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o6v9KO;XkRlgvy zq^L4mzcevdzc@8FwYa3nNWZu;Q$IL2v8W^Z#o bWtPOp>lIYq;;_lhPbtkwwFBAm8HgDG34khk diff --git a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc deleted file mode 100644 index 417941631187a51499fd934d3a9a1b689839298f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3530 zcmb6bOLN=CnWVsn7)h37$#!hVq2tyLWecz*+euS96+}W3V!nm|C3`Ozh~J8W3=jw& zR)kxpmtOi0d}xoo_tzlD&U7Y!ATw<n-%`i<<2)$< zN2Vc5ioF#12y&2z0!%{@K7tvTg}L4|nSm=X4-2peS78a3dwDVo*T@`P@1-CMH{fHq z3Af;Ok2BKn$vdu>CRgANnTJoIL zPOd_kETJXK_+G>JI;@Zz@Q{2Ak6^Wz0lt?8;a!H@gvYQ3>#zY&;3+(dpD)moETm}$ zzJ%ZXB^|@Q8m@ki>*w#5$SruLq{=V!H4IU)daU<*cFCi@Z}fX!>Ckpdo~66KV{~=T zvrCR^AJeYS7mGWzPhH)oP&zm*J%E^TRR_!Hmpq?wB$N+Ifrp|>1IZiw8ozx?;jbc)iCKJG=dh7eBbfD5(Kcj9-rtqv!H8R0__VZQ1ERu&lAq9 z783FP5iK1Crdcu#&o9}BBd_#6pdxCxrMJ2nQ1AcI<@i9)7Npq zwRHa|T>tKP#k{{#rv1%z>+a*QT)w-px!OIvYrOEi;H|UiJI?*5RvBRP;gepl)^(56 za4GST@7jIeH4gYVp5fI=Xn^u>O#m4S?fd?zL%s0&1k$6PhY>!Hun?j5kmKeghmSew zvP^j4@^}gGy5sPHN8Rv~3&9#Dh_Qt?&Y=gX3s(oaECax#C%Q{{k9Gss@K1SVFsTo5 z;gd zR?%aOlTMrkew?|UBx8*0*#%CRM)%FJ-hG2z#lPBib&EC~rpz1TTX-+_fopo9Fc9Ta z%Q3NU`2&VUNy+ASxcDOM?JPhOo3}?797v;Ca%1fzHC0tc*D^WpgwX}GaZ?;sq*-$3R z`NZoPtkf~uaVn!c&_g{i{b8rT!6<~@x2ECKjj)Ko!MvP_a#CYQZb%W=5bKgVjax;y zJ7IlXKMroKC$i7VTSca*y{@6<>Y&ZP+LnYOXzF`GcjrM!~ z(TM*KAIhJ!OKV``NWkWY3TOltb&c+M30c}-4LmZ{Q7d6Vz*7VJMhK_b<`VlKuDDnp z+99iPjL#e1p{`{lI~gx~W4%Tpyni_@JD6BZ!{_hQX~!o%&$2M;TK*fQ+1RHCs*U|I zrUZMej3;eX+7>%CRclG@x~wQzJ6feCDvG3#J7+ktqwY!#Rj!Dvw$AY3!wYl=zF~Si zTA|T?*9NK`;qhdmp_dZ_eUJFjrIH=})Uc8i{I?4n$)N?tCF@W zHmWtLoxrNnd$6mFt|h*%HO1{Mlpj+D@26?QN_3o)ivYwn|O+vwgd88{j*&WpO1 zh*Ed8T}iBBh+4=eze@aIC9GAN&6l!Nz8&Q?4ewx@78P)RqU^TgW-xV8-od+$X&ksy zY*o-ScJw1z9;?7M-_j`OU`G2sDQt-tYTR*Mc4d#URcWiU6U~auTnRJNR8%FJlN*YP zAOzt4tVG4ST*cJyi)|^IX*Zjg$#$*MY-~r0;g0n0^`*S>5dv)bC@ zMwDYPm0%64sH4K{h_1x4&P7Og}*X>qv-4P&pjGyPj`zP<5Muq2=4S`9&#_M~^ z`v(r(%uIS_YCgwJaTzX~Ne`b)Jo}NG8$uZF-&~R7Vn~8#u%9x&WPaj);pVvn$C2#-?GE*8 zSn@kz$%IYZZ#%1dGlQ-!`pIoAd$SsAA72O1fP zK5+I?C+JKnB&1@97gMQ(gFt1@h-OGLHjWUixiO_4V@zeH6S^S9OqNP6SZ0z;3d{=p zFgeCX0x6AcGKTURM=w4R0a$t*omE9<*=@=?(BlL>qZE+>aZyTT#t2Q76i6&nQkKnO zEB~a)calLsOCfv;V&|jb@UYP}mx3Llf(Z6_XyaiVo#tTJ(G3WrE!6+9kY>)5C6YL! zwsg(`%dx*D8=IdHom!Al{0F0pBFihviy4^U>RD+ST;|rF3ug=hDsVkEmyKdHZLAz` z?AlyMVh!JtY;q5sDYs^Olgk+f1Gkli_Q2r|<2d>OeeK15-6d4;A`a@%I$rmi>{Uog zj#u~Ey_s0|D$SGwSv~mYyA&E}%5%2Kx&K$rw$H4-RnHa2ui~A$pQg}_X*xM*3;^GZ z;x`Hg#H)8(t|*vSPlfh4)ZDN-v{?0StADi<$GKafi)9M8+C&9 xlH*G|eXlpuhZUS3flS=y?V3L+m-XP0khIF#6Cc3!0c_!&J^yZJ&v(CHzX3>tUcmqW diff --git a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc deleted file mode 100644 index 532843f83e5a77368a1fe521a79900f311d6832c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 580 zcmYjP&2AGh5cY1;CM*2EnDL3#s4%^#Iv2gvLK*OxVijV#Q5u|7)tOW?sr_gW2W5#m$}*Ji}(9oFo*GD1Y%uzyH4|F8;8&K U^M8)Ng!mzv{*7UJE4`im16{JXEC2ui diff --git a/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 72eb12b4eafa74b963799d6effcf364e0bf4a65b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 176 zcmWIL<>g`kf_ndR@gVv!h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o10WKO;XkRlgvy zq^L4mzcevdzc@8FwYa3nNWZu;Q$IL2v8W^g`kf_ndR@%BLaF^Gc(44TX@fuanW zjJH@5Q*tx&{4|-O_)@YG^V0M6lJoOQiZYXmKnAR2C}IXuVB%Mhenx(7s(wLYNl|6C zeraN^esOAUYH>-Ck$!Pyrhag4Vo^yzW^!V2alU>LP+T{$pg_MEBw7F!1qqZErxxjh aE!8Wiyv1RYo1apelWNBZwB|DqGXMbAGdU{& diff --git a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc deleted file mode 100644 index 66e537eb877091ef17f6feffde1897331eb846e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2416 zcmZ`*UvC>l5Wl^DK0D{wq^%02zzGSc5!ezcFA+j%8y8g~2AYP4d%3Q?o8;2_JjCpIpc}!nW}S}O1>w#*r6Fc z;6in8jb$O|q*yFWP-(SUz-&R69|PeAIBSF^BcTOuSj>J-Lc4Y_bhIm;T3gwm`m7Z| zn{OBFgMX7!7I_+!;6--%8JUOb@yiF`W$`7QP6rZar}J5yK#PMKqW$TyTAS!3ML6BT{QE$R zhD|)OL0V+ptgd1-=8)>INWUFIH^IUTQ2WReU4W5U!{`N>5rB>P%whnc$kY_UWWO{J zN*X+WE>n6QJoF5FWI5#my$)_rmd05x06vYSjPpz`t-J+1OXW8O7m+`UpbNw=gwc7q zQT5U8!qGE`S|ap8&r!_>$I}`);tIr0`LT?awv>llLHGAX8y0nzG$3kn85O$oyeySI zgju-`#AtYsN}ss!^UUh{1<710^~eZt>_rh?#wb#)C<36A36A|JdR)?EzS4*ymQSKc zyDQ#L1~DhTd*cgAO@*?JY0Xia4reB#};&n`m0G`CcHZJ{cLIrJG`LP z*UP(eCxMz16nOyEEzmItbUBZ+fWgx^hF5SYD>lIRsON}l@D=YPxsK!mAj)IoNb9d0 zW{D?HPD;Ngkful&yQZL z>#l!0&l66wTD}R_4xZ{5^7by65?9gQ`rhvF{^-`uFuHqh`2Du(+#mk5ckljiyXJQ_ zyj3F~AMr^c#iyu$HFcQ8=OC_{ z?1*Lud7q8zlU|$ilRPU#JnrNFlYU+2g#`)%gQnfnwk~o=dEeCc{ab{B#G7l|SUkE` H_mlqs(|KkT diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc deleted file mode 100644 index f707b2c1ac7c16e4e4d460c160acd6098beac22f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1028 zcmYjQ&2AJq5N^9YGu@q;knp#AFBbWpI26+Gk2W3Iz2d>TLq;$r{;*-Cr}GXeZ%FddxJo?yydQmCbojjBrPhD8Oa z?TfjOT^(Zr4{6y?WH87W1Q`dGg}^hh46*?ZS0jH8MynVGAYi!R3l1Z~32>Sb#G8*0-g&P4bWUCt&A*e>qG`g+Ys6v``eu8TkQw2(D zb%t($g;e_df;OK`I{%IYFlg;GG?7m^Y)f_8VxK=&Hkb28y~Zgs+ddo-V;i|xxUu)z z8co{?gjwDnJ@{F!=;RC+3N=_as_O2dUrcvhly_3|+$DKV_ugtGf1Ky1t<-)Op`mQ5 zLe1Ssm8zlY-59XO60n>rw1)d)wjLXl4L`_vYxc+s14$NPazB4}{J+2B&YuT9fN!rRHwOF8S z%-^Y9tMn!Hz4=eg>B6g&I@{cpb)8zz)|ad&eAm)n??2t&-@lh%YTc{X#{Xa=TJ{ez z5f^?6!8qSx*V%1a+kSrM2@m)M|0XWF9n*n}VI|9DwFk4VNnKyepT2sZ@|TX@yGxvl R?)R7Q!1vJl&vsZ8{txYlDWU)X diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc deleted file mode 100644 index 00ad2b87204a0b20afd7f5b1091671b6db95a57d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 545 zcmYjNy>8nu5ayp;$8eB5LxutxVoJ(Xpa_yBMTevToGe-h+9X^$qNtG6;3-48_CfM8 zeE_bV`U)NDkhatKh&$YUcl^lj?hg+~AllQnU+gOc;CCwajl|+2x;u$M00A4IVGSYp z0t6EH2M}1oC3?m+5@ZVU>`$BnISeDM7M6QuS~pM7zWpct7*PpoC_uapYb?+L)VSriGw(PiVMy*5HNcZo8LOec5JUVuG{ zGn??&(Cg`kf_ndR@gVv!h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o10DKO;XkRlgvy zq^L4mzcevdzc@8FwYa3nNWZu;Q$IL2v8W^g`kf_ndR@gVv!h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o10YKO;XkRlgvy zq^L4mzcevdzc@8FwYa3nNWZu;Q$IL2v8W^ diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc deleted file mode 100644 index 975329643db64764625b762b10864b6cafc07357..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 225 zcmYj~F$%&!5Jh(r1Q8-$BZV2T7WD)w1e-Krbyr=@W|!HdNacCFj0Z?-Wo>8WBv|<2 z|IdHL%r1&XjC9*P@+I}N8~+MutjK;sA(`X_Gd$y*$slEM_#(<;-VTH`x?IOWHkKDr zo@{ckWrcc=-GMv9kgAVQ24`y&I8kA9g<2T!$|zsq41A*@H3F-xJ_zqEAn~bi4tz)5 fk9MH;3Ui0{s0#)C^TajnaBi%u3$@_%?oDQ2&7eGk diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc deleted file mode 100644 index 57822434e0f3a497f9e8c62109a66d7bbaad3424..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1267 zcmZux%Wl&^6dik<#Bq~8fdWFvD^P?QOI240p_Y~+7A=+9Zp>md%}iUTesyLn(TELd zxBU=)X;`xAFLcGdPC!O5(VX1J_|CZx`?%i^2&{MCey~TBke{eDmj}uwZ2cNQkeCQZ zxTzC6@J~}WqcL^R=A~ZNidzo(KtxNlZ-{71I&NRnxFg&{GU!Z}gH2wU^FoE?P!uUQ zJh+3HWPjk;c2)?PYLL8RE!7C^&D8>B6Sg)0lECdGc7+pD>5W^$mF;myP~qLu*au5j z27q(O11vp|`vO=9|JIG?XBw@wg}<~#(G|fBiI*UUInje0de?5eEc(EI-p(Pj16712>Ei(y`)+2qDM2AoSbC8U<)*D%4X$=rh_pop=gXjB*q?KS}p)_CM%7e3}^m-h6n4h30vcn&EXMl>lQ<5Betg#E#aLaTa=@C4y0 z0+z^jkB>j@>?Sf5)~l*S*cRf3bwTWZ%H>f3Q2P~*jO}c19d2*!yob}!1>4;|=W6O+ zz?h2&O9&4U@cITzoB@SY6%xenipB?!>9Vuz%;V4XY3&{OQJQ*hN2D diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc deleted file mode 100644 index a792bc3bae0aa9f90a8e42d68858ab984c49fadf..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1055 zcmY*Y&2HO95aupPk<^d>lBQ@*z4V|%MM*6R6bOO@&JTJ>9Ki8~m&M96l9%RRmn2a6 zl0$L|;0MVYGM_|F}1!F%U`hb-;Ab(0?OV`uDNk*_o6rk|^o zmW?Wl+Vt`gFsomlTHEb4B=CrK{hkCm2?HnLz!DeuiX|TUY0pN%APq4}```nk-MjRb z90Jk~AcW|W5$gXB4K|3uknWEzU9#_xW{9J7Ck@iwbPsl65B9BP<--BoQ4H>0x)gIC zejpb2O!VSg`mc$M*Vd@bkJIUNE@a!3Vm_TuXS3g?Vm_PwX$B``ex=K$%Fu8H&&Hk! z0GG1O8WSR@MlQ%QsIFn}}SL%+v*%{!;0>5rxe0YEFe1Gpe5aM`T#6nllq+ za%(li>Z~kK6m7mhePz2jc8$NtWO1%{2^p_wvrPN;7*t(C7m-bVVg+4}%0f^tut77_ zn8^lV6WH*kG$AZRm+H`77uzq8n`e_Vy`{noY7>;zrm-)_2PPC7e<4g?2&()xA|b@bU5C<0nr|zpQXOiXR+3p%@$SC5z9> z9OFthdVL3#WzDA)3D6M zmiVMvYx{SFwCkVkfqO2$_I!_Vevj?YbHMI@x-LDm#jblK_E^Y5_di$rHmCpq diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 0b6cc2bcbff79dfefbeeb1cbf6e4c5aede37a43c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 195 zcmWIL<>g`kf_ndR@gVv!h(HF6K#l_t7qb9~6oz01O-8?!3`HPe1o10FKO;XkRlgvy zq^L4mzcevdzc@8FwYa3nNWZu;Q$IL2v8W^ Date: Tue, 29 Dec 2020 21:42:16 +0100 Subject: [PATCH 2/4] recognize finger straight --- ...gle_solution.py => gesture_recognition.py} | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) rename gestures/{google_solution.py => gesture_recognition.py} (50%) diff --git a/gestures/google_solution.py b/gestures/gesture_recognition.py similarity index 50% rename from gestures/google_solution.py rename to gestures/gesture_recognition.py index 75fa9dd..8ad8ff5 100644 --- a/gestures/google_solution.py +++ b/gestures/gesture_recognition.py @@ -2,6 +2,13 @@ import cv2 import mediapipe as mp mp_drawing = mp.solutions.drawing_utils mp_hands = mp.solutions.hands +from math import sqrt + +def calculate_distance(ax, ay, bx,by): + distance = sqrt(((bx - ax) ** 2 + (by - ay) ** 2)) + return distance + + hands = mp_hands.Hands( min_detection_confidence=0.5, min_tracking_confidence=0.5) @@ -18,7 +25,7 @@ while cap.isOpened(): results = hands.process(image) - # Draw the hand annotations on the image. + # Draw the hand annotations on the image.g image.flags.writeable = True image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) if results.multi_hand_landmarks: @@ -26,6 +33,30 @@ while cap.isOpened(): mp_drawing.draw_landmarks( image, hand_landmarks, mp_hands.HAND_CONNECTIONS) #print(hand_landmarks) ## spójrz na to + if cv2.waitKey(33) == ord('s'): + if results.multi_hand_landmarks: + i = 0 + for hand_landmarks in results.multi_hand_landmarks: + ax = hand_landmarks.landmark[8].x + ay = hand_landmarks.landmark[8].y + bx = hand_landmarks.landmark[5].x + by = hand_landmarks.landmark[5].y + odleglosc_8_5 = calculate_distance(ax,ay, bx, by) + print(odleglosc_8_5) + ax = hand_landmarks.landmark[5].x + ay = hand_landmarks.landmark[5].y + bx = hand_landmarks.landmark[0].x + by = hand_landmarks.landmark[0].y + odleglosc_5_0 = calculate_distance(ax, ay, bx, by) + print(odleglosc_5_0) + if(odleglosc_5_0 < odleglosc_8_5 + 0.1): + print("wyprostowany") + else: + print("niewyprostowany") + + + # i += 1 + # print(hand_landmarks.) cv2.imshow('MediaPipe Hands', image) if cv2.waitKey(5) & 0xFF == 27: -- 2.20.1 From 8aec2319d10c2df04b390aabfaf1a8d758cad6e5 Mon Sep 17 00:00:00 2001 From: Michal Maciaszek Date: Tue, 29 Dec 2020 21:46:50 +0100 Subject: [PATCH 3/4] recognize finger straight --- gestures/gesture_recognition.py | 90 ++++++++++++++++----------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/gestures/gesture_recognition.py b/gestures/gesture_recognition.py index 8ad8ff5..01a8030 100644 --- a/gestures/gesture_recognition.py +++ b/gestures/gesture_recognition.py @@ -1,66 +1,64 @@ import cv2 import mediapipe as mp + mp_drawing = mp.solutions.drawing_utils mp_hands = mp.solutions.hands from math import sqrt -def calculate_distance(ax, ay, bx,by): - distance = sqrt(((bx - ax) ** 2 + (by - ay) ** 2)) - return distance +def calculate_distance(ax, ay, bx, by): + distance = sqrt(((bx - ax) ** 2 + (by - ay) ** 2)) + return distance hands = mp_hands.Hands( min_detection_confidence=0.5, min_tracking_confidence=0.5) cap = cv2.VideoCapture(0) while cap.isOpened(): - success, image = cap.read() + success, image = cap.read() - # Flip the image horizontally for a later selfie-view display, and convert - # the BGR image to RGB. - image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) - # To improve performance, optionally mark the image as not writeable to - # pass by reference. - image.flags.writeable = False - results = hands.process(image) + # Flip the image horizontally for a later selfie-view display, and convert + # the BGR image to RGB. + image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) + # To improve performance, optionally mark the image as not writeable to + # pass by reference. + image.flags.writeable = False + results = hands.process(image) - - # Draw the hand annotations on the image.g - image.flags.writeable = True - image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) - if results.multi_hand_landmarks: - for hand_landmarks in results.multi_hand_landmarks: - mp_drawing.draw_landmarks( - image, hand_landmarks, mp_hands.HAND_CONNECTIONS) - #print(hand_landmarks) ## spójrz na to - if cv2.waitKey(33) == ord('s'): + # Draw the hand annotations on the image.g + image.flags.writeable = True + image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) if results.multi_hand_landmarks: - i = 0 - for hand_landmarks in results.multi_hand_landmarks: - ax = hand_landmarks.landmark[8].x - ay = hand_landmarks.landmark[8].y - bx = hand_landmarks.landmark[5].x - by = hand_landmarks.landmark[5].y - odleglosc_8_5 = calculate_distance(ax,ay, bx, by) - print(odleglosc_8_5) - ax = hand_landmarks.landmark[5].x - ay = hand_landmarks.landmark[5].y - bx = hand_landmarks.landmark[0].x - by = hand_landmarks.landmark[0].y - odleglosc_5_0 = calculate_distance(ax, ay, bx, by) - print(odleglosc_5_0) - if(odleglosc_5_0 < odleglosc_8_5 + 0.1): - print("wyprostowany") - else: - print("niewyprostowany") + for hand_landmarks in results.multi_hand_landmarks: + mp_drawing.draw_landmarks( + image, hand_landmarks, mp_hands.HAND_CONNECTIONS) + # print(hand_landmarks) ## spójrz na to + if cv2.waitKey(33) == ord('s'): + if results.multi_hand_landmarks: + i = 0 + for hand_landmarks in results.multi_hand_landmarks: + ax = hand_landmarks.landmark[8].x + ay = hand_landmarks.landmark[8].y + bx = hand_landmarks.landmark[5].x + by = hand_landmarks.landmark[5].y + distance_8_5 = calculate_distance(ax, ay, bx, by) + print(distance_8_5) + ax = hand_landmarks.landmark[5].x + ay = hand_landmarks.landmark[5].y + bx = hand_landmarks.landmark[0].x + by = hand_landmarks.landmark[0].y + distance_5_0 = calculate_distance(ax, ay, bx, by) + print(distance_5_0) + if (distance_5_0 < distance_8_5 + 0.1): + print("wyprostowany") + else: + print("niewyprostowany") + # i += 1 + # print(hand_landmarks.) - # i += 1 - # print(hand_landmarks.) - - cv2.imshow('MediaPipe Hands', image) - if cv2.waitKey(5) & 0xFF == 27: - break + cv2.imshow('MediaPipe Hands', image) + if cv2.waitKey(5) & 0xFF == 27: + break hands.close() cap.release() - -- 2.20.1 From 6aa3dc2cb4f89f7fd73f602e85b8a4d517436261 Mon Sep 17 00:00:00 2001 From: Michal Maciaszek Date: Sun, 3 Jan 2021 13:33:47 +0100 Subject: [PATCH 4/4] added fingers --- gestures/gesture_recognition.py | 36 +++------------ gestures/simple_gestures_lib.py | 78 +++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 gestures/simple_gestures_lib.py diff --git a/gestures/gesture_recognition.py b/gestures/gesture_recognition.py index 01a8030..fd2f6a4 100644 --- a/gestures/gesture_recognition.py +++ b/gestures/gesture_recognition.py @@ -1,61 +1,35 @@ import cv2 import mediapipe as mp +import simple_gestures_lib as sgest mp_drawing = mp.solutions.drawing_utils mp_hands = mp.solutions.hands from math import sqrt -def calculate_distance(ax, ay, bx, by): - distance = sqrt(((bx - ax) ** 2 + (by - ay) ** 2)) - return distance - hands = mp_hands.Hands( min_detection_confidence=0.5, min_tracking_confidence=0.5) cap = cv2.VideoCapture(0) while cap.isOpened(): success, image = cap.read() - - # Flip the image horizontally for a later selfie-view display, and convert - # the BGR image to RGB. image = cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB) - # To improve performance, optionally mark the image as not writeable to - # pass by reference. image.flags.writeable = False results = hands.process(image) - # Draw the hand annotations on the image.g image.flags.writeable = True image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) if results.multi_hand_landmarks: for hand_landmarks in results.multi_hand_landmarks: mp_drawing.draw_landmarks( image, hand_landmarks, mp_hands.HAND_CONNECTIONS) - # print(hand_landmarks) ## spójrz na to if cv2.waitKey(33) == ord('s'): if results.multi_hand_landmarks: - i = 0 for hand_landmarks in results.multi_hand_landmarks: - ax = hand_landmarks.landmark[8].x - ay = hand_landmarks.landmark[8].y - bx = hand_landmarks.landmark[5].x - by = hand_landmarks.landmark[5].y - distance_8_5 = calculate_distance(ax, ay, bx, by) - print(distance_8_5) - ax = hand_landmarks.landmark[5].x - ay = hand_landmarks.landmark[5].y - bx = hand_landmarks.landmark[0].x - by = hand_landmarks.landmark[0].y - distance_5_0 = calculate_distance(ax, ay, bx, by) - print(distance_5_0) - if (distance_5_0 < distance_8_5 + 0.1): - print("wyprostowany") - else: - print("niewyprostowany") - - # i += 1 - # print(hand_landmarks.) + print(sgest.check_index_finger(hand_landmarks)) + print(sgest.check_middle_finger(hand_landmarks)) + print(sgest.check_ring_finger(hand_landmarks)) + print(sgest.check_pinky_finger(hand_landmarks)) cv2.imshow('MediaPipe Hands', image) if cv2.waitKey(5) & 0xFF == 27: diff --git a/gestures/simple_gestures_lib.py b/gestures/simple_gestures_lib.py new file mode 100644 index 0000000..ec7013e --- /dev/null +++ b/gestures/simple_gestures_lib.py @@ -0,0 +1,78 @@ +from math import sqrt + +def calculate_distance(ax, ay, bx, by): + distance = sqrt(((bx - ax) ** 2 + (by - ay) ** 2)) + return distance + +def check_index_finger(hand_landmarks): + ax = hand_landmarks.landmark[8].x + ay = hand_landmarks.landmark[8].y + bx = hand_landmarks.landmark[5].x + by = hand_landmarks.landmark[5].y + distance_8_5 = calculate_distance(ax, ay, bx, by) + ax = hand_landmarks.landmark[5].x + ay = hand_landmarks.landmark[5].y + bx = hand_landmarks.landmark[0].x + by = hand_landmarks.landmark[0].y + distance_5_0 = calculate_distance(ax, ay, bx, by) + + if (distance_5_0 < distance_8_5 + 0.1): + result = "wskazujacy_wyprostowany" + else: + result = "wskazujacy_niewyprostowany" + return (result, hand_landmarks.landmark[8].x, hand_landmarks.landmark[8].y) + +def check_middle_finger(hand_landmarks): + ax = hand_landmarks.landmark[12].x + ay = hand_landmarks.landmark[12].y + bx = hand_landmarks.landmark[9].x + by = hand_landmarks.landmark[9].y + distance_12_9 = calculate_distance(ax, ay, bx, by) + ax = hand_landmarks.landmark[9].x + ay = hand_landmarks.landmark[9].y + bx = hand_landmarks.landmark[0].x + by = hand_landmarks.landmark[0].y + distance_9_0 = calculate_distance(ax, ay, bx, by) + + if (distance_9_0 < distance_12_9 + 0.1): + result = "srodkowy_wyprostowany" + else: + result = "srodkowy_niewyprostowany" + return (result, hand_landmarks.landmark[12].x, hand_landmarks.landmark[12].y) + +def check_ring_finger(hand_landmarks): + ax = hand_landmarks.landmark[16].x + ay = hand_landmarks.landmark[16].y + bx = hand_landmarks.landmark[13].x + by = hand_landmarks.landmark[13].y + distance_16_13 = calculate_distance(ax, ay, bx, by) + ax = hand_landmarks.landmark[13].x + ay = hand_landmarks.landmark[13].y + bx = hand_landmarks.landmark[0].x + by = hand_landmarks.landmark[0].y + distance_13_0 = calculate_distance(ax, ay, bx, by) + + if (distance_13_0 < distance_16_13 + 0.1): + result = "serdeczny_wyprostowany" + else: + result = "serdeczny_niewyprostowany" + return (result, hand_landmarks.landmark[16].x, hand_landmarks.landmark[16].y) + +def check_pinky_finger(hand_landmarks): + ax = hand_landmarks.landmark[20].x + ay = hand_landmarks.landmark[20].y + bx = hand_landmarks.landmark[17].x + by = hand_landmarks.landmark[17].y + distance_20_17 = calculate_distance(ax, ay, bx, by) + ax = hand_landmarks.landmark[17].x + ay = hand_landmarks.landmark[17].y + bx = hand_landmarks.landmark[0].x + by = hand_landmarks.landmark[0].y + distance_17_0 = calculate_distance(ax, ay, bx, by) + + if (distance_17_0 < distance_20_17 + 0.1): + result = "maly_wyprostowany" + else: + result = "maly_niewyprostowany" + return (result, hand_landmarks.landmark[20].x, hand_landmarks.landmark[20].y) + -- 2.20.1