You are on page 1of 3

OPTATIVA DE PROFESIONALIZACIÓN

Integrantes: Bonilla Andrés

NRC: 9503

Carrera: Ingeniería Mecatrónica


DEBER 2 TERCER PARCIAL
Vamos a presentar 2 imágenes

1. una imagen negra que solo la pelota sea blanca

2. imagen final, La pelota de ping pong sea cambiada de color y genere una
realidad aumentada en el video original.

Código
# UNIVERSIDAD DE LAS FUERZAS ARMADAS ESPE-L
# OPTATIVA DE PROFESIONALIZACION
# 9503
# ANDRÉS BONILLA

import cv2
import numpy as np

# --------------------TRACEBARS
def nothing(x):
pass
cv2.namedWindow('VARIABLES MANIPULADAS',cv2.WINDOW_NORMAL)
# cv2.resizeWindow('VARIABLES MANIPULADAS', 750,850)
cv2.createTrackbar('val1', 'VARIABLES MANIPULADAS', 0, 255, nothing)
cv2.createTrackbar('val2', 'VARIABLES MANIPULADAS', 0, 255, nothing)

cap = cv2.VideoCapture('D:\\ANDRES\\Documents\\ESPE 9 Y
ULTIMO\\OPTATIVA\\II PARCIAL\\Programas\\Imagenes\\pingpong.mp4')

while(True):

aux, src = cap.read()


aux2, src2 = cap.read()
aux3, src3 = cap.read()
gris = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY) # Escala de Grises
val1 = int(cv2.getTrackbarPos('val1', 'VARIABLES MANIPULADAS'))
val2 = int(cv2.getTrackbarPos('val2', 'VARIABLES MANIPULADAS'))
canny = cv2.Canny(gris, 167, 162)

cdst = cv2.cvtColor(canny, cv2.COLOR_GRAY2BGR)


cdstP = np.copy(cdst)

linesP = cv2.HoughLinesP(canny, 1, np.pi / 180, 67, None, 0, 250)


if linesP is not None:
for i in range(0, len(linesP)):
l = linesP[i][0]
cv2.line(src, (l[0], l[1]), (l[2], l[3]), (0, 0, 0), 4,
cv2.LINE_AA)

frame1 = cv2.medianBlur(src,5)
# cv2.imshow('lineas', frame1)

hsv_frame = cv2.cvtColor(frame1, cv2.COLOR_BGR2HSV)


low_red = np.array([19, 0, 198])
high_red = np.array([100, 40, 255])
filtro = cv2.inRange(hsv_frame, low_red, high_red)
cv2.imshow('Fondo Negro Bola Blanca', filtro)
diff = cv2.absdiff(src2, src3)
gris = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY)
gris2 = cv2.medianBlur(gris, 5)
cdstP2 = np.copy(gris2)

rows = gris2.shape[0]
circles = cv2.HoughCircles(cdstP2, cv2.HOUGH_GRADIENT, 1, rows /
8, param1=100, param2=8,minRadius=3, maxRadius=3)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
center = (i[0], i[1])
# circle center
cv2.circle(src2, center, 1, (0, 100, 100), 5)
# circle outline
radius = i[2]
cv2.circle(src2, center, radius, (0, 0, 255), 5)

cv2.imshow('Realidad Aumentada', src2)

if cv2.waitKey(1) & 0xFF == ord('q'):


break

cap.release()
cv2.destroyAllWindows()

Resultados

Enlace del Video

https://drive.google.com/drive/folders/1v31EUHgUvwXrX1zCvXZ3ZsInK21ZHFpB?usp=sharing

You might also like