- Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathexample1.py
More file actions
Latest commit
69 lines (53 loc) · 1.93 KB
/
Copy pathexample1.py
File metadata and controls
69 lines (53 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#**********************************************************************
#Finds the 100 best features in an image, and tracks these
#features to the next image. Saves the feature
#locations (before and after tracking) to text files and to PPM files,
#and prints the features to the screen.
#**********************************************************************
#include "pnmio.h"
from __future__ importprint_function
fromkltimport*
fromPILimportImage
fromselectGoodFeaturesimport*
fromwriteFeaturesimport*
fromtrackFeaturesimport*
importpickle, time
defmain():
tc=KLT_TrackingContext()
nFeatures=50
tc.nSkippedPixels=0
tc.max_residue=10.0
KLTPrintTrackingContext(tc)
img1=Image.open("img0.pgm")
img2=Image.open("img1.pgm")
ncols, nrows=img1.size
fl=KLTSelectGoodFeatures(tc, img1, nFeatures)
print("\nIn first image:")
fori, featinenumerate(fl):
print("Feature #{0}: ({1},{2}) with value of {3}".format(i, feat.x, feat.y, feat.val))
KLTWriteFeatureListToPPM(fl, img1, "feat1.ppm")
#KLTWriteFeatureList(fl, "feat1.txt", "%3d")
#pickle.dump(tc, open("context.dat","w"))
#pickle.dump(fl, open("featurelist.dat","w"))
#img1 = Image.open("img0.pgm")
#img2 = Image.open("img1.pgm")
#tc = pickle.load(open("context.dat"))
#tc.writeInternalImages = True
#KLTPrintTrackingContext(tc)
#fl = pickle.load(open("featurelist.dat"))
#KLTTrackFeatures(tc, img1, img2, fl)
count=0
ti=time.clock()
foriinrange(100):
KLTTrackFeatures(tc, img1, img2, fl)
KLTTrackFeatures(tc, img2, img1, fl)
count+=2
print((time.clock() -ti) /count)
print("\nIn second image:")
fori, featinenumerate(fl):
print("Feature #{0}: ({1},{2}) with value of {3}".format(i, feat.x, feat.y, feat.val))
KLTWriteFeatureListToPPM(fl, img2, "feat2.ppm")
#KLTWriteFeatureList(fl, "feat2.fl", NULL) # binary file
#KLTWriteFeatureList(fl, "feat2.txt", "%5.1f") # text file
if__name__=="__main__":
main()