#tested  khwong 25 June 2011
#from http://stackoverflow.com/questions/2933284/opencv-python-houghcircles-error
# still need to make houghcircle work
import cv

cv.NamedWindow("Hough", 1)
capture = cv.CaptureFromCAM(0)

while True:
    img = cv.QueryFrame(capture)
    gray = cv.CreateImage(cv.GetSize(img), 8, 1)
    edges = cv.CreateImage(cv.GetSize(img), 8, 1)

    cv.CvtColor(img, gray, cv.CV_BGR2GRAY)
    cv.Canny(gray, edges, 50, 200, 3)

    #cv.ShowImage("Hough_lines", edges)
    
    cv.Smooth(gray, gray, cv.CV_GAUSSIAN, 9, 9)

    storage = cv.CreateMat(1, 2, cv.CV_32FC3)

    #This is the line that throws the error
    cv.HoughCircles(edges, storage, cv.CV_HOUGH_GRADIENT, 2, gray.height/4, 200, 100)

    cv.ShowImage("Hough", edges)
    if cv.WaitKey(10) == 27:
        cv.DestroyWindow("Hough")
        break
