├── requirements.txt ├── 0.png ├── 1.png ├── 2.png ├── V1.png ├── V2.png ├── V3.png ├── papel.png ├── piedra.png ├── tijera.png ├── README.md ├── SeguimientoManos.py └── Juego.py /requirements.txt: -------------------------------------------------------------------------------- 1 | opencv-python==4.6.0.66 2 | imutils==0.5.4 3 | mediapipe==0.8.10.1 -------------------------------------------------------------------------------- /0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/0.png -------------------------------------------------------------------------------- /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/2.png -------------------------------------------------------------------------------- /V1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/V1.png -------------------------------------------------------------------------------- /V2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/V2.png -------------------------------------------------------------------------------- /V3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/V3.png -------------------------------------------------------------------------------- /papel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/papel.png -------------------------------------------------------------------------------- /piedra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/piedra.png -------------------------------------------------------------------------------- /tijera.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AprendeIngenia/Piedra-Papel-o-Tijera-con-IA/HEAD/tijera.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Piedra-Papel-o-Tijera-con-IA 2 | Hola chicos en este repositorio encontraran el codigo fuente para crear un algoritmo capaz de jugar piedra papel o tijera con ustedes utilizando vision artificial e inteligencia artificial. 3 | 4 | ### Explicacion: 5 | - En el archivo Juego.py encontraras el codigo general que debes implementar en Python con el fin de que puedas ejecutar tu propio juego de piedra papel o tijera en tiempo real, en este [Video](https://youtu.be/STXo_3V4gRE) te explico toda la programacion. 6 | 7 | - Recuerda que debes tener en tu carpeta el archivo SeguimientoManos.py, te explico el funcionamiento completo en este [Video](https://youtu.be/YLrjXRTDq6I), o lo repasamos de forma general en este [Video](https://youtu.be/STXo_3V4gRE) 8 | 9 | - En este video encontraras toda la programacion desde cero para que aprendas como funciona el programa [Video](https://youtu.be/STXo_3V4gRE). 10 | 11 | - Todos los requerimientos aprenderas a instalarlos en este [Video](https://youtu.be/STXo_3V4gRE), tambien puedes instalarlos con el archivo requirements.txt. Recuerda que fue ejecutado con Python 3.7 12 | 13 | ![Mini](https://user-images.githubusercontent.com/85022752/197960733-12fb7ac7-9005-45c1-a88f-b2afb3e4670f.jpg) 14 | 15 | # Recuerda que puedes contribuir a que siga desarrollando: 16 | Simplemente suscribiendote a mi canal de YouTube: 17 | - [Canal YouTube](https://www.youtube.com/channel/UCzwHEOCbsZLjfELperJ6VeQ/videos) 18 | 19 | ### Siguiendome en mis redes sociales: 20 | - [Instagram](https://www.instagram.com/santiagsanchezr/) 21 | - [Twitter](https://twitter.com/SantiagSanchezR) 22 | -------------------------------------------------------------------------------- /SeguimientoManos.py: -------------------------------------------------------------------------------- 1 | 2 | #------------------------------Importamos las librerias ----------------------------------- 3 | import math 4 | import cv2 5 | import mediapipe as mp 6 | import time 7 | 8 | #-------------------------------- Creamos una clase--------------------------------- 9 | class detectormanos(): 10 | #-------------------Inicializamos los parametros de la deteccion---------------- 11 | def __init__(self, mode=False, maxManos = 2, model_complexity=1, Confdeteccion = 0.5, Confsegui = 0.5): 12 | self.mode = mode #Creamos el objeto y el tendra su propia variable 13 | self.maxManos = maxManos #Lo mismo haremos con todos los objetos 14 | self.compl = model_complexity 15 | self.Confdeteccion = Confdeteccion 16 | self.Confsegui = Confsegui 17 | 18 | # ---------------------------- Creamos los objetos que detectaran las manos y las dibujaran---------------------- 19 | self.mpmanos = mp.solutions.hands 20 | self.manos = self.mpmanos.Hands(self.mode, self.maxManos, self.compl, self.Confdeteccion, self.Confsegui) 21 | self.dibujo = mp.solutions.drawing_utils 22 | self.tip = [4,8,12,16,20] 23 | 24 | #----------------------------------------Funcion para encontrar las manos----------------------------------- 25 | def encontrarmanos(self, frame, dibujar = True ): 26 | imgcolor = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 27 | self.resultados = self.manos.process(imgcolor) 28 | 29 | if self.resultados.multi_hand_landmarks: 30 | for mano in self.resultados.multi_hand_landmarks: 31 | if dibujar: 32 | self.dibujo.draw_landmarks(frame, mano, self.mpmanos.HAND_CONNECTIONS) # Dibujamos las conexiones de los puntos 33 | return frame 34 | 35 | #------------------------------------Funcion para encontrar la posicion---------------------------------- 36 | def encontrarposicion(self, frame, ManoNum = 0, dibujar = True, color = []): 37 | xlista = [] 38 | ylista = [] 39 | bbox = [] 40 | player = 0 41 | self.lista = [] 42 | if self.resultados.multi_hand_landmarks: 43 | miMano = self.resultados.multi_hand_landmarks[ManoNum] 44 | prueba = self.resultados.multi_hand_landmarks 45 | player = len(prueba) 46 | #print(player) 47 | for id, lm in enumerate(miMano.landmark): 48 | alto, ancho, c = frame.shape # Extraemos las dimensiones de los fps 49 | cx, cy = int(lm.x * ancho), int(lm.y * alto) # Convertimos la informacion en pixeles 50 | xlista.append(cx) 51 | ylista.append(cy) 52 | self.lista.append([id, cx, cy]) 53 | if dibujar: 54 | cv2.circle(frame,(cx, cy), 3, (0, 0, 0), cv2.FILLED) # Dibujamos un circulo 55 | 56 | xmin, xmax = min(xlista), max(xlista) 57 | ymin, ymax = min(ylista), max(ylista) 58 | bbox = xmin, ymin, xmax, ymax 59 | if dibujar: 60 | # Dibujamos cuadro 61 | cv2.rectangle(frame,(xmin - 20, ymin - 20), (xmax + 20, ymax + 20), color,2) 62 | return self.lista, bbox, player 63 | 64 | #----------------------------------Funcion para detectar y dibujar los dedos arriba------------------------ 65 | def dedosarriba(self): 66 | dedos = [] 67 | if self.lista[self.tip[0]][1] > self.lista[self.tip[0]-1][1]: 68 | dedos.append(1) 69 | else: 70 | dedos.append(0) 71 | 72 | for id in range (1,5): 73 | if self.lista[self.tip[id]][2] < self.lista[self.tip[id]-2][2]: 74 | dedos.append(1) 75 | else: 76 | dedos.append(0) 77 | 78 | return dedos 79 | 80 | #--------------------------- Funcion para detectar la distancia entre dedos---------------------------- 81 | def distancia(self, p1, p2, frame, dibujar = True, r = 15, t = 3): 82 | x1, y1 = self.lista[p1][1:] 83 | x2, y2 = self.lista[p2][1:] 84 | cx, cy = (x1 + x2) // 2, (y1 + y2) // 2 85 | if dibujar: 86 | cv2.line(frame, (x1,y1), (x2,y2), (0,0,255),t) 87 | cv2.circle(frame, (x1,y1), r, (0,0,255), cv2.FILLED) 88 | cv2.circle(frame, (x2,y2), r, (0, 0, 255), cv2.FILLED) 89 | cv2.circle(frame, (cx,cy), r, (0, 0, 255), cv2.FILLED) 90 | length = math.hypot(x2-x1, y2-y1) 91 | 92 | return length, frame, [x1, y1, x2, y2, cx, cy] 93 | 94 | #----------------------------------------------- Funcion principal-------------------- ---------------------------- 95 | def main(): 96 | ptiempo = 0 97 | ctiempo = 0 98 | 99 | # -------------------------------------Leemos la camara web --------------------------------------------- 100 | cap = cv2.VideoCapture(0) 101 | #-------------------------------------Crearemos el objeto ------------------------------------- 102 | detector = detectormanos() 103 | # ----------------------------- Realizamos la deteccion de manos--------------------------------------- 104 | while True: 105 | ret, frame = cap.read() 106 | #Una vez que obtengamos la imagen la enviaremos 107 | frame = detector.encontrarmanos(frame) 108 | lista, bbox = detector.encontrarposicion(frame) 109 | #if len(lista) != 0: 110 | #print(lista[4]) 111 | # ----------------------------------------Mostramos los fps --------------------------------------- 112 | ctiempo = time.time() 113 | fps = 1 / (ctiempo - ptiempo) 114 | ptiempo = ctiempo 115 | 116 | cv2.putText(frame, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3) 117 | 118 | cv2.imshow("Manos", frame) 119 | k = cv2.waitKey(1) 120 | 121 | if k == 27: 122 | break 123 | cap.release() 124 | cv2.destroyAllWindows() 125 | 126 | 127 | 128 | 129 | if __name__ == "__main__": 130 | main() 131 | -------------------------------------------------------------------------------- /Juego.py: -------------------------------------------------------------------------------- 1 | # Importamos las librerias 2 | import cv2 3 | import random 4 | import SeguimientoManos as sm # Clase manos 5 | import os 6 | import imutils 7 | 8 | # Declaracion de variables 9 | fs = False 10 | fu = False # Bandera up 11 | fd = False # Bandera down 12 | fj = False # Bandera juego 13 | fr = False # Bandera reset 14 | fgia = False # Bandera gana IA 15 | fgus = False # Bandera gana Usuario 16 | femp = False # Bandera empate 17 | fder = False # Bandera derecha 18 | fizq = False # Bandera izquierda 19 | conteo = 0 20 | 21 | # Accedemos a la carpeta 22 | path = 'Imagenes' 23 | images = [] 24 | clases = [] 25 | lista = os.listdir(path) 26 | 27 | # Leemos los rostros del DB 28 | for lis in lista: 29 | # Leemos las imagenes de los rostros 30 | imgdb = cv2.imread(f'{path}/{lis}') 31 | # Almacenamos imagen 32 | images.append(imgdb) 33 | # Almacenamos nombre 34 | clases.append(os.path.splitext(lis)[0]) 35 | 36 | print(clases) 37 | 38 | # Lectura de la camara 39 | cap = cv2.VideoCapture(0) 40 | 41 | # Declaramos el detector 42 | detector = sm.detectormanos(Confdeteccion=0.9) 43 | 44 | # Empezamos 45 | while True: 46 | # Lectura de la videocaptura 47 | ret, frame = cap.read() 48 | 49 | # Leemos teclado 50 | t = cv2.waitKey(1) 51 | 52 | # Extraemos la mitad del frame 53 | al, an, c = frame.shape 54 | cx = int(an/2) 55 | cy = int(al/2) 56 | 57 | # Espejo 58 | frame = cv2.flip(frame,1) 59 | 60 | # Encontramos las manos 61 | frame = detector.encontrarmanos(frame, dibujar=True) 62 | # Posiciones mano 1 63 | lista1, bbox1, jug = detector.encontrarposicion(frame, ManoNum=0, dibujar=True, color = [0,255,0]) 64 | 65 | # 1 Jugador 66 | if jug == 1: 67 | # Dividimos pantalla 68 | cv2.line(frame, (cx,0), (cx,480), (0,255,0), 2) 69 | 70 | # Mostramos jugadores 71 | cv2.rectangle(frame, (245, 25), (380, 60), (0, 0, 0), -1) 72 | cv2.putText(frame, '1 JUGADOR', (250, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.71,(0, 255, 0), 2) 73 | 74 | # Mensaje inicio 75 | cv2.rectangle(frame, (145, 425), (465, 460), (0, 0, 0), -1) 76 | cv2.putText(frame, 'PRESIONA S PARA EMPEZAR', (150, 450), cv2.FONT_HERSHEY_SIMPLEX, 0.71, (0, 255, 0), 2) 77 | 78 | # Presiona S 79 | if t == 83 or t == 115 or fs == True: 80 | # Cambiamos bandera 's' 81 | fs = True 82 | # Obtenemos posicion de la mano 83 | if len(lista1) != 0: 84 | # Extraemos las coordenadas del dedo corazon 85 | x1, y1 = lista1[9][1:] 86 | 87 | #print(conteo) 88 | # Conteo de juego 89 | if conteo <= 2: 90 | # Leemos la imagen inicial 91 | #print(name) 92 | img = images[conteo] 93 | # Redimensionamos 94 | img = imutils.resize(img, width=240, height=240) 95 | ali, ani, c = img.shape 96 | 97 | # Definimos en que parte de la pantalla esta 98 | # Izquierda 99 | if x1 < cx: 100 | # Banderas Lado 101 | fizq = True 102 | fder = False 103 | # Mostramos imagen 104 | frame[130: 130 + ali, 350: 350 + ani] = img 105 | 106 | # Empezamos conteo 107 | # Superamos el Umbral 108 | if y1 < cy - 40 and fd == False: 109 | fu = True 110 | cv2.circle(frame, (cx, cy), 5, (255, 255, 0), -1) 111 | # cv2.line(frame, (cx - cx, cy-40), (an, cy-40), (0, 0, 0), 1) 112 | 113 | # Bajamos del Umbral con Flag 114 | elif y1 > cy - 40 and fu == True: 115 | conteo = conteo + 1 116 | fu = False 117 | 118 | # Derecha 119 | elif x1 > cx: 120 | # Banderas Lado 121 | fder = True 122 | fizq = False 123 | # Mostramos la imagen 124 | frame[130: 130 + ali, 30: 30 + ani] = img 125 | 126 | # Empezamos conteo 127 | # Superamos el Umbral 128 | if y1 < cy - 40 and fd == False: 129 | fu = True 130 | cv2.circle(frame, (cx,cy), 5, (255,255,0), -1) 131 | #cv2.line(frame, (cx - cx, cy-40), (an, cy-40), (0, 0, 0), 1) 132 | 133 | # Bajamos del Umbral con Flag 134 | elif y1 > cy - 40 and fu == True: 135 | conteo = conteo + 1 136 | fu = False 137 | # Jugamos 138 | elif conteo == 3: 139 | # Si no hemos jugado jugamos 140 | if fj == False and fr == False: 141 | # Elegimos piedra papel o tijera 142 | juego = random.randint(3,5) 143 | fj = True 144 | 145 | # Izquierda 146 | if fizq == True and fder == False: 147 | # Mostramos 148 | img = images[juego] 149 | # Redimensionamos 150 | img = imutils.resize(img, width=240, height=240) 151 | ali, ani, c = img.shape 152 | # Mostramos imagen 153 | frame[130: 130 + ali, 350: 350 + ani] = img 154 | print(juego) 155 | 156 | # Si ya jugamos 157 | if fj == True and fr == False: 158 | # Extraemos valores de interes 159 | # Punta DI 160 | x2, y2 = lista1[8][1:] 161 | # Punta DC 162 | x3, y3 = lista1[12][1:] 163 | # Punta DA 164 | x4, y4 = lista1[16][1:] 165 | 166 | # Falange DI 167 | x22, y22 = lista1[6][1:] 168 | # Falange DC 169 | x33, y33 = lista1[10][1:] 170 | # Falange DA 171 | x44, y44 = lista1[14][1:] 172 | 173 | # Condiciones de posicion 174 | # Piedra 175 | if x2 < x22 and x3 < x33 and x4 < x44: 176 | # IA PAPEL 177 | if juego == 3: 178 | # GANA IA 179 | print('GANA LA IA') 180 | # Bandera Ganador 181 | fgia = True 182 | fgus = False 183 | femp = False 184 | fr = True 185 | # IA PIEDRA 186 | elif juego == 4: 187 | # EMPATE 188 | print('EMPATE') 189 | # Bandera Ganador 190 | fgia = False 191 | fgus = False 192 | femp = True 193 | fr = True 194 | 195 | elif juego == 5: 196 | # GANA USUARIO 197 | print('GANA EL HUMANO') 198 | # Bandera Ganador 199 | fgia = False 200 | fgus = True 201 | femp = False 202 | fr = True 203 | 204 | 205 | # Papel 206 | elif x2 > x22 and x3 > x33 and x4 > x44: 207 | # IA PAPEL 208 | if juego == 3: 209 | # EMPATE 210 | print('EMPATE') 211 | fgia = False 212 | fgus = False 213 | fr = True 214 | femp = True 215 | # IA PIEDRA 216 | elif juego == 4: 217 | # GANA USUARIO 218 | print('GANA EL HUMANO') 219 | # Bandera Ganador 220 | fgia = False 221 | fgus = True 222 | femp = False 223 | fr = True 224 | elif juego == 5: 225 | # GANA LA IA 226 | print('GANA LA IA') 227 | # Bandera Ganador 228 | fgia = True 229 | fgus = False 230 | femp = False 231 | fr = True 232 | 233 | # Tijera 234 | elif x2 > x22 and x3 > x33 and x4 < x44: 235 | # IA PAPEL 236 | if juego == 3: 237 | # GANA EL USUARIO 238 | print('GANA EL HUMANO') 239 | # Bandera Ganador 240 | fgia = False 241 | fgus = True 242 | femp = False 243 | fr = True 244 | # IA PIEDRA 245 | elif juego == 4: 246 | # GANA LA IA 247 | print('GANA LA IA') 248 | # Bandera Ganador 249 | fgia = True 250 | fgus = False 251 | femp = False 252 | fr = True 253 | elif juego == 5: 254 | # EMPATE 255 | print('EMPATE') 256 | fgia = False 257 | fgus = False 258 | femp = True 259 | fr = True 260 | 261 | # Mostramos ganador 262 | # IA 263 | if fgia == True: 264 | # Mostramos 265 | gan = images[6] 266 | alig, anig, c = gan.shape 267 | # Mostramos imagen 268 | frame[70: 70 + alig, 180: 180 + anig] = gan 269 | 270 | # Reset 271 | if t == 82 or t == 114: 272 | fs = False 273 | fu = False 274 | fd = False 275 | fj = False 276 | fr = False 277 | fgia = False 278 | fgus = False 279 | femp = False 280 | fder = False 281 | fizq = False 282 | conteo = 0 283 | 284 | # USUARIO 285 | elif fgus == True: 286 | # Mostramos 287 | gan = images[7] 288 | alig, anig, c = gan.shape 289 | # Mostramos imagen 290 | frame[70: 70 + alig, 180: 180 + anig] = gan 291 | 292 | # Reset 293 | if t == 82 or t == 114: 294 | fs = False 295 | fu = False 296 | fd = False 297 | fj = False 298 | fr = False 299 | fgia = False 300 | fgus = False 301 | femp = False 302 | fder = False 303 | fizq = False 304 | conteo = 0 305 | 306 | # EMPATE 307 | elif femp == True: 308 | # Mostramos 309 | gan = images[8] 310 | alig, anig, c = gan.shape 311 | # Mostramos imagen 312 | frame[70: 70 + alig, 180: 180 + anig] = gan 313 | 314 | # Reset 315 | if t == 82 or t == 114: 316 | fs = False 317 | fu = False 318 | fd = False 319 | fj = False 320 | fr = False 321 | fgia = False 322 | fgus = False 323 | femp = False 324 | fder = False 325 | fizq = False 326 | conteo = 0 327 | 328 | 329 | # Derecha 330 | if fizq == False and fder == True: 331 | # Mostramos 332 | img = images[juego] 333 | # Redimensionamos 334 | img = imutils.resize(img, width=240, height=240) 335 | ali, ani, c = img.shape 336 | # Mostramos imagen 337 | frame[130: 130 + ali, 30: 30 + ani] = img 338 | print(juego) 339 | 340 | # Si ya jugamos 341 | if fj == True and fr == False: 342 | # Extraemos valores de interes 343 | # Punta DI 344 | x2, y2 = lista1[8][1:] 345 | # Punta DC 346 | x3, y3 = lista1[12][1:] 347 | # Punta DA 348 | x4, y4 = lista1[16][1:] 349 | 350 | # Falange DI 351 | x22, y22 = lista1[6][1:] 352 | # Falange DC 353 | x33, y33 = lista1[10][1:] 354 | # Falange DA 355 | x44, y44 = lista1[14][1:] 356 | 357 | # Condiciones de posicion 358 | # Piedra 359 | if x2 > x22 and x3 > x33 and x4 > x44: 360 | # IA PAPEL 361 | if juego == 3: 362 | # GANA IA 363 | print('GANA LA IA') 364 | # Bandera Ganador 365 | fgia = True 366 | fgus = False 367 | femp = False 368 | fr = True 369 | # IA PIEDRA 370 | elif juego == 4: 371 | # EMPATE 372 | print('EMPATE') 373 | # Bandera Ganador 374 | fgia = False 375 | fgus = False 376 | femp = True 377 | fr = True 378 | 379 | elif juego == 5: 380 | # GANA USUARIO 381 | print('GANA EL HUMANO') 382 | # Bandera Ganador 383 | fgia = False 384 | fgus = True 385 | femp = False 386 | fr = True 387 | 388 | 389 | # Papel 390 | elif x2 < x22 and x3 < x33 and x4 < x44: 391 | # IA PAPEL 392 | if juego == 3: 393 | # EMPATE 394 | print('EMPATE') 395 | fgia = False 396 | fgus = False 397 | fr = True 398 | femp = True 399 | # IA PIEDRA 400 | elif juego == 4: 401 | # GANA USUARIO 402 | print('GANA EL HUMANO') 403 | # Bandera Ganador 404 | fgia = False 405 | fgus = True 406 | femp = False 407 | fr = True 408 | elif juego == 5: 409 | # GANA LA IA 410 | print('GANA LA IA') 411 | # Bandera Ganador 412 | fgia = True 413 | fgus = False 414 | femp = False 415 | fr = True 416 | 417 | # Tijera 418 | elif x2 < x22 and x3 < x33 and x4 > x44: 419 | # IA PAPEL 420 | if juego == 3: 421 | # GANA EL USUARIO 422 | print('GANA EL HUMANO') 423 | # Bandera Ganador 424 | fgia = False 425 | fgus = True 426 | femp = False 427 | fr = True 428 | # IA PIEDRA 429 | elif juego == 4: 430 | # GANA LA IA 431 | print('GANA LA IA') 432 | # Bandera Ganador 433 | fgia = True 434 | fgus = False 435 | femp = False 436 | fr = True 437 | elif juego == 5: 438 | # EMPATE 439 | print('EMPATE') 440 | fgia = False 441 | fgus = False 442 | femp = True 443 | fr = True 444 | 445 | # Mostramos ganador 446 | # IA 447 | if fgia == True: 448 | # Mostramos 449 | gan = images[6] 450 | alig, anig, c = gan.shape 451 | # Mostramos imagen 452 | frame[70: 70 + alig, 180: 180 + anig] = gan 453 | 454 | # Reset 455 | if t == 82 or t == 114: 456 | fs = False 457 | fu = False 458 | fd = False 459 | fj = False 460 | fr = False 461 | fgia = False 462 | fgus = False 463 | femp = False 464 | fder = False 465 | fizq = False 466 | conteo = 0 467 | 468 | # USUARIO 469 | elif fgus == True: 470 | # Mostramos 471 | gan = images[7] 472 | alig, anig, c = gan.shape 473 | # Mostramos imagen 474 | frame[70: 70 + alig, 180: 180 + anig] = gan 475 | 476 | # Reset 477 | if t == 82 or t == 114: 478 | fs = False 479 | fu = False 480 | fd = False 481 | fj = False 482 | fr = False 483 | fgia = False 484 | fgus = False 485 | femp = False 486 | fder = False 487 | fizq = False 488 | conteo = 0 489 | 490 | # EMPATE 491 | elif femp == True: 492 | # Mostramos 493 | gan = images[8] 494 | alig, anig, c = gan.shape 495 | # Mostramos imagen 496 | frame[70: 70 + alig, 180: 180 + anig] = gan 497 | 498 | # Reset 499 | if t == 82 or t == 114: 500 | fs = False 501 | fu = False 502 | fd = False 503 | fj = False 504 | fr = False 505 | fgia = False 506 | fgus = False 507 | femp = False 508 | fder = False 509 | fizq = False 510 | conteo = 0 511 | 512 | # 2 Jugadores 513 | elif jug == 2: 514 | # Encontramos la segunda mano 515 | lista2, bbox2, jug2 = detector.encontrarposicion(frame, ManoNum=1, dibujar=True, color = [255,0,0]) 516 | 517 | # Dividimos pantalla 518 | cv2.line(frame, (cx, 0), (cx, 240), (255, 0, 0), 2) 519 | cv2.line(frame, (cx, 240), (cx, 480), (0, 255, 0), 2) 520 | 521 | # Mostramos jugadores 522 | cv2.rectangle(frame, (245, 25), (408, 60), (0, 0, 0), -1) 523 | cv2.putText(frame, '2 JUGADORES', (250, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.71, (255, 0, 0), 2) 524 | 525 | # Mensaje inicio 526 | cv2.rectangle(frame, (145, 425), (465, 460), (0, 0, 0), -1) 527 | cv2.putText(frame, 'PRESIONA S PARA EMPEZAR', (150, 450), cv2.FONT_HERSHEY_SIMPLEX, 0.71, (255, 0, 0), 2) 528 | 529 | if t == 83 or t == 115: 530 | print('EMPEZAMOS') 531 | 532 | # 0 Jugadores 533 | elif jug == 0: 534 | # Mostramos jugadores 535 | cv2.rectangle(frame, (225, 25), (388, 60), (0, 0, 0), -1) 536 | cv2.putText(frame, '0 JUGADORES', (230, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.71, (0, 0, 255), 2) 537 | 538 | # Mensaje inicio 539 | cv2.rectangle(frame, (115, 425), (480, 460), (0, 0, 0), -1) 540 | cv2.putText(frame, 'LEVANTA TU MANO PARA INICIAR', (120, 450), cv2.FONT_HERSHEY_SIMPLEX, 0.71, (0, 0, 255), 2) 541 | 542 | 543 | # Mostramos frames 544 | cv2.imshow("JUEGO CON AI", frame) 545 | if t == 27: 546 | break 547 | cap.release() 548 | cv2.destroyAllWindows() 549 | --------------------------------------------------------------------------------