title: Python Opencv Detecting Circles from the Binary Image by Using Hough Circle Transform
body: <p>I am trying trying to split video which is threshold applied into frames then trying to find the circles in the image. But I searched that converting binary image to grayscale is not possible. I searched about Hough circle and the method only can take grayscale images. Hough Lines can work on binary images but hough circles could not. Is there any advice to use thresholded images in hough circle method? Please help me. </p>
  
  <p>ps: I am adding the code and image that purpose is to find the circles in the thresholded image.  </p>
  
  <pre><code>while videoCapture.isOpened(): #Begins to detect the captures in video by frames
  
      ret, image = videoCapture.read()
      print("image capture opened")
  
      if ret == True:
  
          #rgb = cv2.cvtColor(image, cv2.COLOR_HLS2RGB)
          gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
          bgr = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR) #converting video color to gray
  
          print("gray scaled image\n")
          frameCounter = frameCounter + 1
          circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 20, param1=71, param2=70, minRadius=0, maxRadius=0)
          if circles is not None:
  
              print("Hough Circle on each frame")
              circles = np.uint16(np.around(circles))
              for i in circles[0, :]:
                  cv2.circle(bgr, (i[0],i[1]), i[2], (0, 255, 0), 2) #Outer circle in the image
                  cv2.circle(bgr, (i[0],i[1]), 2, (0, 0, 255), 3) #inner circle center
                  print("inner outer circle draw")
  
              cv2.imwrite(outputDir + "/%d.jpg" % (frameCounter), bgr) #Saving frame to the output directory
          else :
              print('Circle could not find')
              cv2.imwrite(outputDir + "/%d.jpg" % (frameCounter), bgr)  # Saving frame to the output directory
  
          print("image saved to directory")
  
          videoOutput.write(bgr)
  
          if(frameCounter &gt; (frameLength-1)):
              endTime = time.time()
              videoCapture.release()
              videoOutput.release()
              print("Converting video took %d seconds." % (endTime-startTime))
              break
      else:
         break
  </code></pre>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/b9Lnq.jpg" alt="**Binary Image (Threshold applied.)**"></p>