1
2
3
4
5
6
7
8
9 package org.openimaj.video.tracking.klt.examples;
10
11 import java.io.IOException;
12
13 import org.openimaj.image.DisplayUtilities;
14 import org.openimaj.image.FImage;
15 import org.openimaj.image.ImageUtilities;
16 import org.openimaj.video.tracking.klt.FeatureList;
17 import org.openimaj.video.tracking.klt.FeatureTable;
18 import org.openimaj.video.tracking.klt.KLTTracker;
19 import org.openimaj.video.tracking.klt.TrackingContext;
20
21
22
23
24 public class Example3 {
25
26
27
28
29 public static void main(String [] args) throws IOException {
30 int nFeatures = 150, nFrames = 10;
31 boolean replace = false;
32 int i;
33
34 TrackingContext tc = new TrackingContext();
35 FeatureList fl = new FeatureList(nFeatures);
36 FeatureTable ft = new FeatureTable(nFeatures);
37 KLTTracker tracker = new KLTTracker(tc, fl);
38
39 tc.setSequentialMode(true);
40 tc.setWriteInternalImages(false);
41 tc.setAffineConsistencyCheck(-1);
42
43 FImage img1 = ImageUtilities.readF(Example1.class.getResourceAsStream("img0.pgm"));
44
45 tracker.selectGoodFeatures(img1);
46 ft.storeFeatureList(fl, 0);
47
48 DisplayUtilities.display(fl.drawFeatures(img1));
49
50 for (i = 1 ; i < nFrames ; i++) {
51 String fnamein = String.format("img%d.pgm", i);
52 FImage img2 = ImageUtilities.readF(Example1.class.getResourceAsStream(fnamein));
53 tracker.trackFeatures(img1, img2);
54
55 if (replace)
56 tracker.replaceLostFeatures(img2);
57
58 ft.storeFeatureList(fl, i);
59 DisplayUtilities.display(fl.drawFeatures(img2));
60 }
61 ft.writeFeatureTable(null, "%5.1f");
62 }
63 }