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

boofcv.factory.feature.tracker.FactoryPointTrackerTwoPass Maven / Gradle / Ivy

Go to download

BoofCV is an open source Java library for real-time computer vision and robotics applications.

There is a newer version: 0.26
Show newest version
/*
 * 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.feature.tracker;

import boofcv.abst.feature.associate.AssociateDescription2D;
import boofcv.abst.feature.describe.DescribeRegionPoint;
import boofcv.abst.feature.detdesc.DetectDescribePoint;
import boofcv.abst.feature.detect.interest.ConfigGeneralDetector;
import boofcv.abst.feature.tracker.*;
import boofcv.abst.filter.derivative.ImageGradient;
import boofcv.alg.feature.detect.interest.EasyGeneralFeatureDetector;
import boofcv.alg.feature.detect.interest.GeneralFeatureDetector;
import boofcv.alg.interpolate.InterpolateRectangle;
import boofcv.alg.tracker.klt.PkltConfig;
import boofcv.factory.filter.derivative.FactoryDerivative;
import boofcv.factory.interpolate.FactoryInterpolation;
import boofcv.factory.transform.pyramid.FactoryPyramid;
import boofcv.struct.feature.TupleDesc;
import boofcv.struct.image.ImageGray;
import boofcv.struct.pyramid.PyramidDiscrete;

import static boofcv.factory.feature.tracker.FactoryPointTracker.createShiTomasi;

/**
 * @author Peter Abeles
 */
public class FactoryPointTrackerTwoPass {

	/**
	 * Pyramid KLT feature tracker.
	 *
	 * @param config Config for the tracker. Try PkltConfig.createDefault().
	 * @param configExtract Configuration for extracting features
	 * @return KLT based tracker.
	 */
	public static 
	PointTrackerTwoPass klt(PkltConfig config, ConfigGeneralDetector configExtract,
							   Class imageType, Class derivType) {

		GeneralFeatureDetector detector = createShiTomasi(configExtract, derivType);

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

		ImageGradient gradient = FactoryDerivative.sobel(imageType, derivType);

		PyramidDiscrete pyramid = FactoryPyramid.discreteGaussian(config.pyramidScaling,-1,2,true,imageType);

		return new PointTrackerTwoPassKltPyramid<>(config.config, config.templateRadius, pyramid, detector,
				gradient, interpInput, interpDeriv);
	}

	public static 
	PointTrackerTwoPass dda(GeneralFeatureDetector detector,
							   DescribeRegionPoint describe,
							   AssociateDescription2D associate1,
							   AssociateDescription2D associate2,
							   double scale,
							   Class imageType) {

		EasyGeneralFeatureDetector easy = new EasyGeneralFeatureDetector<>(detector, imageType, null);

		DdaManagerGeneralPoint manager = new DdaManagerGeneralPoint<>(easy, describe, scale);

		if( associate2 == null )
			associate2 = associate1;

		return new DetectDescribeAssociateTwoPass<>(manager, associate1, associate2, false);
	}

	public static 
	PointTrackerTwoPass dda(DetectDescribePoint detectDescribe,
							   AssociateDescription2D associate1 ,
							   AssociateDescription2D associate2 ,
							   boolean updateDescription ) {


		DdaManagerDetectDescribePoint manager = new DdaManagerDetectDescribePoint<>(detectDescribe);

		if( associate2 == null )
			associate2 = associate1;

		return new DetectDescribeAssociateTwoPass<>(manager, associate1, associate2, updateDescription);
	}
}