Ask Your Question

CAMShift - automated blob 'grabbing'

asked 2012-12-01 13:58:41 -0500

dwhyte gravatar image

updated 2012-12-01 14:29:45 -0500


I've been playing with the CAMshift example but I am struggling to get it to track a ball.

I grab all circular blobs, I check the Radius is within sane size and I return the bounding box (minX, minY..).

I check the image to see that it has grabbed the blob, it has but I can't get it to 'track' this ball. If i detect every second, I can detect/track but I can't get .track to work :-(

from SimpleCV import *
import time

def cam():
    cam = Camera()
    bb1 = None
    while bb1 is None:
        img = cam.getImage()
        bb1 = getBB(img)

    while True:
            img1 = cam.getImage()
            img1 = img1.colorDistance(SimpleCV.Color.WHITE).dilate(3)
            fs1 = img1.track("camshift",fs1,img,bb1)
            print fs1[-1].getBB()
        except KeyboardInterrupt:

def getBB(img):
    found = "false"
    nimg = img.colorDistance(SimpleCV.Color.WHITE).dilate(3)
    blobs = nimg.findBlobs()
    circles = blobs.filter([b.isCircle(1) for b in blobs])
    firstblob = None
    for b in circles:
        #print "got a blob"
        if int(b.radius()) > 15 :
            found = "true"
        if found == "true" :
            firstblob = b
            xmin = firstblob.minX()
            ymin = firstblob.minY()
            xmax = firstblob.maxX()
            ymax = firstblob.maxY()
            #nimg.drawCircle((b.x, b.y), b.radius(),SimpleCV.Color.BLUE,4)

            return (xmin,ymin,xmax-xmin,ymax-ymin)
        else: return None


Please advise, if I can't automate this process... I can only select by index of got blobs and this makes it very difficult to do anything worthwhile. Essentially... I am trying to track a tennis ball in slow motion, I'm struggling to understand why this is failing - I get the red boundingBox to pop up on one frame, no more.

I would understand if the same process used in getBB DID NOT detect the blob, but this doesn't make too much sense to me.

Please advise!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2012-12-02 06:00:25 -0500

dwhyte gravatar image


I've not seen your code to track your two balls, I have managed to do this in OpenCV (with Python) myself.

If both images are dilated, they have the same featureset/data to work with (albeit less to play with?) so, a histogram will still contain data.

I have tried grabbing the bounding box from the dilated image and then using the colour image to track, this is still not working.

I'll keep playing... :)

edit flag offensive delete link more


Could you give a link/gist of your code?

jayrambhia gravatar imagejayrambhia ( 2012-12-02 11:38:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-12-01 13:58:41 -0500

Seen: 1,712 times

Last updated: Dec 02 '12