def track_video(frames): """Create a generator around the Lucas-Kanade optical flow class.""" first_frame = next(frames) lkt = lktrack.LKTracker(first_frame) lkt.detect_points() yield lkt.draw() for im in frames: lkt.step(im) lkt.track_points() yield lkt.draw()
import glob import numpy as np img_array = [] direc = './data/' for i in range(108): #fileName = direc + 'image00' + str(i+1) +'.jpg' fileName = direc + 'img' + str(i + 1) + '.jpg' img_array.append(fileName) #print img_array[0] print "length ", len(img_array) imgA = img_array[40:80] print imgA lkt = lktrack.LKTracker(imgA) lkt.detect_points() image = cv2.imread(imgA[0]) #lkt.image = image #lkt.gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) #lkt.prev_gray = lkt.gray #for point in initial_points: #print point # cv2.circle(image,(int(point[0]),int(point[1])),3,(0,255,0),-1) cv2.imshow('LKtrack', image) lkt.draw() #cv2.waitKey()
import lktrack from pylab import * imnames = ['../data/viff/viff.000.ppm', '../data/viff/viff.001.ppm', '../data/viff/viff.002.ppm', '../data/viff/viff.003.ppm', '../data/viff/viff.004.ppm'] # track using the LKTracker generator lkt = lktrack.LKTracker(imnames) for im,ft in lkt.track(): print 'tracking %d features' % len(ft) # plot the tracks figure() imshow(im) for p in ft: plot(p[0],p[1],'bo') for t in lkt.tracks: plot([p[0] for p in t],[p[1] for p in t]) axis('off') show()