title: Track circles in video OpenCV
body: <pre><code>import cv2
  import numpy as np
  
  cap = cv2.VideoCapture(0)
  
  while(1):
  
      # Take each frame
      _, frame = cap.read()
      frame = cv2.medianBlur(frame,5)
      cimg = cv2.cvtColor(frame,cv2.COLOR_GRAY2BGR)
  
      circles = cv2.HoughCircles(frame,cv2.HOUGH_GRADIENT,1,20,
                                  param1=50,param2=30,minRadius=0,maxRadius=0)
  
      circles = np.uint16(np.around(circles))
  
      for i in circles[0,:]:
          # draw the outer circle
          cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
          # draw the center of the circle
          cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
  
      cv2.imshow('frame',cimg)
  
      if cv2.waitKey(1) &amp; 0xFF == ord('q'):
          break
  
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>I am trying to find circles, but my code fails <code>OpenCV Error: Assertion failed (scn == 1 &amp;&amp; (dcn == 3 || dcn == 4))</code>. Any idea why? In addition, how to get coordinates of a circle?</p>