Search in sources :

Example 6 with MediaManager

use of boofcv.io.MediaManager in project BoofCV by lessthanoptimal.

the class FiducialDetection method process.

private void process() {
    if (detector == null) {
        System.err.println("Need to specify which fiducial you wish to detect");
        System.exit(1);
    }
    if (outputPath != null) {
        try {
            outputFile = new PrintStream(outputPath);
            outputFile.println("# Results from fiducial detection ");
            outputFile.println("# These comments should include the data source and the algorithm used, but I'm busy.");
            outputFile.println("# ");
            outputFile.println("# <frame #> <number of fiducials> <fiducial id> <X> <Y> <Z> <Q1> <Q2> <Q3> <Q4> ...");
            outputFile.println("# ");
            outputFile.println("# The special Euclidean transform saved each fiducial is from fiducial to camera");
            outputFile.println("# (X,Y,Z) is the translation and (Q1,Q2,Q3,Q4) specifies a quaternion");
            outputFile.println("# ");
        } catch (FileNotFoundException e) {
            System.err.println("Failed to open output file.");
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }
    MediaManager media = DefaultMediaManager.INSTANCE;
    CameraPinholeRadial intrinsic = intrinsicPath == null ? null : (CameraPinholeRadial) CalibrationIO.load(intrinsicPath);
    SimpleImageSequence<GrayU8> sequence = null;
    long pause = 0;
    BufferedImage buffered = null;
    if (inputType == InputType.VIDEO || inputType == InputType.WEBCAM) {
        if (inputType == InputType.WEBCAM) {
            String device = getCameraDeviceString();
            sequence = media.openCamera(device, desiredWidth, desiredHeight, ImageType.single(GrayU8.class));
        } else {
            // just assume 30ms is appropriate.  Should let the use specify this number
            pause = 30;
            sequence = media.openVideo(filePath, ImageType.single(GrayU8.class));
            sequence.setLoop(true);
        }
        intrinsic = handleIntrinsic(intrinsic, sequence.getNextWidth(), sequence.getNextHeight());
    } else {
        buffered = UtilImageIO.loadImage(filePath);
        if (buffered == null) {
            System.err.println("Can't find image or it can't be read.  " + filePath);
            System.exit(1);
        }
        intrinsic = handleIntrinsic(intrinsic, buffered.getWidth(), buffered.getHeight());
    }
    ImagePanel gui = new ImagePanel();
    gui.setPreferredSize(new Dimension(intrinsic.width, intrinsic.height));
    ShowImages.showWindow(gui, "Fiducial Detector", true);
    detector.setLensDistortion(new LensDistortionRadialTangential(intrinsic), intrinsic.width, intrinsic.height);
    if (sequence != null) {
        processStream(intrinsic, sequence, gui, pause);
    } else {
        processImage(intrinsic, buffered, gui);
    }
}
Also used : PrintStream(java.io.PrintStream) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) FileNotFoundException(java.io.FileNotFoundException) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 7 with MediaManager

use of boofcv.io.MediaManager in project BoofCV by lessthanoptimal.

the class ExampleVisualOdometryDepth method main.

public static void main(String[] args) throws IOException {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String directory = UtilIO.pathExample("kinect/straight");
    // load camera description and the video sequence
    VisualDepthParameters param = CalibrationIO.load(media.openFile(directory + "visualdepth.yaml"));
    // specify how the image features are going to be tracked
    PkltConfig configKlt = new PkltConfig();
    configKlt.pyramidScaling = new int[] { 1, 2, 4, 8 };
    configKlt.templateRadius = 3;
    PointTrackerTwoPass<GrayU8> tracker = FactoryPointTrackerTwoPass.klt(configKlt, new ConfigGeneralDetector(600, 3, 1), GrayU8.class, GrayS16.class);
    DepthSparse3D<GrayU16> sparseDepth = new DepthSparse3D.I<>(1e-3);
    // declares the algorithm
    DepthVisualOdometry<GrayU8, GrayU16> visualOdometry = FactoryVisualOdometry.depthDepthPnP(1.5, 120, 2, 200, 50, true, sparseDepth, tracker, GrayU8.class, GrayU16.class);
    // Pass in intrinsic/extrinsic calibration.  This can be changed in the future.
    visualOdometry.setCalibration(param.visualParam, new DoNothing2Transform2_F32());
    // Process the video sequence and output the location plus number of inliers
    SimpleImageSequence<GrayU8> videoVisual = media.openVideo(directory + "rgb.mjpeg", ImageType.single(GrayU8.class));
    SimpleImageSequence<GrayU16> videoDepth = media.openVideo(directory + "depth.mpng", ImageType.single(GrayU16.class));
    while (videoVisual.hasNext()) {
        GrayU8 visual = videoVisual.next();
        GrayU16 depth = videoDepth.next();
        if (!visualOdometry.process(visual, depth)) {
            throw new RuntimeException("VO Failed!");
        }
        Se3_F64 leftToWorld = visualOdometry.getCameraToWorld();
        Vector3D_F64 T = leftToWorld.getT();
        System.out.printf("Location %8.2f %8.2f %8.2f      inliers %s\n", T.x, T.y, T.z, inlierPercent(visualOdometry));
    }
}
Also used : VisualDepthParameters(boofcv.struct.calib.VisualDepthParameters) GrayU16(boofcv.struct.image.GrayU16) PkltConfig(boofcv.alg.tracker.klt.PkltConfig) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) DoNothing2Transform2_F32(boofcv.struct.distort.DoNothing2Transform2_F32) Vector3D_F64(georegression.struct.point.Vector3D_F64) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) GrayU8(boofcv.struct.image.GrayU8) Se3_F64(georegression.struct.se.Se3_F64)

Example 8 with MediaManager

use of boofcv.io.MediaManager 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(directory + "mono_plane.yaml"));
    SimpleImageSequence<GrayU8> video = media.openVideo(directory + "left.mjpeg", ImageType.single(GrayU8.class));
    // specify how the image features are going to be tracked
    PkltConfig configKlt = new PkltConfig();
    configKlt.pyramidScaling = new int[] { 1, 2, 4, 8 };
    configKlt.templateRadius = 3;
    ConfigGeneralDetector configDetector = new ConfigGeneralDetector(600, 3, 1);
    PointTracker<GrayU8> tracker = FactoryPointTracker.klt(configKlt, configDetector, GrayU8.class, null);
    // declares the algorithm
    MonocularPlaneVisualOdometry<GrayU8> visualOdometry = FactoryVisualOdometry.monoPlaneInfinity(75, 2, 1.5, 200, tracker, ImageType.single(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
    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      inliers %s\n", T.x, T.y, T.z, inlierPercent(visualOdometry));
    }
}
Also used : Vector3D_F64(georegression.struct.point.Vector3D_F64) PkltConfig(boofcv.alg.tracker.klt.PkltConfig) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) GrayU8(boofcv.struct.image.GrayU8) MonoPlaneParameters(boofcv.struct.calib.MonoPlaneParameters) Se3_F64(georegression.struct.se.Se3_F64)

Example 9 with MediaManager

use of boofcv.io.MediaManager in project BoofCV by lessthanoptimal.

the class ExampleVisualOdometryStereo method main.

public static void main(String[] args) {
    MediaManager media = DefaultMediaManager.INSTANCE;
    String directory = UtilIO.pathExample("vo/backyard/");
    // load camera description and the video sequence
    StereoParameters stereoParam = CalibrationIO.load(media.openFile(directory + "stereo.yaml"));
    SimpleImageSequence<GrayU8> video1 = media.openVideo(directory + "left.mjpeg", ImageType.single(GrayU8.class));
    SimpleImageSequence<GrayU8> video2 = media.openVideo(directory + "right.mjpeg", ImageType.single(GrayU8.class));
    // specify how the image features are going to be tracked
    PkltConfig configKlt = new PkltConfig();
    configKlt.pyramidScaling = new int[] { 1, 2, 4, 8 };
    configKlt.templateRadius = 3;
    PointTrackerTwoPass<GrayU8> tracker = FactoryPointTrackerTwoPass.klt(configKlt, new ConfigGeneralDetector(600, 3, 1), GrayU8.class, GrayS16.class);
    // computes the depth of each point
    StereoDisparitySparse<GrayU8> disparity = FactoryStereoDisparity.regionSparseWta(0, 150, 3, 3, 30, -1, true, GrayU8.class);
    // declares the algorithm
    StereoVisualOdometry<GrayU8> visualOdometry = FactoryVisualOdometry.stereoDepth(1.5, 120, 2, 200, 50, true, disparity, tracker, GrayU8.class);
    // Pass in intrinsic/extrinsic calibration.  This can be changed in the future.
    visualOdometry.setCalibration(stereoParam);
    // Process the video sequence and output the location plus number of inliers
    while (video1.hasNext()) {
        GrayU8 left = video1.next();
        GrayU8 right = video2.next();
        if (!visualOdometry.process(left, right)) {
            throw new RuntimeException("VO Failed!");
        }
        Se3_F64 leftToWorld = visualOdometry.getCameraToWorld();
        Vector3D_F64 T = leftToWorld.getT();
        System.out.printf("Location %8.2f %8.2f %8.2f      inliers %s\n", T.x, T.y, T.z, inlierPercent(visualOdometry));
    }
}
Also used : PkltConfig(boofcv.alg.tracker.klt.PkltConfig) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) Vector3D_F64(georegression.struct.point.Vector3D_F64) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager) GrayU8(boofcv.struct.image.GrayU8) StereoParameters(boofcv.struct.calib.StereoParameters) Se3_F64(georegression.struct.se.Se3_F64)

Example 10 with MediaManager

use of boofcv.io.MediaManager in project BoofCV by lessthanoptimal.

the class ExamplePointFeatureTracker method main.

public static void main(String[] args) throws FileNotFoundException {
    Class imageType = GrayF32.class;
    MediaManager media = DefaultMediaManager.INSTANCE;
    int pause;
    SimpleImageSequence sequence = media.openVideo(UtilIO.pathExample("zoom.mjpeg"), ImageType.single(imageType));
    pause = 100;
    // media.openCamera(null,640,480,ImageType.single(imageType)); pause = 5;
    sequence.setLoop(true);
    ExamplePointFeatureTracker app = new ExamplePointFeatureTracker(imageType, pause);
    // Comment or un-comment to change the type of tracker being used
    app.createKLT();
    // app.createSURF();
    app.process(sequence);
}
Also used : SimpleImageSequence(boofcv.io.image.SimpleImageSequence) GrayF32(boofcv.struct.image.GrayF32) MediaManager(boofcv.io.MediaManager) DefaultMediaManager(boofcv.io.wrapper.DefaultMediaManager)

Aggregations

MediaManager (boofcv.io.MediaManager)12 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)12 GrayU8 (boofcv.struct.image.GrayU8)7 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)6 BufferedImage (java.awt.image.BufferedImage)6 GrayF32 (boofcv.struct.image.GrayF32)5 ImageGridPanel (boofcv.gui.image.ImageGridPanel)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 SimpleImageSequence (boofcv.io.image.SimpleImageSequence)4 PkltConfig (boofcv.alg.tracker.klt.PkltConfig)3 ImageBase (boofcv.struct.image.ImageBase)3 Planar (boofcv.struct.image.Planar)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Vector3D_F64 (georegression.struct.point.Vector3D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 PlToGrayMotion2D (boofcv.abst.sfm.d2.PlToGrayMotion2D)2 ConfigBackgroundBasic (boofcv.factory.background.ConfigBackgroundBasic)2 ConfigBackgroundGmm (boofcv.factory.background.ConfigBackgroundGmm)2 TrackerObjectQuadPanel (boofcv.gui.tracker.TrackerObjectQuadPanel)2 ImageType (boofcv.struct.image.ImageType)2