Ask Your Question

Revision history [back]

The program which i have written works fine if i keep the object almost still in front of the camera But if i try to displace it a little then the video window stops responding.

import cv2 import numpy as np import cv2.cv as cv

cap = cv2.VideoCapture(0)

while(True):

ret,frame =cap.read()
img = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

# img = cv2.imread('soda.png',0) img = cv2.medianBlur(img,5)

circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,250,param1=70,param2=30,minRadius=0,maxRadius=0)

circles = np.uint64(np.around(circles))
for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)

cv2.imshow('detected circles',img)
if cv2.waitKey(60) & 0xFF == ord('q'):
  break

cap.release()
cv2.destroyAllWindows()

click to hide/show revision 2
No.2 Revision

updated 2015-05-22 06:33:45 -0600

berak gravatar image

The program which i have written works fine if i keep the object almost still in front of the camera But if i try to displace it a little then the video window stops responding.

import cv2
import numpy as np
import cv2.cv as cv

cv cap = cv2.VideoCapture(0)

while(True):

cv2.VideoCapture(0)

while(True):

    ret,frame =cap.read()
 img = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

# img = cv2.imread('soda.png',0) img = cv2.medianBlur(img,5)

cv2.medianBlur(img,5)


    circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,250,param1=70,param2=30,minRadius=0,maxRadius=0)

 circles = np.uint64(np.around(circles))
 for i in circles[0,:]:
     # draw the outer circle
     cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),2)
     # draw the center of the circle
     cv2.circle(img,(i[0],i[1]),2,(0,0,255),3)

 cv2.imshow('detected circles',img)
 if cv2.waitKey(60) & 0xFF == ord('q'):
  break
    break       



cap.release()        
cv2.destroyAllWindows()

cap.release()
cv2.destroyAllWindows()