Search in sources :

Example 1 with ConvertRotation3D_F64

use of georegression.geometry.ConvertRotation3D_F64 in project BoofCV by lessthanoptimal.

the class ExampleMultiViewSparseReconstruction method compute.

public void compute(String videoName, boolean sequential) {
    // Turn on threaded code for bundle adjustment
    DDoglegConcurrency.USE_CONCURRENT = true;
    // Create a directory to store the work space
    String path = UtilIO.pathExample("mvs/" + videoName);
    workDirectory = "mvs_work/" + FilenameUtils.getBaseName(videoName);
    // Attempt to reload intermediate results if previously computed
    if (!rebuild) {
        try {
            pairwise = MultiViewIO.load(new File(workDirectory, "pairwise.yaml").getPath(), (PairwiseImageGraph) null);
        } catch (UncheckedIOException ignore) {
        }
        try {
            working = MultiViewIO.load(new File(workDirectory, "working.yaml").getPath(), pairwise, null);
        } catch (UncheckedIOException ignore) {
        }
        try {
            scene = MultiViewIO.load(new File(workDirectory, "structure.yaml").getPath(), (SceneStructureMetric) null);
        } catch (UncheckedIOException ignore) {
        }
    }
    // Convert the video into an image sequence. Later on we will need to access the images in random order
    var imageDirectory = new File(workDirectory, "images");
    if (imageDirectory.exists()) {
        imageFiles = UtilIO.listSmart(String.format("glob:%s/images/*.png", workDirectory), true, (f) -> true);
    } else {
        checkTrue(imageDirectory.mkdirs(), "Failed to image directory");
        SimpleImageSequence<InterleavedU8> sequence = DefaultMediaManager.INSTANCE.openVideo(path, ImageType.IL_U8);
        System.out.println("----------------------------------------------------------------------------");
        System.out.println("### Decoding Video");
        BoofMiscOps.profile(() -> {
            int frame = 0;
            while (sequence.hasNext()) {
                InterleavedU8 image = sequence.next();
                File imageFile = new File(imageDirectory, String.format("frame%04d.png", frame++));
                imageFiles.add(imageFile.getPath());
                // This is commented out for what appears to be a JRE bug.
                // V  [libjvm.so+0xdc4059]  SWPointer::SWPointer(MemNode*, SuperWord*, Node_Stack*, bool)
                UtilImageIO.saveImage(image, imageFile.getPath());
            }
        }, "Video Decoding");
    }
    // Only determine the visual relationship between images if needed
    if (pairwise == null || working == null) {
        if (sequential) {
            similarImagesFromSequence();
        } else {
            similarImagesFromUnsorted();
        }
    }
    if (pairwise == null)
        computePairwiseGraph();
    if (working == null)
        metricFromPairwise();
    if (scene == null)
        bundleAdjustmentRefine();
    var rod = new Rodrigues_F64();
    System.out.println("----------------------------------------------------------------------------");
    for (PairwiseImageGraph.View pv : pairwise.nodes.toList()) {
        if (!working.containsView(pv.id))
            continue;
        SceneWorkingGraph.View wv = working.lookupView(pv.id);
        int order = working.listViews.indexOf(wv);
        ConvertRotation3D_F64.matrixToRodrigues(wv.world_to_view.R, rod);
        BundlePinholeSimplified intrinsics = working.getViewCamera(wv).intrinsic;
        System.out.printf("view[%2d]='%2s' f=%6.1f k1=%6.3f k2=%6.3f T={%5.1f,%5.1f,%5.1f} R=%4.2f\n", order, wv.pview.id, intrinsics.f, intrinsics.k1, intrinsics.k2, wv.world_to_view.T.x, wv.world_to_view.T.y, wv.world_to_view.T.z, rod.theta);
    }
    System.out.println("   Views used: " + scene.views.size + " / " + pairwise.nodes.size);
}
Also used : FactorySceneReconstruction(boofcv.factory.structure.FactorySceneReconstruction) PointTracker(boofcv.abst.tracker.PointTracker) ConfigGeneratePairwiseImageGraph(boofcv.factory.structure.ConfigGeneratePairwiseImageGraph) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) VisualizeData(boofcv.visualize.VisualizeData) FactoryPointTracker(boofcv.factory.tracker.FactoryPointTracker) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) UtilAngle(georegression.metric.UtilAngle) LookUpImageFilesByIndex(boofcv.io.image.LookUpImageFilesByIndex) DogArray(org.ddogleg.struct.DogArray) Point3D_F64(georegression.struct.point.Point3D_F64) ConfigSimilarImagesTrackThenMatch(boofcv.alg.similar.ConfigSimilarImagesTrackThenMatch) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) Rodrigues_F64(georegression.struct.so.Rodrigues_F64) List(java.util.List) LookUpColorRgbFormats(boofcv.core.image.LookUpColorRgbFormats) GrayU8(boofcv.struct.image.GrayU8) PointCloudIO(boofcv.io.points.PointCloudIO) BoofMiscOps.checkTrue(boofcv.misc.BoofMiscOps.checkTrue) FilenameUtils(org.apache.commons.io.FilenameUtils) DogArray_I32(org.ddogleg.struct.DogArray_I32) ConfigPointTracker(boofcv.factory.tracker.ConfigPointTracker) ColorizeMultiViewStereoResults(boofcv.alg.mvs.ColorizeMultiViewStereoResults) UtilImageIO(boofcv.io.image.UtilImageIO) PointTrack(boofcv.abst.tracker.PointTrack) Point3dRgbI_F64(boofcv.struct.Point3dRgbI_F64) ArrayList(java.util.ArrayList) ConvertRotation3D_F64(georegression.geometry.ConvertRotation3D_F64) SimpleImageSequence(boofcv.io.image.SimpleImageSequence) BoofMiscOps(boofcv.misc.BoofMiscOps) InterleavedU8(boofcv.struct.image.InterleavedU8) TwoAxisRgbPlane(boofcv.visualize.TwoAxisRgbPlane) BoofVerbose(boofcv.BoofVerbose) boofcv.alg.structure(boofcv.alg.structure) ShowImages(boofcv.gui.image.ShowImages) UtilIO(boofcv.io.UtilIO) ImageType(boofcv.struct.image.ImageType) MultiViewIO(boofcv.io.geo.MultiViewIO) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) java.awt(java.awt) BoofSwingUtil(boofcv.gui.BoofSwingUtil) PointCloudReader(boofcv.alg.cloud.PointCloudReader) DDoglegConcurrency(org.ddogleg.DDoglegConcurrency) PointCloudViewer(boofcv.visualize.PointCloudViewer) Point4D_F64(georegression.struct.point.Point4D_F64) ConfigSimilarImagesSceneRecognition(boofcv.alg.similar.ConfigSimilarImagesSceneRecognition) FactorySceneRecognition(boofcv.factory.scene.FactorySceneRecognition) javax.swing(javax.swing) InterleavedU8(boofcv.struct.image.InterleavedU8) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) UncheckedIOException(java.io.UncheckedIOException) ConfigGeneratePairwiseImageGraph(boofcv.factory.structure.ConfigGeneratePairwiseImageGraph) SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) Rodrigues_F64(georegression.struct.so.Rodrigues_F64) File(java.io.File)

Aggregations

BoofVerbose (boofcv.BoofVerbose)1 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)1 PointTrack (boofcv.abst.tracker.PointTrack)1 PointTracker (boofcv.abst.tracker.PointTracker)1 PointCloudReader (boofcv.alg.cloud.PointCloudReader)1 BundlePinholeSimplified (boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified)1 ColorizeMultiViewStereoResults (boofcv.alg.mvs.ColorizeMultiViewStereoResults)1 ConfigSimilarImagesSceneRecognition (boofcv.alg.similar.ConfigSimilarImagesSceneRecognition)1 ConfigSimilarImagesTrackThenMatch (boofcv.alg.similar.ConfigSimilarImagesTrackThenMatch)1 boofcv.alg.structure (boofcv.alg.structure)1 LookUpColorRgbFormats (boofcv.core.image.LookUpColorRgbFormats)1 FactorySceneRecognition (boofcv.factory.scene.FactorySceneRecognition)1 ConfigGeneratePairwiseImageGraph (boofcv.factory.structure.ConfigGeneratePairwiseImageGraph)1 FactorySceneReconstruction (boofcv.factory.structure.FactorySceneReconstruction)1 ConfigPointTracker (boofcv.factory.tracker.ConfigPointTracker)1 FactoryPointTracker (boofcv.factory.tracker.FactoryPointTracker)1 BoofSwingUtil (boofcv.gui.BoofSwingUtil)1 ShowImages (boofcv.gui.image.ShowImages)1 UtilIO (boofcv.io.UtilIO)1 MultiViewIO (boofcv.io.geo.MultiViewIO)1