From 7d0f66cd8ed9d60f8511060539e2375374dfe74b Mon Sep 17 00:00:00 2001 From: arthurgriloss Date: Wed, 15 Dec 2021 10:18:03 +0100 Subject: [PATCH] att gesture recognition --- .../__pycache__/being.cpython-38.pyc | Bin 0 -> 2178 bytes .../__pycache__/food.cpython-38.pyc | Bin 0 -> 1199 bytes Biological Evolution/being.py | 83 +++ Biological Evolution/food.py | 25 + Biological Evolution/main.py | 102 +++ .../__pycache__/ann.cpython-38.pyc | Bin 1041 -> 1016 bytes Computer Vision/Gesture Recognition/ann.py | 5 +- .../collect_data_handtracking.py | 6 +- .../Gesture Recognition/hand_data.csv | 599 +++++++++--------- 9 files changed, 514 insertions(+), 306 deletions(-) create mode 100644 Biological Evolution/__pycache__/being.cpython-38.pyc create mode 100644 Biological Evolution/__pycache__/food.cpython-38.pyc create mode 100644 Biological Evolution/being.py create mode 100644 Biological Evolution/food.py create mode 100644 Biological Evolution/main.py diff --git a/Biological Evolution/__pycache__/being.cpython-38.pyc b/Biological Evolution/__pycache__/being.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9aeffb7edd60a6529ed26a9c3979d72cbe8d2d69 GIT binary patch literal 2178 zcma)7UvC>l5Z~R~JD>mLPZJZ0_*be*=s*gnst`g5RVAfDK_;}R5K*d=<2~EwI_G5X zoYax?L_PrG6U01J3Xgmmv@blsi@yRd64ZE zA3kG$(qy(tOzxwncR&7?!NoAUfLwCil_P z4UmZKaK(0n;!2z`taOybD3z-`jIJsuAET#=s)Vti%Bq6VR|{$pV^J-^)3R|NL~+t; z&><&{cyje6db$mw_>hG-C@5DBs8ABr8IoKMN$w6w?hUzen=~&>IbV607wsM;RRCXB z46glJAT-DB<5y@Co&@0O2v!N+nee&58NVWdJ0V84d;3vPF`|E9r0N|f#?^7Fof+AU znwcrKbgaTOK8cKb9ILEtymmx-?O_Y!AN0~Vi+fnr=yiMA6jiLFhLw0}R?qrrAdO6; zZc~@ZXNAZD$OY4@82(;YpY1-1vvz-PcWaQfd&%yD7(2D%M!kFM;Zd*Kr_FZvD9-B# z1LKEboWxle(iPI1AdGugz7j9l`N^UMXMM7uLD88sT1{cHDE$g%$j;e_odS~%-xa6g z6!<9q1|xhrqRL)}MaNlVkP1kF*HkLkSW}$Jp|tj}dM@}hHln|Q$&jPxV#GGsvtN+0yyHM3ku@J=?A#q8{F&D&aCTU_)cMd6 zUxZx={5CKtBkL;2`USGLmZV*TRztgVt#%pOpP;>Qt#-wFVV%{h+G&J>s__m6t@=J{ zNput?nQ;Jyk=fuNGV;5pUvC?E*pDGj2dR0RhkGGa*j3ew*PrLpuM zI!Vx()mQR`5To?BsC@$l*id!BFUM8|LDhk(eTQm^(-b3A9m4V4rOfJhLosrIs<3Qf%LxEeWXax_)dV6==Ogc1~Ut3Tay5~8Jr^8(4`yGXr*sv@@9-5qdHJ+iEhte%PJn3`no=0<_f#LT3{52r5Bv3QuFfgc5Z(1|94Bp{L={kRfI}}vv=Rq6AV3uedO=YI;t~Z}uGdLyxp7%LRE^Au z{*dO_e}wi5m;41z%v(2YMA>L(X4mue-cCMuI&DTPeAW%03dVlnu(~82_GlN|BotFT zWBpq5KHq1`QR0j#5j#IbUnu^G`Eo&?tQSG9E{6_#w2LPsV%F!1^&Q2PbH*rAC`nqX zhH^d*96>O)1Eh<4$R_wenXPi2x ze4^(&np2DwzF0gYd+`clorLci?>H}#GRY^V5#?E~O>3kR6%@%VHf?L3B&r;nHEWOK zWHc^KSBDdoACXV64ELpxMVt+_hiWYd(0##lht!`P^I;pO#sWYH{cdSRnTrg$3yHm1Mo;NUlsarX7!6~Y~QKF)V zxx5@f*{cT-ZP5UJA+`7k@f#OS;~t-m!lT&8k8xDi$N9t2;fVOD?9w<%WN zfdHEtNmmM4!Z9Ek6ym>Gpk0r9El+yV-uhB+!DEwzar46z7~uZDJjQ!jH}V=2P#_~E GbN&J%NAjEi literal 0 HcmV?d00001 diff --git a/Biological Evolution/being.py b/Biological Evolution/being.py new file mode 100644 index 0000000..768d196 --- /dev/null +++ b/Biological Evolution/being.py @@ -0,0 +1,83 @@ +import pygame +import sys + +class Being(object): + def __init__(self, grid_size, width, height): + self.up = (0, -1) + self.down = (0, 1) + self.right = (1, 0) + self.left = (-1, 0) + self.grid_size = grid_size + self.width = width + self.height = height + self.position = (grid_size, 0) + self.color = (255, 255, 255) + self.direction = (0, -1) + self.home = (grid_size, 0) + self.energy = 100 + self.status = "home" + + + def move(self): + cur = self.getPosition() + x, y = self.direction + new = (((cur[0] + (x * self.grid_size)) % self.width), (cur[1] + (y * self.grid_size)) % self.height) + if new[0] == self.width: + pass + elif new[1] == self.height - self.grid_size: + if new[0] == self.width - self.grid_size: + self.position = new + else: + pass + elif new[0] == 0: + pass + elif new[1] == 0: + pass + else: + self.position = new + + + def getPosition(self): + return self.position + + + def getDirection(self): + return self.direction + + def getEnergy(self): + return energy + + def setDirection(self, direction): + self.direction = direction + + + def go_home(self): + pass + + def feed(self, target): + pass + + def handle_keys(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + sys.exit + elif event.type == pygame.KEYDOWN: + if event.key == pygame.K_KP8: + self.direction = self.up + self.move() + elif event.key == pygame.K_KP2: + self.direction = self.down + self.move() + elif event.key == pygame.K_KP4: + self.direction = self.left + self.move() + elif event.key == pygame.K_KP6: + self.direction = self.right + self.move() + + + def draw(self, surface): + r = pygame.Rect((self.position[0], self.position[1]), (self.grid_size, self.grid_size)) + pygame.draw.rect(surface, self.color, r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) diff --git a/Biological Evolution/food.py b/Biological Evolution/food.py new file mode 100644 index 0000000..d4a282e --- /dev/null +++ b/Biological Evolution/food.py @@ -0,0 +1,25 @@ +import pygame +import random + +class Food(object): + def __init__(self, grid_size, grid_width, grid_height): + self.position = (0, 0) + self.color = (31, 61, 12) + self.grid_size = grid_size + self.grid_width = grid_width + self.grid_height = grid_height + self.randomize_position() + + + def getPosition(self): + return self.position + + + def randomize_position(self): + self.position = (random.randint(1, self.grid_width - 2) * self.grid_size, random.randint(1, self.grid_height - 2) * self.grid_size) + + + def draw(self, surface): + r = pygame.Rect((self.position[0], self.position[1]), (self.grid_size, self.grid_size)) + pygame.draw.rect(surface, self.color, r) + pygame.draw.rect(surface, (93, 216, 228), r, 1) \ No newline at end of file diff --git a/Biological Evolution/main.py b/Biological Evolution/main.py new file mode 100644 index 0000000..bb247e6 --- /dev/null +++ b/Biological Evolution/main.py @@ -0,0 +1,102 @@ +import pygame +import random +import sys +import numpy as np +from time import sleep +import pandas as pd +from being import Being +from food import Food + + +def dist_points(x1, x2, y1, y2): + # Find the distance between two points + return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** (1/2) + + +def step(being, food): + if len(food) != 0: + dist_food = np.zeros(len(food)) + for i in range(len(food)): + x_being = being.getPosition()[0] + y_being = being.getPosition()[1] + x_food = food[i].getPosition()[0] + y_food = food[i].getPosition()[1] + dist_food[i] = dist_points(x_being, x_food, y_being, y_food) + closest_tree = np.min(dist_food) + n_steps = ((closest_tree / 2) ** 2) * 2 + if being.getEnergy() >= n_steps: + being.feed(closest_tree) + else: + being.go_home() + else: + being.go_home() + + +def drawGrid(surface): + for y in range(0, int(height)): + for x in range(0, int(width)): + if (x + y) % 2 == 0: + r = pygame.Rect((x * grid_size, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (89, 60, 31), r) + else: + rr = pygame.Rect((x * grid_size, y * grid_size), (grid_size, grid_size)) + pygame.draw.rect(surface, (100, 70, 36), rr) + + +# Grid size parameters +height = 800 +width = 800 +grid_size = 20 +height_grid = int(height / grid_size) +width_grid = int(width / grid_size) + +# Possible movements +up = (0, -1) +down = (0, 1) +right = (1, 0) +left = (-1, 0) + +# Q-learning entries +state_space_size = width_grid * height_grid +action_size = 8 +q_table = np.zeros((int(state_space_size), action_size)) +state_table = np.zeros(height_grid * width_grid).tolist() +k = 0 +for j in range(0, height_grid): + for i in range(0, width_grid): + state_table[k] = (grid_size * i, grid_size * j) + k += 1 + + +def main(): + pygame.init() + clock = pygame.time.Clock() + screen = pygame.display.set_mode((width, height), 0, 32) + + surface = pygame.Surface(screen.get_size()) + surface = surface.convert() + drawGrid(surface) + + being = Being(grid_size, width, height) + food = [] + + for b in range(int(min([height_grid, width_grid]) - 1)): + food.append(Food(grid_size, width_grid, height_grid)) + + while(True): + clock.tick(30) + drawGrid(surface) + + being.handle_keys() + + for tree in food: + if being.getPosition() == tree.getPosition(): + food.remove(tree) + tree.draw(surface) + + being.draw(surface) + screen.blit(surface, (0, 0)) + pygame.display.update() + + +main() \ No newline at end of file diff --git a/Computer Vision/Gesture Recognition/__pycache__/ann.cpython-38.pyc b/Computer Vision/Gesture Recognition/__pycache__/ann.cpython-38.pyc index 3ee54c3481a771bcad0c73282833fdf03074330e..cb34caf8edaf05f327ad3333bd4e3e1461869194 100644 GIT binary patch delta 226 zcmbQp@q?W=l$V!_0SGMKyieG-k++?ZF>3Nu#xh>_%#w`Kq?mxpl8pSk$r4Oed`v)9 z%s}i6#Kk(37cl8~Fa|SdGWuz<6mbH@ia_QRaf1jxAfd@r#1EuyF;)}_fyBUsFi3`!>Rk++?Z@z&(2jAgt9l_eSZc>zWFS*gh-lO>p{_?UsJ zK-d|Gi_Io4VA4rsSin-lxR9}ysfH<-L6gx>leLHwC|d+Fv4|H$aDxbbAfd@zBmkst zF;?7StBfxwN=+#e2FZa55s(afT7FS^Vo{19kW