├── Contador de cartas con Canny ├── README.md ├── cartas.png ├── contandoCanny.gif └── objCanny.py ├── Contador de monedas aplicando thresholding ├── ProcesoTotal.gif ├── README.md ├── monedas.jpg └── monedasTH.py ├── Contanto por colores ├── README.md ├── contandoPorColor.gif ├── countColors.py └── lunares.png ├── Detección de Figuras Geométricas y colores ├── README.md ├── figFinal.gif ├── figuras3.png ├── figurasColores.py └── figurasColores2.png ├── Detección de Figuras Geométricas ├── README.md ├── figGeometricas2.gif ├── figurasColores.png ├── figurasColores2.png └── figurasGeometricas.py ├── Detección de Rostros ├── README.md ├── detectorRostro.py ├── detectorRostroVideo.py ├── haarcascade_frontalface_default.xml └── oficina.png ├── Efecto ESPEJO en Python-OpenCV ├── README.md ├── ave.jpg ├── espejo.gif ├── espejo.py └── espejoImagen.py ├── Movement detector (subtraction) ├── README.md ├── Video.mp4 ├── detectMov.py ├── finalMovDetect.gif └── proceso.png └── Ropa Invisible ├── README.md ├── colorInvisible.py ├── ropaInvisible.gif └── video1.mp4 /Contador de cartas con Canny/README.md: -------------------------------------------------------------------------------- 1 | ## 🧮 CONTANDO OBJETOS (Aplicando detección de bordes con CANNY) en Python-OpenCV 2 | 3 | Para una descripción más detallada el proceso realizado para encontrar cartas/barajas aplicando cv2.Canny, puedes dirigirte a: 4 | 5 | Mi blog: https://omes-va.com/contando-objetos-aplicando-deteccion-de-bordes-con-canny-en-python-opencv/ 6 | 7 | Video: https://youtu.be/jYSdkLBzD88 8 | 9 | A continuación puedes ver el proceso que se ha realizado en objCanny.py 10 | 11 | ![](contandoCanny.gif) 12 | -------------------------------------------------------------------------------- /Contador de cartas con Canny/cartas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Contador de cartas con Canny/cartas.png -------------------------------------------------------------------------------- /Contador de cartas con Canny/contandoCanny.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Contador de cartas con Canny/contandoCanny.gif -------------------------------------------------------------------------------- /Contador de cartas con Canny/objCanny.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | imagen = cv2.imread('cartas.png') 4 | grises = cv2.cvtColor(imagen, cv2.COLOR_BGR2GRAY) 5 | bordes = cv2.Canny(grises, 100, 200) 6 | 7 | #Para OpenCV3 8 | #_, ctns, _ = cv2.findContours(bordes, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) 9 | 10 | #Para OpenCV4 11 | ctns, _ = cv2.findContours(bordes, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) 12 | 13 | cv2.drawContours(imagen, ctns, -1, (0,0,255), 2) 14 | print('Número de contornos encontrados: ', len(ctns)) 15 | texto = 'Contornos encontrados: '+ str(len(ctns)) 16 | 17 | cv2.putText(imagen, texto, (10,20), cv2.FONT_HERSHEY_SIMPLEX, 0.7, 18 | (255, 0, 0), 1) 19 | 20 | cv2.imshow('Imagen', imagen) 21 | cv2.waitKey(0) 22 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Contador de monedas aplicando thresholding/ProcesoTotal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Contador de monedas aplicando thresholding/ProcesoTotal.gif -------------------------------------------------------------------------------- /Contador de monedas aplicando thresholding/README.md: -------------------------------------------------------------------------------- 1 | 🧮 CONTANDO OBJETOS (Aplicando Umbralización/Thersholding) en Python - OpenCV 2 | 3 | Para una descripción más detalla de este programa para la detección de monedas en una imagen usando umbralización simple o 4 | thresholding puedes visitar: 5 | 6 | Mi blog: https://omes-va.com/contando-objetos-aplicando-umbralizacion-thersholding/ 7 | 8 | Video: https://youtu.be/wBPIAGNTFzY 9 | 10 | 11 | A continuación puedes ver el proceso que se ha realizado en monedasTH.py 12 | 13 | 14 | ![](ProcesoTotal.gif) 15 | -------------------------------------------------------------------------------- /Contador de monedas aplicando thresholding/monedas.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Contador de monedas aplicando thresholding/monedas.jpg -------------------------------------------------------------------------------- /Contador de monedas aplicando thresholding/monedasTH.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | imagen = cv2.imread('monedas.jpg') 4 | grises = cv2.cvtColor(imagen, cv2.COLOR_BGR2GRAY) 5 | _,th = cv2.threshold(grises, 240, 255, cv2.THRESH_BINARY_INV) 6 | #Para OpenCV 3 7 | _,cnts,_ = cv2.findContours(th, cv2.RETR_EXTERNAL, 8 | cv2.CHAIN_APPROX_SIMPLE) 9 | #Para OpenCV 4 10 | #cnts,_ = cv2.findContours(th, cv2.RETR_EXTERNAL, 11 | # cv2.CHAIN_APPROX_SIMPLE) 12 | 13 | #cv2.drawContours(imagen, cnts, -1, (255,0,0),2) 14 | #print('Contornos: ', len(cnts)) 15 | 16 | font = cv2.FONT_HERSHEY_SIMPLEX 17 | i=0 18 | for c in cnts: 19 | M=cv2.moments(c) 20 | if (M["m00"]==0): M["m00"]=1 21 | x=int(M["m10"]/M["m00"]) 22 | y=int(M['m01']/M['m00']) 23 | 24 | mensaje = 'Num :' + str(i+1) 25 | cv2.putText(imagen,mensaje,(x-40,y),font,0.75, 26 | (255,0,0),2,cv2.LINE_AA) 27 | cv2.drawContours(imagen, [c], 0, (255,0,0),2) 28 | cv2.imshow('Imagen', imagen) 29 | cv2.waitKey(0) 30 | i = i+1 31 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Contanto por colores/README.md: -------------------------------------------------------------------------------- 1 | 🧮 Contando por COLORES en Python-OpenCV 2 | 3 | La aplicación que realiza countColors.py es, dada la imagen lunares.png va a enumerar cada uno de los círculos dependiendo 4 | de sus colores (amarillo, violeta, verde o rojo). Al final mostrará una imagen resumen de la cantidad de cpirculos encontrados 5 | por colores y la suma de todos ellos. Para una explicación más detallada puedes visitar: 6 | 7 | 8 | Mi blog: https://omes-va.com/contando-por-colores-en-python-opencv/ 9 | 10 | 11 | Video: https://youtu.be/DwPug0V8pcI 12 | 13 | 14 | A continuación puedes ver el proceso que se ha realizado en countColors.py: 15 | 16 | ![](contandoPorColor.gif) 17 | -------------------------------------------------------------------------------- /Contanto por colores/contandoPorColor.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Contanto por colores/contandoPorColor.gif -------------------------------------------------------------------------------- /Contanto por colores/countColors.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | def dibujarContorno(contornos, color): 5 | for (i, c) in enumerate(contornos): 6 | M = cv2.moments(c) 7 | if (M["m00"]==0): M["m00"]==1 8 | x = int(M["m10"]/M["m00"]) 9 | y = int(M["m01"]/M["m00"]) 10 | cv2.drawContours(imagen, [c], 0, color, 2) 11 | cv2.putText(imagen, str(i+1), (x-10,y+10), 1, 2,(0,0,0),2) 12 | 13 | amarilloBajo = np.array([20, 100, 20], np.uint8) 14 | amarilloAlto = np.array([32, 255, 255], np.uint8) 15 | 16 | violetaBajo = np.array([130, 100, 20], np.uint8) 17 | violetaAlto = np.array([145, 255, 255], np.uint8) 18 | 19 | verdeBajo = np.array([36, 100, 20], np.uint8) 20 | verdeAlto = np.array([70, 255, 255], np.uint8) 21 | 22 | rojoBajo1 = np.array([0, 100, 20], np.uint8) 23 | rojoAlto1 = np.array([10, 255, 255], np.uint8) 24 | rojoBajo2 = np.array([175, 100, 20], np.uint8) 25 | rojoAlto2 = np.array([180, 255, 255], np.uint8) 26 | 27 | imagen = cv2.imread('lunares.png') 28 | imagenHSV = cv2.cvtColor(imagen, cv2.COLOR_BGR2HSV) 29 | 30 | #Detectando colores 31 | maskAmarillo = cv2.inRange(imagenHSV, amarilloBajo, amarilloAlto) 32 | maskVioleta = cv2.inRange(imagenHSV, violetaBajo, violetaAlto) 33 | maskVerde = cv2.inRange(imagenHSV, verdeBajo, verdeAlto) 34 | maskRojo1 = cv2.inRange(imagenHSV, rojoBajo1, rojoAlto1) 35 | maskRojo2 = cv2.inRange(imagenHSV, rojoBajo2, rojoAlto2) 36 | maskRojo = cv2.add(maskRojo1, maskRojo2) 37 | 38 | #Encontrando contornos 39 | #OpenCV 3 40 | #contornosAmarillo = cv2.findContours(maskAmarillo, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1] 41 | #contornosVioleta = cv2.findContours(maskVioleta, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1] 42 | #contornosVerde = cv2.findContours(maskVerde, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1] 43 | #contornosRojo = cv2.findContours(maskRojo, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1] 44 | 45 | #OpenCV 4 46 | contornosAmarillo = cv2.findContours(maskAmarillo, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] 47 | contornosVioleta = cv2.findContours(maskVioleta, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] 48 | contornosVerde = cv2.findContours(maskVerde, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] 49 | contornosRojo = cv2.findContours(maskRojo, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] 50 | 51 | dibujarContorno(contornosAmarillo, (0, 255,255)) 52 | dibujarContorno(contornosVioleta, (140, 40, 120)) 53 | dibujarContorno(contornosVerde, (0, 255, 0)) 54 | dibujarContorno(contornosRojo, (0, 0, 255)) 55 | 56 | #Imagen Resumen 57 | imgResumen = 255 * np.ones((210,100,3), dtype = np.uint8) 58 | cv2.circle(imgResumen, (30,30), 15, (0,255,255), -1) 59 | cv2.circle(imgResumen, (30,70), 15, (140,40,120), -1) 60 | cv2.circle(imgResumen, (30,110), 15, (0,255,0), -1) 61 | cv2.circle(imgResumen, (30,150), 15, (0,0,255), -1) 62 | 63 | cv2.putText(imgResumen,str(len(contornosAmarillo)),(65,40), 1, 2,(0,0,0),2) 64 | cv2.putText(imgResumen,str(len(contornosVioleta)),(65,80), 1, 2,(0,0,0),2) 65 | cv2.putText(imgResumen,str(len(contornosVerde)),(65,120), 1, 2,(0,0,0),2) 66 | cv2.putText(imgResumen,str(len(contornosRojo)),(65,160), 1, 2,(0,0,0),2) 67 | totalCnts = len(contornosAmarillo) + len(contornosVioleta) + len(contornosVerde) + len(contornosRojo) 68 | cv2.putText(imgResumen,str(totalCnts),(55,200), 1, 2,(0,0,0),2) 69 | cv2.imshow('Resumen', imgResumen) 70 | 71 | #cv2.imshow('maskAmarillo', maskAmarillo) 72 | #cv2.imshow('maskVioleta', maskVioleta) 73 | #cv2.imshow('maskVerde', maskVerde) 74 | #cv2.imshow('maskRojo', maskRojo) 75 | cv2.imshow('Imagen', imagen) 76 | cv2.imwrite('conteo.png', imagen) 77 | cv2.waitKey(0) 78 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Contanto por colores/lunares.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Contanto por colores/lunares.png -------------------------------------------------------------------------------- /Detección de Figuras Geométricas y colores/README.md: -------------------------------------------------------------------------------- 1 | ## Detecta FIGURAS GEOMÉTRICAS y sus COLORES ❤️🧡💛💚💜 OpenCV - Python 2 | 3 | 4 | Para una descripción más detallada el proceso realizado puedes dirigirte a: 5 | 6 | Mi blog: https://omes-va.com/detecta-figuras-geometricas-y-sus-colores-opencv-python/ 7 | 8 | Video: https://youtu.be/CsS0V6pDsBM 9 | 10 | 11 | 12 | En figurasColores.py puedes encontrar la programación en Python para detectar figuras geométricas y sus colores. Puedes probar con las imágenes: 13 | figurasColores.png y figurasColores2.png, y tendrás un resultado como el siguiente: 14 | 15 | 16 | ![](figFinal.gif) 17 | -------------------------------------------------------------------------------- /Detección de Figuras Geométricas y colores/figFinal.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Figuras Geométricas y colores/figFinal.gif -------------------------------------------------------------------------------- /Detección de Figuras Geométricas y colores/figuras3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Figuras Geométricas y colores/figuras3.png -------------------------------------------------------------------------------- /Detección de Figuras Geométricas y colores/figurasColores.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | def figColor(imagenHSV): 5 | # Rojo 6 | rojoBajo1 = np.array([0, 100, 20], np.uint8) 7 | rojoAlto1 = np.array([10, 255, 255], np.uint8) 8 | rojoBajo2 = np.array([175, 100, 20], np.uint8) 9 | rojoAlto2 = np.array([180, 255, 255], np.uint8) 10 | 11 | # Naranja 12 | naranjaBajo = np.array([11, 100, 20], np.uint8) 13 | naranjaAlto = np.array([19, 255, 255], np.uint8) 14 | 15 | #Amarillo 16 | amarilloBajo = np.array([20, 100, 20], np.uint8) 17 | amarilloAlto = np.array([32, 255, 255], np.uint8) 18 | 19 | #Verde 20 | verdeBajo = np.array([36, 100, 20], np.uint8) 21 | verdeAlto = np.array([70, 255, 255], np.uint8) 22 | 23 | #Violeta 24 | violetaBajo = np.array([130, 100, 20], np.uint8) 25 | violetaAlto = np.array([145, 255, 255], np.uint8) 26 | 27 | #Rosa 28 | rosaBajo = np.array([146, 100, 20], np.uint8) 29 | rosaAlto = np.array([170, 255, 255], np.uint8) 30 | 31 | # Se buscan los colores en la imagen, segun los límites altos 32 | # y bajos dados 33 | maskRojo1 = cv2.inRange(imagenHSV, rojoBajo1, rojoAlto1) 34 | maskRojo2 = cv2.inRange(imagenHSV, rojoBajo2, rojoAlto2) 35 | maskRojo = cv2.add(maskRojo1, maskRojo2) 36 | maskNaranja = cv2.inRange(imagenHSV, naranjaBajo, naranjaAlto) 37 | maskAmarillo = cv2.inRange(imagenHSV, amarilloBajo, amarilloAlto) 38 | maskVerde = cv2.inRange(imagenHSV, verdeBajo, verdeAlto) 39 | maskVioleta = cv2.inRange(imagenHSV, violetaBajo, violetaAlto) 40 | maskRosa = cv2.inRange(imagenHSV, rosaBajo, rosaAlto) 41 | 42 | cntsRojo = cv2.findContours(maskRojo, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] #Reemplaza por 1, si tienes OpenCV3 43 | cntsNaranja = cv2.findContours(maskNaranja, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] #Reemplaza por 1, si tienes OpenCV3 44 | cntsAmarillo = cv2.findContours(maskAmarillo, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] #Reemplaza por 1, si tienes OpenCV3 45 | cntsVerde = cv2.findContours(maskVerde, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] #Reemplaza por 1, si tienes OpenCV3 46 | cntsVioleta = cv2.findContours(maskVioleta, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] #Reemplaza por 1, si tienes OpenCV3 47 | cntsRosa = cv2.findContours(maskRosa, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[0] #Reemplaza por 1, si tienes OpenCV3 48 | 49 | if len(cntsRojo)>0: color = 'Rojo' 50 | elif len(cntsNaranja)>0: color = 'Naranja' 51 | elif len(cntsAmarillo)>0: color = 'Amarillo' 52 | elif len(cntsVerde)>0: color = 'Verde' 53 | elif len(cntsVioleta)>0: color = 'Violeta' 54 | elif len(cntsRosa)>0: color = 'Rosa' 55 | 56 | return color 57 | 58 | def figName(contorno,width,height): 59 | epsilon = 0.01*cv2.arcLength(contorno,True) 60 | approx = cv2.approxPolyDP(contorno,epsilon,True) 61 | 62 | if len(approx) == 3: 63 | namefig = 'Triangulo' 64 | 65 | if len(approx) == 4: 66 | aspect_ratio = float(width)/height 67 | if aspect_ratio == 1: 68 | namefig = 'Cuadrado' 69 | else: 70 | namefig = 'Rectangulo' 71 | 72 | if len(approx) == 5: 73 | namefig = 'Pentagono' 74 | 75 | if len(approx) == 6: 76 | namefig = 'Hexagono' 77 | 78 | if len(approx) > 10: 79 | namefig = 'Circulo' 80 | 81 | return namefig 82 | 83 | imagen = cv2.imread('figurasColores2.png') 84 | gray = cv2.cvtColor(imagen, cv2.COLOR_BGR2GRAY) 85 | canny = cv2.Canny(gray, 10,150) 86 | canny = cv2.dilate(canny,None,iterations=1) 87 | canny = cv2.erode(canny,None,iterations=1) 88 | #_,cnts,_ = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) #OpenCV 3 89 | cnts,_ = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) #OpenCV 4 90 | imageHSV = cv2.cvtColor(imagen, cv2.COLOR_BGR2HSV) 91 | 92 | for c in cnts: 93 | x, y, w, h = cv2.boundingRect(c) 94 | imAux = np.zeros(imagen.shape[:2], dtype="uint8") 95 | imAux = cv2.drawContours(imAux, [c], -1, 255, -1) 96 | maskHSV = cv2.bitwise_and(imageHSV,imageHSV, mask=imAux) 97 | name = figName(c,w,h) 98 | color = figColor(maskHSV) 99 | nameColor = name + ' ' + color 100 | cv2.putText(imagen,nameColor,(x,y-5),1,0.8,(0,255,0),1) 101 | cv2.imshow('imagen',imagen) 102 | cv2.waitKey(0) 103 | 104 | #cv2.imshow('imagen',imagen) 105 | #cv2.waitKey(0) 106 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Detección de Figuras Geométricas y colores/figurasColores2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Figuras Geométricas y colores/figurasColores2.png -------------------------------------------------------------------------------- /Detección de Figuras Geométricas/README.md: -------------------------------------------------------------------------------- 1 | ## Detectando FIGURAS GEOMÉTRICAS (🔵🔺⬛) con OpenCV - Python 2 | 3 | Para una descripción más detallada el proceso realizado puedes dirigirte a: 4 | 5 | Mi blog: https://omes-va.com/detectando-figuras-geometricas-con-opencv-python/ 6 | 7 | Video: https://youtu.be/R82EcsCgnfg 8 | 9 | El script figurasGeometricas.py muestra como detectar figuras geométricas simples: triángulos, rectángulos, cuadrados, pentágonos, hexágonos 10 | y círculos, lo puedes probar con las dos imágenes figurasColores.png y figurasColores2.png, y tendrás un resultado como el siguiente: 11 | 12 | 13 | ![](figGeometricas2.gif) 14 | -------------------------------------------------------------------------------- /Detección de Figuras Geométricas/figGeometricas2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Figuras Geométricas/figGeometricas2.gif -------------------------------------------------------------------------------- /Detección de Figuras Geométricas/figurasColores.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Figuras Geométricas/figurasColores.png -------------------------------------------------------------------------------- /Detección de Figuras Geométricas/figurasColores2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Figuras Geométricas/figurasColores2.png -------------------------------------------------------------------------------- /Detección de Figuras Geométricas/figurasGeometricas.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | image = cv2.imread('figurasColores2.png') 4 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 5 | canny = cv2.Canny(gray, 10, 150) 6 | canny = cv2.dilate(canny, None, iterations=1) 7 | canny = cv2.erode(canny, None, iterations=1) 8 | #_, th = cv2.threshold(gray, 10, 255, cv2.THRESH_BINARY) 9 | #_,cnts,_ = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# OpenCV 3 10 | cnts,_ = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# OpenCV 4 11 | #cv2.drawContours(image, cnts, -1, (0,255,0), 2) 12 | 13 | for c in cnts: 14 | epsilon = 0.01*cv2.arcLength(c,True) 15 | approx = cv2.approxPolyDP(c,epsilon,True) 16 | #print(len(approx)) 17 | x,y,w,h = cv2.boundingRect(approx) 18 | 19 | if len(approx)==3: 20 | cv2.putText(image,'Triangulo', (x,y-5),1,1,(0,255,0),1) 21 | 22 | if len(approx)==4: 23 | aspect_ratio = float(w)/h 24 | print('aspect_ratio= ', aspect_ratio) 25 | if aspect_ratio == 1: 26 | cv2.putText(image,'Cuadrado', (x,y-5),1,1,(0,255,0),1) 27 | else: 28 | cv2.putText(image,'Rectangulo', (x,y-5),1,1,(0,255,0),1) 29 | 30 | if len(approx)==5: 31 | cv2.putText(image,'Pentagono', (x,y-5),1,1,(0,255,0),1) 32 | 33 | if len(approx)==6: 34 | cv2.putText(image,'Hexagono', (x,y-5),1,1,(0,255,0),1) 35 | 36 | if len(approx)>10: 37 | cv2.putText(image,'Circulo', (x,y-5),1,1,(0,255,0),1) 38 | 39 | cv2.drawContours(image, [approx], 0, (0,255,0),2) 40 | cv2.imshow('image',image) 41 | cv2.waitKey(0) 42 | -------------------------------------------------------------------------------- /Detección de Rostros/README.md: -------------------------------------------------------------------------------- 1 | ## 👨 DETECCIÓN DE ROSTROS 👩 con Haar Cascades Python – OpenCV 2 | 3 | Para una descripción más detallada el proceso realizado para encontrar cartas/barajas aplicando cv2.Canny, puedes dirigirte a: 4 | 5 | Mi blog: https://omes-va.com/deteccion-de-rostros-con-haar-cascades-python-opencv/ 6 | 7 | Video: https://youtu.be/J1jlm-I1cTs 8 | 9 | 10 | Si visitas el blog o el video donde explico este tema podrás ver como usamos distintos valores para los argumentos usados en 11 | detectMultiScale, así que si tienes algunas interrogantes sobre como emplear la detección de objetos usando haar cascades en 12 | OpenCV, te recomiendo que le des un vistazo a la información que he preparado. :) 13 | -------------------------------------------------------------------------------- /Detección de Rostros/detectorRostro.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | faceClassif = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 5 | 6 | image = cv2.imread('oficina.png') 7 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 8 | 9 | faces = faceClassif.detectMultiScale(gray, 10 | scaleFactor=1.1, 11 | minNeighbors=5, 12 | minSize=(30,30), 13 | maxSize=(200,200)) 14 | 15 | for (x,y,w,h) in faces: 16 | cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2) 17 | 18 | cv2.imshow('image',image) 19 | cv2.waitKey(0) 20 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Detección de Rostros/detectorRostroVideo.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | cap = cv2.VideoCapture(0) 5 | 6 | faceClassif = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 7 | 8 | while True: 9 | ret,frame = cap.read() 10 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 11 | 12 | faces = faceClassif.detectMultiScale(gray, 1.3, 5) 13 | 14 | for (x,y,w,h) in faces: 15 | cv2.rectangle(frame, (x,y),(x+w,y+h),(0,255,0),2) 16 | 17 | cv2.imshow('frame',frame) 18 | 19 | if cv2.waitKey(1) & 0xFF == ord('q'): 20 | break 21 | cap.release() 22 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Detección de Rostros/oficina.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Detección de Rostros/oficina.png -------------------------------------------------------------------------------- /Efecto ESPEJO en Python-OpenCV/README.md: -------------------------------------------------------------------------------- 1 | ## Efecto ESPEJO en Python-OpenCV 2 | 3 | Para una descripción más detallada el proceso realizado para realizar el efecto espejo y explicación sobre la función cv2.flip, puedes dirigirte a: 4 | 5 | Mi blog: https://omes-va.com/cv2-flip-en-python-opencv/ 6 | 7 | Video: https://youtu.be/aDK-PaQACIU 8 | 9 | 10 | espejoImagen.py: Se prueba el funcionamiento de cv2.flip cuando el flip code es mayor, igual y menor a cero, empleando la imagen ave.jpg 11 | 12 | espejo.py: Se realiza el efeccto espejo sobre un video streaming. Si lo pruebas tendrás algo parecido a lo siguiente: 13 | 14 | ![](espejo.gif) 15 | -------------------------------------------------------------------------------- /Efecto ESPEJO en Python-OpenCV/ave.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Efecto ESPEJO en Python-OpenCV/ave.jpg -------------------------------------------------------------------------------- /Efecto ESPEJO en Python-OpenCV/espejo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Efecto ESPEJO en Python-OpenCV/espejo.gif -------------------------------------------------------------------------------- /Efecto ESPEJO en Python-OpenCV/espejo.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cap = cv2.VideoCapture(0) 4 | 5 | while True: 6 | ret, frame = cap.read() 7 | if ret == False: break 8 | print('frame.shape=', frame.shape) 9 | anchoMitad = frame.shape[1] // 2 10 | frame[:,:anchoMitad] = cv2.flip(frame[:,anchoMitad:],1) 11 | cv2.imshow('Frame',frame) 12 | 13 | if cv2.waitKey(1) & 0xFF == ord('q'): 14 | break 15 | 16 | cap.release() 17 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Efecto ESPEJO en Python-OpenCV/espejoImagen.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | imagen = cv2.imread('ave.jpg') 4 | flip_1 = cv2.flip(imagen,10) 5 | 6 | cv2.imshow('flip_1',flip_1) 7 | cv2.waitKey(0) 8 | 9 | ''' 10 | flip2 = cv2.flip(imagen,1) 11 | flip3 = cv2.flip(imagen,-1) 12 | 13 | cv2.imwrite('flip0.png',flip1) 14 | cv2.imwrite('flip1.png',flip2) 15 | cv2.imwrite('flip-1.png',flip3) 16 | ''' -------------------------------------------------------------------------------- /Movement detector (subtraction)/README.md: -------------------------------------------------------------------------------- 1 | 2 | # 👣 DETECCIÓN DE MOVIMIENTO (Con sustracción de imágenes) - OpenCV y Python 3 | 4 | Si deseas más información sobre la realización de este código, por favor dirígete al video que he realizado en youtube: https://youtu.be/kcmJQzu_q6M 5 | 6 | O dirígente al post de mi web: https://omes-va.com/deteccion-de-movimiento-con-sustraccion-de-imagenes-opencv-y-python/ 7 | 8 | El proceso realizado dentro de detectMov.py, con el video Video.mp4 es el siguiente: 9 | 10 | ![](proceso.png) 11 | 12 | Finalmente se obtendrá la detección de movimiento con sustracción de imágenes: 13 | 14 | ![](finalMovDetect.gif) 15 | -------------------------------------------------------------------------------- /Movement detector (subtraction)/Video.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Movement detector (subtraction)/Video.mp4 -------------------------------------------------------------------------------- /Movement detector (subtraction)/detectMov.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | video = cv2.VideoCapture('Video.mp4') 5 | 6 | i = 0 7 | while True: 8 | ret, frame = video.read() 9 | if ret == False: break 10 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 11 | if i == 20: 12 | bgGray = gray 13 | if i > 20: 14 | dif = cv2.absdiff(gray, bgGray) 15 | _, th = cv2.threshold(dif, 40, 255, cv2.THRESH_BINARY) 16 | # Para OpenCV 3 17 | #_, cnts, _ = cv2.findContours(th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 18 | # Para OpenCV 4 19 | cnts, _ = cv2.findContours(th, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) 20 | #cv2.drawContours(frame, cnts, -1, (0,0,255),2) 21 | 22 | for c in cnts: 23 | area = cv2.contourArea(c) 24 | if area > 9000: 25 | x,y,w,h = cv2.boundingRect(c) 26 | cv2.rectangle(frame, (x,y), (x+w,y+h),(0,255,0),2) 27 | 28 | cv2.imshow('Frame',frame) 29 | 30 | i = i+1 31 | if cv2.waitKey(30) & 0xFF == ord ('q'): 32 | break 33 | video.release() 34 | -------------------------------------------------------------------------------- /Movement detector (subtraction)/finalMovDetect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Movement detector (subtraction)/finalMovDetect.gif -------------------------------------------------------------------------------- /Movement detector (subtraction)/proceso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Movement detector (subtraction)/proceso.png -------------------------------------------------------------------------------- /Ropa Invisible/README.md: -------------------------------------------------------------------------------- 1 | # 👚 ROPA INVISIBLE - OpenCV y Python 2 | 3 | Para una descripción más detallada del proceso realizado para desarrollar esta pequeña aplicación, puedes dirigirte a: 4 | 5 | Mi blog: https://omes-va.com/ropa-invisible-opencv-y-python/ 6 | V 7 | ideo en youtube: https://youtu.be/fR7IQQJJAnk 8 | 9 | A continuación puedes ver como actúa el archivo colorInvisible.py, en el que habrá un efecto de invisibilidad en una chaqueta 10 | roja, veamos: 11 | 12 | ![](ropaInvisible.gif) 13 | -------------------------------------------------------------------------------- /Ropa Invisible/colorInvisible.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | cap = cv2.VideoCapture('video1.mp4') 5 | 6 | bg = None 7 | 8 | rojoBajo1 = np.array([0, 150, 40], np.uint8) 9 | rojoAlto1 = np.array([8, 255, 255], np.uint8) 10 | rojoBajo2 = np.array([170, 150, 40], np.uint8) 11 | rojoAlto2 = np.array([180, 255, 255], np.uint8) 12 | 13 | while True: 14 | 15 | ret, frame = cap.read() 16 | if ret == False: break 17 | 18 | if bg is None: 19 | bg = frame 20 | 21 | frameHSV = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 22 | maskRojo1 = cv2.inRange(frameHSV, rojoBajo1, rojoAlto1) 23 | maskRojo2 = cv2.inRange(frameHSV, rojoBajo2, rojoAlto2) 24 | mask = cv2.add(maskRojo1,maskRojo2) 25 | mask = cv2.medianBlur(mask, 13) 26 | kernel = np.ones((5,5),np.uint8) 27 | mask = cv2.dilate(mask, kernel, iterations=2) 28 | areaColor = cv2.bitwise_and(bg, bg, mask=mask) 29 | maskInv = cv2.bitwise_not(mask) 30 | sinAreaColor = cv2.bitwise_and(frame,frame,mask=maskInv) 31 | finalFrame = cv2.addWeighted(areaColor,1,sinAreaColor,1,0) 32 | cv2.imshow('Frame',frame) 33 | #cv2.imshow('mask', mask) 34 | #cv2.imshow('areaColor', areaColor) 35 | #cv2.imshow('maskInv',maskInv) 36 | #cv2.imshow('sinAreaColor',sinAreaColor) 37 | cv2.imshow('finalFrame',finalFrame) 38 | if cv2.waitKey(1) & 0xFF == ord('q'): 39 | break 40 | 41 | cap.release() 42 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Ropa Invisible/ropaInvisible.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Ropa Invisible/ropaInvisible.gif -------------------------------------------------------------------------------- /Ropa Invisible/video1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GabySol/OmesTutorials/27e347c5038537ffea3666375bebc07beb39d07d/Ropa Invisible/video1.mp4 --------------------------------------------------------------------------------