Search in sources :

Example 1 with ImagePanel

use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.

the class RemoveLensDistortionApp method addUndistorted.

private void addUndistorted(final String name, final Point2Transform2_F32 model) {
    // Set up image distort
    InterpolatePixel<T> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, undist.getImageType());
    ImageDistort<T, T> undistorter = FactoryDistort.distort(false, interp, undist.getImageType());
    undistorter.setModel(new PointToPixelTransform_F32(model));
    undistorter.apply(dist, undist);
    final BufferedImage out = ConvertBufferedImage.convertTo(undist, null, true);
    // Add this rectified image
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            gui.addItem(new ImagePanel(out), name);
        }
    });
}
Also used : PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 2 with ImagePanel

use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.

the class ExampleTrackingKlt method main.

public static void main(String[] args) {
    // tune the tracker for the image size and visual appearance
    ConfigGeneralDetector configDetector = new ConfigGeneralDetector(-1, 8, 1);
    PkltConfig configKlt = new PkltConfig(3, new int[] { 1, 2, 4, 8 });
    PointTracker<GrayF32> tracker = FactoryPointTracker.klt(configKlt, configDetector, GrayF32.class, null);
    // Open a webcam at a resolution close to 640x480
    Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
    // Create the panel used to display the image and feature tracks
    ImagePanel gui = new ImagePanel();
    gui.setPreferredSize(webcam.getViewSize());
    ShowImages.showWindow(gui, "KLT Tracker", true);
    int minimumTracks = 100;
    while (true) {
        BufferedImage image = webcam.getImage();
        GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
        tracker.process(gray);
        List<PointTrack> tracks = tracker.getActiveTracks(null);
        // Spawn tracks if there are too few
        if (tracks.size() < minimumTracks) {
            tracker.spawnTracks();
            tracks = tracker.getActiveTracks(null);
            minimumTracks = tracks.size() / 2;
        }
        // Draw the tracks
        Graphics2D g2 = image.createGraphics();
        for (PointTrack t : tracks) {
            VisualizeFeatures.drawPoint(g2, (int) t.x, (int) t.y, Color.RED);
        }
        gui.setImageUI(image);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) PointTrack(boofcv.abst.feature.tracker.PointTrack) PkltConfig(boofcv.alg.tracker.klt.PkltConfig) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 3 with ImagePanel

use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.

the class ExampleWebcamGradient method main.

public static void main(String[] args) {
    // Open a webcam at a resolution close to 640x480
    Webcam webcam = UtilWebcamCapture.openDefault(640, 480);
    // Create the panel used to display the image and
    ImagePanel gui = new ImagePanel();
    Dimension viewSize = webcam.getViewSize();
    gui.setPreferredSize(viewSize);
    // Predeclare storage for the gradient
    GrayF32 derivX = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
    GrayF32 derivY = new GrayF32((int) viewSize.getWidth(), (int) viewSize.getHeight());
    ShowImages.showWindow(gui, "Gradient", true);
    for (; ; ) {
        BufferedImage image = webcam.getImage();
        GrayF32 gray = ConvertBufferedImage.convertFrom(image, (GrayF32) null);
        // compute the gradient
        GImageDerivativeOps.gradient(DerivativeType.SOBEL, gray, derivX, derivY, BorderType.EXTENDED);
        // visualize and display
        BufferedImage visualized = VisualizeImageData.colorizeGradient(derivX, derivY, -1);
        gui.setImageUI(visualized);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Webcam(com.github.sarxos.webcam.Webcam) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 4 with ImagePanel

use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.

the class ExamplePointDeformKeyPoints method main.

public static void main(String[] args) {
    BufferedImage orig = UtilImageIO.loadImage(UtilIO.pathExample("standard/man_mls.jpg"));
    BufferedImage bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
    Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
    Planar<GrayF32> output = input.createSameShape();
    List<Point2D_F32> src = new ArrayList<>();
    List<Point2D_F32> dst = new ArrayList<>();
    src.add(new Point2D_F32(64, 241));
    src.add(new Point2D_F32(266, 119));
    src.add(new Point2D_F32(265, 240));
    src.add(new Point2D_F32(208, 410));
    src.add(new Point2D_F32(181, 536));
    src.add(new Point2D_F32(335, 409));
    src.add(new Point2D_F32(375, 531));
    src.add(new Point2D_F32(473, 238));
    for (Point2D_F32 p : src) {
        dst.add(p.copy());
    }
    ConfigDeformPointMLS config = new ConfigDeformPointMLS();
    PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
    deform.setImageShape(input.width, input.height);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
    deform.setImageShape(input.width, input.height);
    deform.setSource(src);
    deform.setDestination(dst);
    ConvertBufferedImage.convertTo(output, bufferedOut, true);
    ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
    int count = 0;
    while (true) {
        // specify new locations of key points
        double theta = count++ * Math.PI / 30;
        // right arm
        dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
        // left arm
        dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
        // head
        dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
        // tell the deformation algorithm that destination points have changed
        deform.setDestination(dst);
        // Tell the distorter that the model has changed. If cached is set to false you can ignore this step
        distorter.setModel(new PointToPixelTransform_F32(deform));
        // distort the image
        distorter.apply(input, output);
        // Show the results
        ConvertBufferedImage.convertTo(output, bufferedOut, true);
        panel.repaint();
        BoofMiscOps.sleep(30);
    }
}
Also used : ArrayList(java.util.ArrayList) PointDeformKeyPoints(boofcv.abst.distort.PointDeformKeyPoints) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigDeformPointMLS(boofcv.abst.distort.ConfigDeformPointMLS) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Planar(boofcv.struct.image.Planar) Point2D_F32(georegression.struct.point.Point2D_F32) ImagePanel(boofcv.gui.image.ImagePanel)

Example 5 with ImagePanel

use of boofcv.gui.image.ImagePanel in project BoofCV by lessthanoptimal.

the class ExampleRemoveLensDistortion method displayResults.

/**
 * Displays results in a window for easy comparison..
 */
private static void displayResults(BufferedImage orig, Planar<GrayF32> distortedImg, ImageDistort allInside, ImageDistort fullView) {
    // render the results
    Planar<GrayF32> undistortedImg = new Planar<>(GrayF32.class, distortedImg.getWidth(), distortedImg.getHeight(), distortedImg.getNumBands());
    allInside.apply(distortedImg, undistortedImg);
    BufferedImage out1 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
    fullView.apply(distortedImg, undistortedImg);
    BufferedImage out2 = ConvertBufferedImage.convertTo(undistortedImg, null, true);
    // display in a single window where the user can easily switch between images
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addItem(new ImagePanel(orig), "Original");
    panel.addItem(new ImagePanel(out1), "Undistorted All Inside");
    panel.addItem(new ImagePanel(out2), "Undistorted Full View");
    ShowImages.showWindow(panel, "Removing Lens Distortion", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) Planar(boofcv.struct.image.Planar) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Aggregations

ImagePanel (boofcv.gui.image.ImagePanel)14 BufferedImage (java.awt.image.BufferedImage)11 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)9 GrayF32 (boofcv.struct.image.GrayF32)6 Webcam (com.github.sarxos.webcam.Webcam)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)2 PointTrack (boofcv.abst.feature.tracker.PointTrack)2 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)2 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 PkltConfig (boofcv.alg.tracker.klt.PkltConfig)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 GrayU8 (boofcv.struct.image.GrayU8)2 ImageBase (boofcv.struct.image.ImageBase)2 Planar (boofcv.struct.image.Planar)2 Se3_F64 (georegression.struct.se.Se3_F64)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 ArrayList (java.util.ArrayList)2 ConfigDeformPointMLS (boofcv.abst.distort.ConfigDeformPointMLS)1 PointDeformKeyPoints (boofcv.abst.distort.PointDeformKeyPoints)1