Ask Your Question
0

Camshift tracking

asked 2012-10-14 04:22:30 -0500

karry89 gravatar image

updated 2012-10-15 00:47:31 -0500

jayrambhia gravatar image
from SimpleCV import *

def foo(image):
    return image.meanColor()

def camshift():
    cam = Camera()
    img = cam.getImage()
    d = Display(img.size())
    bb1 = getBBFromUser(cam,d)
    fs1=[]
    while True:
        try:
            img1 = cam.getImage()
            fs1 = img1.track("camshift",fs1,img,bb1,num_frames=5)
            fs1.drawBB()
            fs1.drawPath()
            fs1.showCoordinates()
            fs1.showSizeRatio()
            fs1.showPixelVelocity()
            fs1.showPixelVelocityRT()
            img1.show()
        except KeyboardInterrupt:
            print "Total number of frames tracked",
            print fs1.trackLength()
            print fs1.processTrack(foo)
            break

def getBBFromUser(cam, d):
    p1 = None
    p2 = None
    img = cam.getImage()
    while d.isNotDone():
        try:
            img = cam.getImage()
            img.save(d)
            dwn = d.leftButtonDownPosition()
            up = d.leftButtonUpPosition()

            if dwn:
                p1 = dwn
            if up:
                p2 = up
                break

            time.sleep(0.05)
        except KeyboardInterrupt:
            break
    if not p1 or not p2:
        return None

    xmax = np.max((p1[0],p2[0]))
    xmin = np.min((p1[0],p2[0]))
    ymax = np.max((p1[1],p2[1]))
    ymin = np.min((p1[1],p2[1]))
    return (xmin,ymin,xmax-xmin,ymax-ymin)

camshift()

this code is opening the camera window but the tracking is nowhere done :(

edit retag flag offensive close merge delete

Comments

thnxxxxxxxxxxxxxxxxxxxx :D

karry89 gravatar imagekarry89 ( 2012-10-17 05:07:11 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-10-17 05:07:24 -0500

karry89 gravatar image

thnxxx jay

edit flag offensive delete link more

Comments

please accept the answer if you find it helpful.

jayrambhia gravatar imagejayrambhia ( 2012-10-18 15:10: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

Stats

Asked: 2012-10-14 04:22:30 -0500

Seen: 515 times

Last updated: Oct 17 '12