View Javadoc

1   /**
2    * This source code file is part of a direct port of Stan Birchfield's implementation
3    * of a Kanade-Lucas-Tomasi feature tracker. The original implementation can be found
4    * here: http://www.ces.clemson.edu/~stb/klt/
5    *
6    * As per the original code, the source code is in the public domain, available
7    * for both commercial and non-commercial use.
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.KLTTracker;
18  import org.openimaj.video.tracking.klt.TrackingContext;
19  
20  /**
21   * KLTTracker Example 2
22   */
23  public class Example2 {
24  	/**
25  	 * @param args
26  	 * @throws IOException
27  	 */
28  	public static void main(String [] args) throws IOException {
29  		int nFeatures = 100;
30  
31  		TrackingContext tc = new TrackingContext();
32  		FeatureList fl = new FeatureList(nFeatures);
33  		KLTTracker tracker = new KLTTracker(tc, fl);
34  
35  		FImage img1 = ImageUtilities.readF(Example1.class.getResourceAsStream("img0.pgm"));
36  		FImage img2 = ImageUtilities.readF(Example1.class.getResourceAsStream("img1.pgm"));
37  
38  		tracker.selectGoodFeatures(img1);
39  
40  		DisplayUtilities.display(fl.drawFeatures(img1));
41  		fl.writeFeatureList(null, "%3d");
42  
43  		tracker.trackFeatures(img1, img2);
44  		tracker.replaceLostFeatures(img2);
45  
46  		DisplayUtilities.display(fl.drawFeatures(img1));
47  		fl.writeFeatureList(null, "%3d");
48  	}
49  }