Skip to content

Instantly share code, notes, and snippets.

@srepho
Forked from xamox/balltrack.py
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save srepho/aa162f5feedb941ece5c to your computer and use it in GitHub Desktop.

Select an option

Save srepho/aa162f5feedb941ece5c to your computer and use it in GitHub Desktop.

Revisions

  1. Anthony Oliver created this gist Apr 21, 2012.
    36 changes: 36 additions & 0 deletions balltrack.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    '''
    This is how to track a white ball example using SimpleCV
    The parameters may need to be adjusted to match the RGB color
    of your object.
    The demo video can be found at:
    http://www.youtube.com/watch?v=jihxqg3kr-g
    '''
    print __doc__

    import SimpleCV

    display = SimpleCV.Display()
    cam = SimpleCV.Camera()
    normaldisplay = True

    while display.isNotDone():

    if display.mouseRight:
    normaldisplay = not(normaldisplay)
    print "Display Mode:", "Normal" if normaldisplay else "Segmented"

    img = cam.getImage().flipHorizontal()
    dist = img.colorDistance(SimpleCV.Color.BLACK).dilate(2)
    segmented = dist.stretch(200,255)
    blobs = segmented.findBlobs()
    if blobs:
    circles = blobs.filter([b.isCircle(0.2) for b in blobs])
    if circles:
    img.drawCircle((circles[-1].x, circles[-1].y), circles[-1].radius(),SimpleCV.Color.BLUE,3)

    if normaldisplay:
    img.show()
    else:
    segmented.show()