INSTALANDO OPENCV Y NUMPY ACTUALIZADOS
Para seguir el tutorial por favor visitar YouTube, al siguiente link:
El documento descargable se encuentra en este enlace:
PASOS DE INSTALACIÓN
1: Debemos de instalar Python la versión que desee en mi caso Python 3.6.7.
Para instalar correctamente siga los siguientes instrucciones:
ver video en youtube...
2: Ejecutamos instalador pip dentro de Python: como en la imagen.
pip install opencv-contrib-python
3: Comprobamos en CMD nuestro OpenCV y Numpy.
C:\Users\esteb>python
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.2.0'
>>> import numpy
>>> numpy.__version__
'1.18.4'
>>>
CÓDIGO FUENTE EJEMPLAR PARA PROBAR LA INSTALACIÓN EN WINDOWS
Para realizar si la instalación esta, todo bien probaremos nuestro ejemplo de detección de formas geométricas, de la siguiente imagen:
CÓDIGO
#ESTEBAN QUISPE CHURATA
#PROBANDO INSTALACION DE OPENCV Y NUMPY
import cv2
image = cv2.imread('imagen_con_formas.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
canny = cv2.Canny(gray, 10, 150)
canny = cv2.dilate(canny, None, iterations=1)
canny = cv2.erode(canny, None, iterations=1)
cnts,_ = cv2.findContours(canny, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# OpenCV 4
for c in cnts:
epsilon = 0.01*cv2.arcLength(c,True)
approx = cv2.approxPolyDP(c,epsilon,True)
x,y,w,h = cv2.boundingRect(approx)
if len(approx)==3:
cv2.putText(image,'TRIANGULO', (x,y-5),1,1.5,(0,255,0),2)
if len(approx)==4:
aspect_ratio = float(w)/h
print('RELACION DE ASPECTO= ', aspect_ratio)
if aspect_ratio == 1:
cv2.putText(image,'CUADRADO', (x,y-5),1,1.5,(0,255,0),2)
else:
cv2.putText(image,'RECTANGULO', (x,y-5),1,1.5,(0,255,0),2)
if len(approx)==5:
cv2.putText(image,'PENTAGONO', (x,y-5),1,1.5,(0,255,0),2)
if len(approx)==6:
cv2.putText(image,'HEXAGONO', (x,y-5),1,1.5,(0,255,0),2)
if len(approx)>10:
cv2.putText(image,'CIRCULO', (x,y-5),1,1.5,(0,255,0),2)
cv2.drawContours(image, [approx], 0, (0,255,0),2)
cv2.imshow('image',image)
cv2.waitKey(0)
RESULTADOS
0 comentarios :
Publicar un comentario