Search in sources :

Example 1 with ConfigPlanarTrackPnP

use of boofcv.factory.sfm.ConfigPlanarTrackPnP in project BoofCV by lessthanoptimal.

the class ExampleVisualOdometryMonocularPlane method main.

public static void main(String[] args) {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String directory = UtilIO.pathExample("vo/drc/");
    // load camera description and the video sequence
    MonoPlaneParameters calibration = CalibrationIO.load(media.openFile(new File(directory, "mono_plane.yaml").getPath()));
    SimpleImageSequence<GrayU8> video = media.openVideo(new File(directory, "left.mjpeg").getPath(), ImageType.single(GrayU8.class));
    var config = new ConfigPlanarTrackPnP();
    // specify how the image features are going to be tracked
    config.tracker.typeTracker = ConfigPointTracker.TrackerType.KLT;
    config.tracker.klt.pyramidLevels = ConfigDiscreteLevels.levels(4);
    config.tracker.klt.templateRadius = 3;
    config.tracker.detDesc.detectPoint.type = PointDetectorTypes.SHI_TOMASI;
    config.tracker.detDesc.detectPoint.general.maxFeatures = 600;
    config.tracker.detDesc.detectPoint.general.radius = 3;
    config.tracker.detDesc.detectPoint.general.threshold = 1;
    // Configure how visual odometry works
    config.thresholdAdd = 75;
    config.thresholdRetire = 2;
    config.ransac.iterations = 200;
    config.ransac.inlierThreshold = 1.5;
    // declares the algorithm
    MonocularPlaneVisualOdometry<GrayU8> visualOdometry = FactoryVisualOdometry.monoPlaneInfinity(config, GrayU8.class);
    // Pass in intrinsic/extrinsic calibration. This can be changed in the future.
    visualOdometry.setCalibration(calibration);
    // Process the video sequence and output the location plus number of inliers
    long startTime = System.nanoTime();
    while (video.hasNext()) {
        GrayU8 image = video.next();
        if (!visualOdometry.process(image)) {
            System.out.println("Fault!");
            visualOdometry.reset();
        }
        Se3_F64 leftToWorld = visualOdometry.getCameraToWorld();
        Vector3D_F64 T = leftToWorld.getT();
        System.out.printf("Location %8.2f %8.2f %8.2f, %s\n", T.x, T.y, T.z, trackStats(visualOdometry));
    }
    System.out.printf("FPS %4.2f\n", video.getFrameNumber() / ((System.nanoTime() - startTime) * 1e-9));
}
Also used : Vector3D_F64(georegression.struct.point.Vector3D_F64) ConfigPlanarTrackPnP(boofcv.factory.sfm.ConfigPlanarTrackPnP) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) GrayU8(boofcv.struct.image.GrayU8) File(java.io.File) MonoPlaneParameters(boofcv.struct.calib.MonoPlaneParameters) Se3_F64(georegression.struct.se.Se3_F64)

Example 2 with ConfigPlanarTrackPnP

use of boofcv.factory.sfm.ConfigPlanarTrackPnP in project BoofCV by lessthanoptimal.

the class VisualizeMonocularPlaneVisualOdometryApp method createVisualOdometry.

private MonocularPlaneVisualOdometry<I> createVisualOdometry(int whichAlg) {
    Class derivType = GImageDerivativeOps.getDerivativeType(imageClass);
    if (whichAlg == 0) {
        var config = new ConfigPlanarTrackPnP();
        config.tracker.typeTracker = ConfigPointTracker.TrackerType.KLT;
        config.tracker.klt.pyramidLevels = ConfigDiscreteLevels.levels(4);
        config.tracker.klt.templateRadius = 3;
        config.tracker.detDesc.detectPoint.type = PointDetectorTypes.SHI_TOMASI;
        config.tracker.detDesc.detectPoint.general.maxFeatures = 600;
        config.tracker.detDesc.detectPoint.general.radius = 3;
        config.tracker.detDesc.detectPoint.general.threshold = 1;
        config.thresholdAdd = 75;
        config.thresholdRetire = 2;
        config.ransac.iterations = 200;
        config.ransac.inlierThreshold = 1.5;
        return FactoryVisualOdometry.monoPlaneInfinity(config, imageClass);
    } else if (whichAlg == 1) {
        ConfigPKlt configKlt = new ConfigPKlt();
        configKlt.pyramidLevels = ConfigDiscreteLevels.levels(4);
        configKlt.templateRadius = 3;
        ConfigPointDetector configDetector = new ConfigPointDetector();
        configDetector.type = PointDetectorTypes.SHI_TOMASI;
        configDetector.general.maxFeatures = 600;
        configDetector.general.radius = 3;
        configDetector.general.threshold = 1;
        PointTracker<I> tracker = FactoryPointTracker.klt(configKlt, configDetector, imageClass, derivType);
        double cellSize = 0.06;
        double inlierGroundTol = 1.5;
        return FactoryVisualOdometry.monoPlaneOverhead(cellSize, 25, 0.7, inlierGroundTol, 300, 2, 100, 0.5, 0.6, tracker, imageType);
    } else {
        throw new RuntimeException("Unknown selection");
    }
}
Also used : ConfigPlanarTrackPnP(boofcv.factory.sfm.ConfigPlanarTrackPnP) ConfigPKlt(boofcv.alg.tracker.klt.ConfigPKlt) ConfigPointTracker(boofcv.factory.tracker.ConfigPointTracker) PointTracker(boofcv.abst.tracker.PointTracker) FactoryPointTracker(boofcv.factory.tracker.FactoryPointTracker) ConfigPointDetector(boofcv.abst.feature.detect.interest.ConfigPointDetector)

Aggregations

ConfigPlanarTrackPnP (boofcv.factory.sfm.ConfigPlanarTrackPnP)2 ConfigPointDetector (boofcv.abst.feature.detect.interest.ConfigPointDetector)1 PointTracker (boofcv.abst.tracker.PointTracker)1 ConfigPKlt (boofcv.alg.tracker.klt.ConfigPKlt)1 ConfigPointTracker (boofcv.factory.tracker.ConfigPointTracker)1 FactoryPointTracker (boofcv.factory.tracker.FactoryPointTracker)1 MediaManager (boofcv.io.MediaManager)1 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)1 MonoPlaneParameters (boofcv.struct.calib.MonoPlaneParameters)1 GrayU8 (boofcv.struct.image.GrayU8)1 Vector3D_F64 (georegression.struct.point.Vector3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 File (java.io.File)1