Skip to content

Instantly share code, notes, and snippets.

@quxiaofeng
Forked from randName/FCD.py
Created January 12, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quxiaofeng/3044e8e03a9f70a4029855e910589528 to your computer and use it in GitHub Desktop.
Save quxiaofeng/3044e8e03a9f70a4029855e910589528 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