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

boofcv.abst.sfm.d3.WrapVisOdomQuadPnP 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: 1.1.5
Show newest version
/*
 * Copyright (c) 2011-2018, 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.abst.sfm.d3;

import boofcv.abst.sfm.AccessPointTracks3D;
import boofcv.alg.feature.associate.AssociateStereo2D;
import boofcv.alg.geo.DistanceFromModelMultiView;
import boofcv.alg.geo.pose.PnPStereoDistanceReprojectionSq;
import boofcv.alg.geo.pose.RefinePnPStereo;
import boofcv.alg.sfm.d3.VisOdomQuadPnP;
import boofcv.struct.calib.StereoParameters;
import boofcv.struct.feature.TupleDesc;
import boofcv.struct.geo.Point2D3D;
import boofcv.struct.image.ImageGray;
import boofcv.struct.image.ImageType;
import boofcv.struct.sfm.Stereo2D3D;
import georegression.struct.point.Point2D_F64;
import georegression.struct.point.Point3D_F64;
import georegression.struct.se.Se3_F64;
import org.ddogleg.fitting.modelset.ModelMatcher;
import org.ddogleg.struct.FastQueue;

import java.util.ArrayList;
import java.util.List;

/**
 * Wrapper around {@link VisOdomQuadPnP} for {@link StereoVisualOdometry}.
 *
 * @author Peter Abeles
 */
public class WrapVisOdomQuadPnP,TD extends TupleDesc>
		implements StereoVisualOdometry, AccessPointTracks3D
{
	VisOdomQuadPnP alg;
	RefinePnPStereo refine;
	AssociateStereo2D associateStereo;
	PnPStereoDistanceReprojectionSq distance;
	DistanceFromModelMultiView distanceMono;
	Class imageType;

	public WrapVisOdomQuadPnP(VisOdomQuadPnP alg,
							  RefinePnPStereo refine,
							  AssociateStereo2D associateStereo,
							  PnPStereoDistanceReprojectionSq distance,
							  DistanceFromModelMultiView distanceMono,
							  Class imageType)
	{
		this.alg = alg;
		this.refine = refine;
		this.associateStereo = associateStereo;
		this.distance = distance;
		this.distanceMono = distanceMono;
		this.imageType = imageType;
	}

	@Override
	public Point3D_F64 getTrackLocation(int index) {
		FastQueue features =  alg.getQuadViews();

		return features.get(index).X;
	}

	@Override
	public long getTrackId(int index) {
		return 0;
	}

	@Override
	public List getAllTracks() {
		FastQueue features =  alg.getQuadViews();

		List ret = new ArrayList<>();
		for( VisOdomQuadPnP.QuadView v : features.toList() )
			ret.add(v.v2); // new left camera

		return ret;
	}

	@Override
	public boolean isInlier(int index) {
		ModelMatcher matcher = alg.getMatcher();
		int N = matcher.getMatchSet().size();
		for( int i = 0; i < N; i++ ) {
			if( matcher.getInputIndex(i) == index )
				return true;
		}
		return false;
	}

	@Override
	public boolean isNew(int index) {
		return false;// its always new
	}

	@Override
	public void setCalibration(StereoParameters parameters) {
		Se3_F64 leftToRight = parameters.getRightToLeft().invert(null);

		alg.setCalibration(parameters);
		associateStereo.setCalibration(parameters);
		distance.setLeftToRight(leftToRight);
		distance.setIntrinsic(0,parameters.left);
		distance.setIntrinsic(1,parameters.right);

		distanceMono.setIntrinsic(0,parameters.left);

		if( refine != null )
			refine.setLeftToRight(leftToRight);
	}

	@Override
	public void reset() {
		alg.reset();
	}

	@Override
	public Se3_F64 getCameraToWorld() {
		return alg.getLeftToWorld();
	}

	@Override
	public boolean process(T leftImage, T rightImage) {
		return alg.process(leftImage,rightImage);
	}

	@Override
	public boolean isFault() {
		return false;
	}

	@Override
	public ImageType getImageType() {
		return ImageType.single(imageType);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy