Skip to content

Instantly share code, notes, and snippets.

@randName
Created June 6, 2014 15:06
Show Gist options
  • Save randName/b087fb6b6247135d2d2b to your computer and use it in GitHub Desktop.
Save randName/b087fb6b6247135d2d2b to your computer and use it in GitHub Desktop.
Fast Circle Detection using Gradient Pair Vectors
#!/usr/bin/env python2
import numpy as np
import cv2 as cv
def FCD( src, mask ):
A_THRESH = [ 2, 1 ]
sobel_x = cv.Sobel( src, cv.CV_32F, 1, 0, ksize = 5 )
sobel_y = cv.Sobel( src, cv.CV_32F, 0, 1, ksize = 5 )
magnitude, angle = cv.cartToPolar( sobel_x, sobel_y, angleInDegrees = True )
angle = np.around( angle, 0 )
# v = [[]]*360
# for x, y in np.transpose( np.nonzero( magnitude > mask ) ) :
# ag = angle.item( x, y )
# if ag == 360: ag = 0
# v[int(ag)].append( ( x, y ) )
for a in range(180) :
for b in range( a + 180 - A_THRESH[0], ( a + 180 + A_THRESH[0] ) % 360 ) :
#v[a], v[b]
# ??? where did the code go
# cv.imshow( "j", edges )
cam = cv.VideoCapture(0)
cv.namedWindow( "i" )
cv.namedWindow( "j" )
while True:
rval, src = cam.read()
src_hsv = cv.cvtColor( src, cv.COLOR_BGR2HSV )
blurred = cv.GaussianBlur( src_hsv[...,2], (7,7), 5 )
FCD( blurred, 1000 )
cv.imshow( "i", blurred )
if cv.waitKey(20) == 27 :
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment