1 | initial version |
this is my new code
import cv2
import numpy as np
cv2.namedWindow("preview") captura = cv2.VideoCapture(0)
if captura.isOpened(): # try to get the first frame rval, frame = captura.read() else: rval = False
while rval:
#Capturamos una imagen y la convertimos de RGB -> HSV
_ ,frame = captura.read()
blur = cv2.GaussianBlur(frame, (5,5), 0)
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
#Establecemos el rango de colores que vamos a detectar
#En este caso de verde oscuro a verde-azulado claro
verde_bajos = np.array([49,50,50], dtype=np.uint8)
verde_altos = np.array([80, 255, 255], dtype=np.uint8)
#Encontrar el area de los objetos que detecta la camara
#moments = cv2.moments(mask)
#area = moments['m00']
res = cv2.bitwise_or(frame,frame, mask=mask)
image = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(image,cv2.HOUGH_GRADIENT,1,20,param1=100,param2=30,minRadius=50,maxRadius=100)
if circles is None:
#cv2.imshow("preview", frame)
continue
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
print i
cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),1) # draw the outer circle
cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3) # draw the center of the circle
#print area
#Mostramos la imagen original con la marca del centro y
#la mascara
cv2.imshow('mask',mask)
cv2.imshow('circles', frame)
tecla = cv2.waitKey(5) & 0xFF
if tecla == 27:
break
cv2.destroyAllWindows()
now my code run, but only detect circles if the background is green, its not util, can anybody help me?
2 | No.2 Revision |
this is my new code
import cv2
import numpy as np
cv2.namedWindow("preview") captura = cv2.VideoCapture(0)
if captura.isOpened(): # try to get the first frame rval, frame = captura.read() else: rval = False
while rval:
#Capturamos una imagen y la convertimos de RGB -> HSV
_ ,frame = captura.read()
blur = cv2.GaussianBlur(frame, (5,5), 0)
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
#Establecemos el rango de colores que vamos a detectar
#En este caso de verde oscuro a verde-azulado claro
verde_bajos = np.array([49,50,50], dtype=np.uint8)
verde_altos = np.array([80, 255, 255], dtype=np.uint8)
#Encontrar el area de los objetos que detecta la camara
#moments = cv2.moments(mask)
#area = moments['m00']
res = cv2.bitwise_or(frame,frame, mask=mask)
image = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(image,cv2.HOUGH_GRADIENT,1,20,param1=100,param2=30,minRadius=50,maxRadius=100)
if circles is None:
#cv2.imshow("preview", frame)
continue
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
print i
cv2.circle(frame,(i[0],i[1]),i[2],(0,255,0),1) # draw the outer circle
cv2.circle(frame,(i[0],i[1]),2,(0,0,255),3) # draw the center of the circle
#print area
#Mostramos la imagen original con la marca del centro y
#la mascara
cv2.imshow('mask',mask)
cv2.imshow('circles', frame)
tecla = cv2.waitKey(5) & 0xFF
if tecla == 27:
break
cv2.destroyAllWindows()
now my code run, but only detect circles if the background is green, only detect circles inside a background green, its not util, can anybody help me?