Search in sources :

Example 6 with SimpleImageSequence

use of boofcv.io.image.SimpleImageSequence in project BoofCV by lessthanoptimal.

the class ExampleWebcamJavaCV method main.

public static void main(String[] args) {
    WebcamOpenCV webcam = new WebcamOpenCV();
    SimpleImageSequence sequence = webcam.open("0", 1280, 960, ImageType.pl(3, GrayU8.class));
    BufferedImage output = new BufferedImage(sequence.getWidth(), sequence.getHeight(), BufferedImage.TYPE_INT_RGB);
    ImagePanel gui = new ImagePanel(output);
    ShowImages.showWindow(gui, "Webam using JavaCV", true);
    while (sequence.hasNext()) {
        ImageBase gray = sequence.next();
        ConvertBufferedImage.convertTo(gray, output, true);
        gui.repaint();
    }
}
Also used : SimpleImageSequence(boofcv.io.image.SimpleImageSequence) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImageBase(boofcv.struct.image.ImageBase) ImagePanel(boofcv.gui.image.ImagePanel)

Example 7 with SimpleImageSequence

use of boofcv.io.image.SimpleImageSequence 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

SimpleImageSequence (boofcv.io.image.SimpleImageSequence)7 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)4 GrayU8 (boofcv.struct.image.GrayU8)4 ImageBase (boofcv.struct.image.ImageBase)4 MediaManager (boofcv.io.MediaManager)3 ImageType (boofcv.struct.image.ImageType)3 PointTracker (boofcv.abst.tracker.PointTracker)2 ConfigBackgroundBasic (boofcv.factory.background.ConfigBackgroundBasic)2 FactoryPointTracker (boofcv.factory.tracker.FactoryPointTracker)2 ImageGridPanel (boofcv.gui.image.ImageGridPanel)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 BoofVerbose (boofcv.BoofVerbose)1 ConfigPointDetector (boofcv.abst.feature.detect.interest.ConfigPointDetector)1 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)1 PointTrack (boofcv.abst.tracker.PointTrack)1 TrackerObjectQuad (boofcv.abst.tracker.TrackerObjectQuad)1 BackgroundModelMoving (boofcv.alg.background.BackgroundModelMoving)1 BackgroundModelStationary (boofcv.alg.background.BackgroundModelStationary)1 PointCloudReader (boofcv.alg.cloud.PointCloudReader)1