001/** 002 * This source code file is part of a direct port of Stan Birchfield's implementation 003 * of a Kanade-Lucas-Tomasi feature tracker. The original implementation can be found 004 * here: http://www.ces.clemson.edu/~stb/klt/ 005 * 006 * As per the original code, the source code is in the public domain, available 007 * for both commercial and non-commercial use. 008 */ 009package org.openimaj.video.tracking.klt.examples; 010 011import java.io.IOException; 012 013import org.openimaj.image.DisplayUtilities; 014import org.openimaj.image.FImage; 015import org.openimaj.image.ImageUtilities; 016import org.openimaj.video.tracking.klt.FeatureList; 017import org.openimaj.video.tracking.klt.KLTTracker; 018import org.openimaj.video.tracking.klt.TrackingContext; 019 020/** 021 * KLTTracker Example 2 022 */ 023public class Example2 { 024 /** 025 * @param args 026 * @throws IOException 027 */ 028 public static void main(String [] args) throws IOException { 029 int nFeatures = 100; 030 031 TrackingContext tc = new TrackingContext(); 032 FeatureList fl = new FeatureList(nFeatures); 033 KLTTracker tracker = new KLTTracker(tc, fl); 034 035 FImage img1 = ImageUtilities.readF(Example1.class.getResourceAsStream("img0.pgm")); 036 FImage img2 = ImageUtilities.readF(Example1.class.getResourceAsStream("img1.pgm")); 037 038 tracker.selectGoodFeatures(img1); 039 040 DisplayUtilities.display(fl.drawFeatures(img1)); 041 fl.writeFeatureList(null, "%3d"); 042 043 tracker.trackFeatures(img1, img2); 044 tracker.replaceLostFeatures(img2); 045 046 DisplayUtilities.display(fl.drawFeatures(img1)); 047 fl.writeFeatureList(null, "%3d"); 048 } 049}