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

boofcv.factory.background.FactoryBackgroundModel 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-2015, 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.background;

import boofcv.alg.background.BackgroundModelStationary;
import boofcv.alg.background.moving.*;
import boofcv.alg.background.stationary.*;
import boofcv.struct.distort.PointTransformModel_F32;
import boofcv.struct.image.ImageBase;
import boofcv.struct.image.ImageType;
import georegression.struct.InvertibleTransform;

/**
 * Factory for creating implementations of {@link BackgroundModelStationary} and {@link boofcv.alg.background.BackgroundModelMoving}
 *
 * @author Peter Abeles
 */
@SuppressWarnings("unchecked")
public class FactoryBackgroundModel {

	/**
	 * Creates an instance of {@link BackgroundMovingBasic}.
	 *
	 * @param config Configures the background model
	 * @param imageType Type of input image
	 * @return new instance of the background model
	 */
	public static 
	BackgroundStationaryBasic stationaryBasic( ConfigBackgroundBasic config , ImageType imageType ) {

		config.checkValidity();

		switch( imageType.getFamily() ) {
			case SINGLE_BAND:
				return new BackgroundStationaryBasic_SB(config.learnRate,config.threshold,imageType.getImageClass());

			case MULTI_SPECTRAL:
				return new BackgroundStationaryBasic_MS(config.learnRate,config.threshold,imageType);

			case INTERLEAVED:
				return new BackgroundStationaryBasic_IL(config.learnRate,config.threshold,imageType);
		}

		throw new IllegalArgumentException("Unknown image type");
	}

	/**
	 * Creates an instance of {@link BackgroundMovingBasic}.
	 *
	 * @param config Configures the background model
	 * @param imageType Type of input image
	 * @return new instance of the background model
	 */
	public static >
	BackgroundMovingBasic movingBasic( ConfigBackgroundBasic config ,
												 PointTransformModel_F32 transform, ImageType imageType ) {

		config.checkValidity();

		switch( imageType.getFamily() ) {
			case SINGLE_BAND:
				return new BackgroundMovingBasic_SB(config.learnRate,config.threshold,
						transform,config.interpolation,imageType.getImageClass());

			case MULTI_SPECTRAL:
				return new BackgroundMovingBasic_MS(config.learnRate,config.threshold,
						transform,config.interpolation,imageType);

			case INTERLEAVED:
				return new BackgroundMovingBasic_IL(config.learnRate,config.threshold,
						transform,config.interpolation,imageType);
		}

		throw new IllegalArgumentException("Unknown image type");
	}

	/**
	 * Creates an instance of {@link BackgroundStationaryGaussian}.
	 *
	 * @param config Configures the background model
	 * @param imageType Type of input image
	 * @return new instance of the background model
	 */
	public static 
	BackgroundStationaryGaussian stationaryGaussian( ConfigBackgroundGaussian config , ImageType imageType ) {

		config.checkValidity();

		BackgroundStationaryGaussian ret;

		switch( imageType.getFamily() ) {
			case SINGLE_BAND:
				ret = new BackgroundStationaryGaussian_SB(config.learnRate,config.threshold,imageType.getImageClass());
				break;

			case MULTI_SPECTRAL:
				ret =  new BackgroundStationaryGaussian_MS(config.learnRate,config.threshold,imageType);
				break;

			case INTERLEAVED:
				ret =  new BackgroundStationaryGaussian_IL(config.learnRate,config.threshold,imageType);
				break;

			default:
				throw new IllegalArgumentException("Unknown image type");
		}

		ret.setInitialVariance(config.initialVariance);
		ret.setMinimumDifference(config.minimumDifference);

		return ret;
	}

	/**
	 * Creates an instance of {@link BackgroundMovingGaussian}.
	 *
	 * @param config Configures the background model
	 * @param imageType Type of input image
	 * @return new instance of the background model
	 */
	public static >
	BackgroundMovingGaussian movingGaussian( ConfigBackgroundGaussian config ,
													   PointTransformModel_F32 transform,
													   ImageType imageType ) {

		config.checkValidity();

		BackgroundMovingGaussian ret;

		switch( imageType.getFamily() ) {
			case SINGLE_BAND:
				ret = new BackgroundMovingGaussian_SB(config.learnRate,config.threshold,
						transform,config.interpolation,imageType.getImageClass());
				break;

			case MULTI_SPECTRAL:
				ret =  new BackgroundMovingGaussian_MS(config.learnRate,config.threshold,
						transform,config.interpolation,imageType);
				break;

			case INTERLEAVED:
				ret =  new BackgroundMovingGaussian_IL(config.learnRate,config.threshold,
						transform,config.interpolation,imageType);
				break;

			default:
				throw new IllegalArgumentException("Unknown image type");
		}

		ret.setInitialVariance(config.initialVariance);
		ret.setMinimumDifference(config.minimumDifference);

		return ret;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy