├── samples └── data │ ├── vtest.avi │ ├── messi5.jpg │ ├── opencv-logo.png │ └── starry_night.jpg ├── Dockerfile ├── test_image_matplotlib.py ├── test_image.py ├── test_playvideo.py ├── test_webcam.py ├── test_playvideo_2.py ├── README.md └── instalacion-opencv.md /samples/data/vtest.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CAChemE/curso-opencv-python/HEAD/samples/data/vtest.avi -------------------------------------------------------------------------------- /samples/data/messi5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CAChemE/curso-opencv-python/HEAD/samples/data/messi5.jpg -------------------------------------------------------------------------------- /samples/data/opencv-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CAChemE/curso-opencv-python/HEAD/samples/data/opencv-logo.png -------------------------------------------------------------------------------- /samples/data/starry_night.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CAChemE/curso-opencv-python/HEAD/samples/data/starry_night.jpg -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM andrewosh/binder-base 2 | 3 | MAINTAINER FJ Navarro 4 | 5 | USER root 6 | 7 | RUN apt-get update 8 | RUN apt-get install -y libgtk2.0-common 9 | RUN conda install -n python3 -c menpo opencv3=3.1 10 | 11 | USER main 12 | -------------------------------------------------------------------------------- /test_image_matplotlib.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | from matplotlib import pyplot as plt 4 | 5 | img = cv2.imread('samples/data/starry_night.jpg',0) 6 | plt.imshow(img, cmap = 'gray', interpolation = 'bicubic') 7 | plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis 8 | plt.show() 9 | -------------------------------------------------------------------------------- /test_image.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | #img = cv2.imread('samples/data/messi5.jpg',0) 5 | img = cv2.imread('samples/data/starry_night.jpg',0) 6 | cv2.imshow('image',img) 7 | k = cv2.waitKey(0) 8 | if k == 27: # wait for ESC key to exit 9 | cv2.destroyAllWindows() 10 | elif k == ord('s'): # wait for 's' key to save and exit 11 | cv2.imwrite('messigray.png',img) 12 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /test_playvideo.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | cap = cv2.VideoCapture('samples/data/vtest.avi') 5 | 6 | _, frame = cap.read() 7 | 8 | assert frame is not None, "Fmmpeg seems not to be installed properly" 9 | 10 | while(cap.isOpened()): 11 | ret, frame = cap.read() 12 | if ret == True: 13 | 14 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 15 | 16 | cv2.imshow('frame',gray) 17 | if cv2.waitKey(1) & 0xFF == ord('q'): 18 | break 19 | else: 20 | break 21 | 22 | 23 | cap.release() 24 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /test_webcam.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | cap = cv2.VideoCapture(0) 5 | # Webcam test 6 | 7 | while(cap.isOpened()): 8 | # Capture frame-by-frame 9 | ret, frame = cap.read() 10 | 11 | # Our operations on the frame come here 12 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 13 | 14 | # Display the resulting frame 15 | cv2.imshow('frame',gray) 16 | if cv2.waitKey(1) & 0xFF == ord('q'): 17 | break 18 | 19 | # When everything done, release the capture 20 | cap.release() 21 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /test_playvideo_2.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | cap = cv2.VideoCapture('samples/data/vtest.avi') 5 | 6 | _, frame = cap.read() 7 | 8 | assert frame is not None, "Fmmpeg seems not to be installed properly" 9 | 10 | kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3)) 11 | fgbg = cv2.createBackgroundSubtractorMOG2() 12 | 13 | while(cap.isOpened()): 14 | ret, frame = cap.read() 15 | 16 | if ret == True: 17 | 18 | fgmask = fgbg.apply(frame) 19 | fgmask = cv2.morphologyEx(fgmask, cv2.MORPH_OPEN, kernel) 20 | 21 | cv2.imshow('frame',fgmask) 22 | if cv2.waitKey(1) & 0xFF == ord('q'): 23 | break 24 | else: 25 | break 26 | 27 | cap.release() 28 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Curso OpenCV Python 2 | #### Por Rubén Crespo Cano ([CAChemE.org](http://cacheme.org/curso-vision-artificial-opencv-python/)) 3 | 4 | La visión artificial o visión por computador es una disciplina científica que incluye métodos para adquirir, procesar, analizar y comprender las imágenes del mundo real con el fin de producir información numérica o simbólica para que puedan ser tratados por un computador. Esta comprensión se consigue gracias a distintos campos como la geometría, la estadística, la física y otras disciplinas. 5 | 6 | La visión artificial se incluye en varios planes de estudio de los distintos grados en ingeniería o másteres como el de robótica, pero, normalmente, se utiliza software propietario como MATLAB para ello. Este taller permitiría que los estudiantes conozcan herramientas informáticas libres y gratuitas específicas para la resolución de los problemas de visión artificial con los que se enfrentarán en su vida profesional. 7 | 8 | ### [Intrucciones de instalación (Windows, Mac, Linux)](https://github.com/CAChemE/curso-opencv-python/blob/master/instalacion-opencv.md) 9 | 10 | ### [Materiales del curso de visión artificial con OpenCV y Python](https://github.com/CAChemE/opencv-python) 11 | 12 | El material de este curso está orientado a estudiantes con conocimientos de programación en un lenguaje de alto nivel (Python, MATLAB, R, C++, C, Java, etc.) y hará una introducción a las diferentes funcionalidades disponibles y su uso mediante la interfaz de Python de [OpenCV](http://opencv.org/) (otros ejemplos interesantes se pueden encontrar en [Scikit-Image](http://scikit-image.org/)). 13 | 14 | 15 | 16 | 1. [Introducción](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#1.-Introducción) 17 | 2. [Instalación](https://github.com/CAChemE/curso-opencv-python/blob/master/instalacion-opencv.md) 18 | 3. [Manejo de ficheros, cámaras e interfaces gráficas de usuario](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#3.-Manejo-de-ficheros,-cámaras-e-interfaces-gráficas-de-usuario) 19 | 4. [Filtrado y convolución de imágenes](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#4.-Filtrado-y-suavizado-de-imágenes) 20 | 5. [Gradientes](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#5.-Gradientes) 21 | 6. [Canny edge detector](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#6.-Canny-edge-detector) 22 | 7. [Histogramas](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#8.-Template-matching) 23 | 8. [Template Matching](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#7.-Histogramas) 24 | 9. [Detección-de-caras](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#9.-Detección-de-caras) 25 | 10. [Colores y espacios de color](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#10.-Colores-y-espacios-de-color) 26 | 11. [Detección y extracción de características](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#11.-Detección-y-extracción-de-características-(feature-detection)) 27 | 12. [Aprendizaje automático](http://nbviewer.jupyter.org/github/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb#12.-Aprendizaje-automático) 28 | 29 | Si tienes problemas con enlaces anteriores, prueba con [este otro](https://github.com/CAChemE/opencv-python/blob/master/opencv-and-python.ipynb) 30 | 31 | [![Binder](http://mybinder.org/badge.svg)](http://mybinder.org:/repo/cacheme/curso-opencv-python) 32 | 33 | 34 | +información: http://cacheme.org/curso-vision-artificial-opencv-python 35 | -------------------------------------------------------------------------------- /instalacion-opencv.md: -------------------------------------------------------------------------------- 1 | Comandos para instalar OpenCV con miniconda ([DOC](https://conda.io/docs/using/envs.html)) y Python 3 para Windows, Mac o Linux. 2 | 3 | Testeado en Windows 7 x64: 4 | 5 | 6 | 0. Si aún no tienes Anaconda o miniconda instalado en tu ordenador: descarga e instala [miniconda con Python 3.x (64-bit)](https://conda.io/miniconda.html) 7 | 8 | 1. Actualiza conda a la última versión disponible y crea un entorno desde la ventana de comandos o terminal: 9 | 10 | `conda update conda` 11 | 12 | `conda create --name pyOCV python==3.5.0` 13 | 14 | 2. Activación de entorno: 15 | 16 | Windows: `activate pyOCV` 17 | 18 | Linux/Mac: `$source activate pyOCV` 19 | 20 | **Comprueba que la ventana de comandos se ha activado el entorno correctamente (aparece junto a la ruta).** 21 | 22 | 3. Instalación de OpenCV junto a sus dependencias (mínimas) 23 | 24 | `conda install -c menpo opencv3=3.1` 25 | 26 | 4. Instalación de librerías auxiliares para el curso 27 | 28 | `conda install jupyter matplotlib` 29 | 30 | 5. [Descarga este repositorio](https://github.com/CAChemE/curso-opencv-python/archive/master.zip) y comprueba que eres capaz de ejecutar el script `test_playvideo.py` 31 | 32 | `python test_playvideo.py` 33 | 34 | --- 35 | 36 | Log de instalación: 37 | 38 | ``` 39 | C:\Users\franz\Desktop\OpenCV-intro>conda update conda 40 | Fetching package metadata ............. 41 | Solving package specifications: . 42 | 43 | # All requested packages already installed. 44 | # packages in environment at C:\Users\franz\Miniconda3: 45 | # 46 | conda 4.3.11 py35_0 47 | 48 | C:\Users\franz\Desktop\OpenCV-intro>conda create --name pyOCV python==3.5.0 49 | Fetching package metadata ............. 50 | Solving package specifications: . 51 | 52 | Package plan for installation in environment C:\Users\franz\Miniconda3\envs\pyO 53 | 54 | The following NEW packages will be INSTALLED: 55 | 56 | msvc_runtime: 1.0.1-vc14_0 [vc14] 57 | pip: 9.0.1-py35_1 58 | python: 3.5.0-4 59 | setuptools: 27.2.0-py35_1 60 | wheel: 0.29.0-py35_0 61 | 62 | Proceed ([y]/n)? y 63 | 64 | msvc_runtime-1 100% |###############################| Time: 0:00:01 1.75 MB/s 65 | python-3.5.0-4 100% |###############################| Time: 0:00:09 2.86 MB/s 66 | # 67 | # To activate this environment, use: 68 | # > activate pyOCV 69 | # 70 | # To deactivate this environment, use: 71 | # > deactivate pyOCV 72 | # 73 | # * for power-users using bash, you must source 74 | # 75 | 76 | 77 | C:\Users\franz\Desktop\OpenCV-intro>activate pyOCV 78 | 79 | (pyOCV) C:\Users\franz\Desktop\OpenCV-intro>conda install -c menpo opencv3=3.1 80 | Fetching package metadata ............... 81 | Solving package specifications: . 82 | 83 | Package plan for installation in environment C:\Users\franz\Miniconda3\envs\pyOCV: 84 | 85 | The following NEW packages will be INSTALLED: 86 | 87 | mkl: 2017.0.1-0 88 | numpy: 1.12.0-py35_0 89 | opencv3: 3.1.0-py35_0 menpo 90 | 91 | Proceed ([y]/n)? y 92 | 93 | numpy-1.12.0-p 100% |###############################| Time: 0:00:01 2.90 MB/s 94 | opencv3-3.1.0- 100% |###############################| Time: 0:00:26 1.67 MB/s 95 | 96 | (pyOCV) C:\Users\franz\Desktop\OpenCV-intro>conda install jupyter matplotlib scipy 97 | Fetching package metadata ............... 98 | Solving package specifications: . 99 | 100 | Package plan for installation in environment C:\Users\franz\Miniconda3\envs\pyOCV: 101 | 102 | The following NEW packages will be INSTALLED: 103 | 104 | bleach: 1.5.0-py35_0 105 | colorama: 0.3.7-py35_0 106 | cycler: 0.10.0-py35_0 107 | decorator: 4.0.11-py35_0 108 | entrypoints: 0.2.2-py35_1 109 | html5lib: 0.999-py35_0 110 | icu: 57.1-vc14_0 [vc14] 111 | ipykernel: 4.5.2-py35_0 112 | ipython: 5.1.0-py35_0 113 | ipython_genutils: 0.1.0-py35_0 114 | ipywidgets: 5.1.5-py35_0 menpo 115 | jinja2: 2.9.4-py35_0 116 | jpeg: 9b-vc14_0 [vc14] 117 | jsonschema: 2.5.1-py35_0 118 | jupyter: 1.0.0-py35_3 119 | jupyter_client: 4.4.0-py35_0 120 | jupyter_console: 5.0.0-py35_0 121 | jupyter_core: 4.2.1-py35_0 122 | libpng: 1.6.27-vc14_0 [vc14] 123 | markupsafe: 0.23-py35_2 124 | matplotlib: 2.0.0-np112py35_0 125 | mistune: 0.7.3-py35_0 126 | nbconvert: 5.1.1-py35_0 127 | nbformat: 4.2.0-py35_0 128 | notebook: 4.3.1-py35_1 129 | openssl: 1.0.2k-vc14_0 [vc14] 130 | pandocfilters: 1.4.1-py35_0 131 | path.py: 10.0-py35_0 132 | pickleshare: 0.7.4-py35_0 133 | prompt_toolkit: 1.0.9-py35_0 134 | pygments: 2.1.3-py35_0 135 | pyparsing: 2.1.4-py35_0 136 | pyqt: 5.6.0-py35_2 137 | python-dateutil: 2.6.0-py35_0 138 | pytz: 2016.10-py35_0 139 | pyzmq: 16.0.2-py35_0 140 | qt: 5.6.2-vc14_3 [vc14] 141 | qtconsole: 4.2.1-py35_2 142 | scipy: 0.18.1-np112py35_1 143 | simplegeneric: 0.8.1-py35_1 144 | sip: 4.18-py35_0 145 | six: 1.10.0-py35_0 146 | testpath: 0.3-py35_0 147 | tk: 8.5.18-vc14_0 [vc14] 148 | tornado: 4.4.2-py35_0 149 | traitlets: 4.3.1-py35_0 150 | vs2015_runtime: 14.0.25123-0 151 | wcwidth: 0.1.7-py35_0 152 | widgetsnbextension: 1.2.3-py35_1 menpo 153 | win_unicode_console: 0.5-py35_0 154 | zlib: 1.2.8-vc14_3 [vc14] 155 | 156 | Proceed ([y]/n)? y 157 | 158 | entrypoints-0. 100% |###############################| Time: 0:00:00 1.04 MB/s 159 | pandocfilters- 100% |###############################| Time: 0:00:00 1.15 MB/s 160 | testpath-0.3-p 100% |###############################| Time: 0:00:00 1.72 MB/s 161 | html5lib-0.999 100% |###############################| Time: 0:00:00 1.90 MB/s 162 | scipy-0.18.1-n 100% |###############################| Time: 0:00:03 3.09 MB/s 163 | bleach-1.5.0-p 100% |###############################| Time: 0:00:00 1.86 MB/s 164 | matplotlib-2.0 100% |###############################| Time: 0:00:02 3.14 MB/s 165 | nbconvert-5.1. 100% |###############################| Time: 0:00:00 3.55 MB/s 166 | widgetsnbexten 100% |###############################| Time: 0:00:03 388.75 kB/s 167 | ipywidgets-5.1 100% |###############################| Time: 0:00:00 381.78 kB/s 168 | 169 | (pyOCV) C:\Users\franz\Desktop\OpenCV-intro> 170 | ``` 171 | --------------------------------------------------------------------------------