All Downloads are FREE. Search and download functionalities are using the official Maven repository.

boofcv.factory.tracker.FactoryTrackerAlg Maven / Gradle / Ivy

/*
 * Copyright (c) 2011-2016, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package boofcv.factory.tracker;

import boofcv.abst.feature.associate.AssociateDescription;
import boofcv.abst.feature.detdesc.DetectDescribePoint;
import boofcv.alg.filter.derivative.GImageDerivativeOps;
import boofcv.alg.interpolate.InterpolateRectangle;
import boofcv.alg.tracker.combined.CombinedTrackerScalePoint;
import boofcv.alg.tracker.combined.PyramidKltForCombined;
import boofcv.alg.tracker.klt.KltConfig;
import boofcv.alg.tracker.klt.KltTracker;
import boofcv.alg.tracker.klt.PkltConfig;
import boofcv.alg.tracker.klt.PyramidKltTracker;
import boofcv.factory.interpolate.FactoryInterpolation;
import boofcv.struct.feature.TupleDesc;
import boofcv.struct.image.ImageGray;

/**
 * Factory for creating feature trackers algorithms.
 *
 * @author Peter Abeles
 */
public class FactoryTrackerAlg {

	/**
	 * Creates a {@link KltTracker}.
	 *
	 * NOTE: The pyramid's structure is determined by the input pyramid that is processed.
	 *
	 * @param config KLT configuration
	 * @param imageType Type of input image
	 * @param derivType Type of image derivative
	 * @param  Input image type.
	 * @param  Derivative image type.
	 * @return Tracker
	 */
	public static 
	KltTracker klt( KltConfig config, Class imageType , Class derivType )
	{
		if( config == null )
			config = new KltConfig();
		if( derivType == null )
			derivType = GImageDerivativeOps.getDerivativeType(imageType);

		InterpolateRectangle interpInput = FactoryInterpolation.bilinearRectangle(imageType);
		InterpolateRectangle interpDeriv = FactoryInterpolation.bilinearRectangle(derivType);

		return new KltTracker<>(interpInput, interpDeriv, config);
	}

	/**
	 * Creates a {@link PyramidKltTracker}.
	 *
	 * NOTE: The pyramid's structure is determined by the input pyramid that is processed.
	 *
	 * @param config KLT configuration
	 * @param imageType Type of input image
	 * @param derivType Type of image derivative
	 * @param  Input image type.
	 * @param  Derivative image type.
	 * @return Tracker
	 */
	public static 
	PyramidKltTracker kltPyramid( KltConfig config,
										Class imageType ,
										Class derivType )
	{
		if( config == null )
			config = new KltConfig();
		if( derivType == null )
			derivType = GImageDerivativeOps.getDerivativeType(imageType);

		InterpolateRectangle interpInput = FactoryInterpolation.bilinearRectangle(imageType);
		InterpolateRectangle interpDeriv = FactoryInterpolation.bilinearRectangle(derivType);

		KltTracker klt = new KltTracker<>(interpInput, interpDeriv, config);
		return new PyramidKltTracker<>(klt);
	}

	/**
	 * Creates a tracker that is a hybrid between KLT and Detect-Describe-Associate (DDA) trackers.
	 *
	 * @see boofcv.alg.tracker.combined.CombinedTrackerScalePoint
	 *
	 * @param detector Feature detector and describer.
	 * @param associate Association algorithm.
	 * @param kltConfig Configuration for KLT
	 * @param imageType Input image type.    @return Feature tracker
	 */
	public static 
	CombinedTrackerScalePoint combined(DetectDescribePoint detector,
												 AssociateDescription associate,
												 PkltConfig kltConfig ,
												 Class imageType,
												 Class derivType)
	{
		if( kltConfig == null)
			kltConfig = new PkltConfig();
		if( derivType == null )
			derivType = GImageDerivativeOps.getDerivativeType(imageType);

		PyramidKltForCombined klt = new PyramidKltForCombined<>(kltConfig.config,
				kltConfig.templateRadius, kltConfig.pyramidScaling, imageType, derivType);

		return new CombinedTrackerScalePoint<>(klt, detector, associate);
	}
}