Search in sources :

Example 1 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class VisualizeCannySteps method main.

// static String fileName = UtilIO.pathExample("indoors01.jpg");
// static String fileName = UtilIO.pathExample("shapes01.png)";
public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImage(fileName);
    GrayF32 inputF32 = ConvertBufferedImage.convertFrom(input, (GrayF32) null);
    GrayF32 blurred = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 derivX = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 derivY = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 intensity = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 orientation = new GrayF32(inputF32.width, inputF32.height);
    GrayF32 suppressed = new GrayF32(inputF32.width, inputF32.height);
    GrayS8 direction = new GrayS8(inputF32.width, inputF32.height);
    GrayU8 output = new GrayU8(inputF32.width, inputF32.height);
    BlurStorageFilter<GrayF32> blur = FactoryBlurFilter.gaussian(GrayF32.class, -1, 2);
    ImageGradient<GrayF32, GrayF32> gradient = FactoryDerivative.sobel(GrayF32.class, null);
    blur.process(inputF32, blurred);
    gradient.process(blurred, derivX, derivY);
    float threshLow = 5;
    float threshHigh = 40;
    GradientToEdgeFeatures.intensityE(derivX, derivY, intensity);
    GradientToEdgeFeatures.direction(derivX, derivY, orientation);
    GradientToEdgeFeatures.discretizeDirection4(orientation, direction);
    GradientToEdgeFeatures.nonMaxSuppression4(intensity, direction, suppressed);
    BufferedImage renderedOrientation = VisualizeEdgeFeatures.renderOrientation4(direction, suppressed, threshLow, null);
    HysteresisEdgeTraceMark hysteresis = new HysteresisEdgeTraceMark();
    hysteresis.process(suppressed, direction, threshLow, threshHigh, output);
    BufferedImage renderedLabel = VisualizeBinaryData.renderBinary(output, false, null);
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(suppressed, "Suppressed Intensity");
    gui.addImage(intensity, "Raw Intensity");
    gui.addImage(renderedOrientation, "Orientation");
    gui.addImage(renderedLabel, "Labeled Contours");
    ShowImages.showWindow(gui, "Visualized Canny Steps", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayS8(boofcv.struct.image.GrayS8) HysteresisEdgeTraceMark(boofcv.alg.feature.detect.edge.HysteresisEdgeTraceMark) GrayU8(boofcv.struct.image.GrayU8) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 2 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class IntensityFastHessianApp method main.

// static String fileName = "data/particles01.jpg";
// static String fileName = "data/scale/beach02.jpg";
// static String fileName = "data/scale/mountain_7p1mm.jpg";
// static String fileName = "data/indoors01.jpg";
// static String fileName = "data/shapes01.png";
public static void main(String[] args) {
    BufferedImage input = UtilImageIO.loadImage(fileName);
    GrayF32 inputF32 = ConvertBufferedImage.convertFrom(input, (GrayF32) null);
    GrayF32 integral = IntegralImageOps.transform(inputF32, null);
    GrayF32 intensity = new GrayF32(integral.width, integral.height);
    ListDisplayPanel guiIntensity = new ListDisplayPanel();
    guiIntensity.addImage(input, "Original");
    guiIntensity.addImage(VisualizeImageData.grayMagnitude(inputF32, null, 255), "Gray");
    int skip = 0;
    for (int octave = 0; octave < 4; octave++) {
        if (skip == 0)
            skip = 1;
        else
            skip = skip + skip;
        for (int sizeIndex = 0; sizeIndex < 4; sizeIndex++) {
            int block = 1 + skip * 2 * (sizeIndex + 1);
            int size = 3 * block;
            IntegralImageFeatureIntensity.hessian(integral, 1, size, intensity);
            float maxAbs = ImageStatistics.maxAbs(intensity);
            BufferedImage b = VisualizeImageData.colorizeSign(intensity, null, maxAbs);
            guiIntensity.addImage(b, String.format("Oct = %2d size %3d", octave + 1, size));
        }
    }
    ShowImages.showWindow(guiIntensity, "Feature Intensity", true);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ListDisplayPanel(boofcv.gui.ListDisplayPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 3 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class VisualizeSquareBinaryFiducial method process.

public void process(String nameImage, String nameIntrinsic) {
    CameraPinholeRadial intrinsic = nameIntrinsic == null ? null : (CameraPinholeRadial) CalibrationIO.load(nameIntrinsic);
    GrayF32 input = UtilImageIO.loadImage(nameImage, GrayF32.class);
    GrayF32 undistorted = new GrayF32(input.width, input.height);
    InputToBinary<GrayF32> inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, true, GrayF32.class);
    Detector detector = new Detector(gridWidth, borderWidth, inputToBinary);
    detector.setLengthSide(0.1);
    if (intrinsic != null) {
        CameraPinholeRadial paramUndist = new CameraPinholeRadial();
        ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
        detector.configure(new LensDistortionRadialTangential(paramUndist), paramUndist.width, paramUndist.height, false);
        undistorter.apply(input, undistorted);
        detector.process(undistorted);
    } else {
        detector.process(input);
    }
    System.out.println("Total Found: " + detector.squares.size());
    FastQueue<FoundFiducial> fiducials = detector.getFound();
    int N = Math.min(20, detector.squares.size());
    ListDisplayPanel squares = new ListDisplayPanel();
    for (int i = 0; i < N; i++) {
        squares.addImage(VisualizeBinaryData.renderBinary(detector.squares.get(i), false, null), " " + i);
        squares.addImage(ConvertBufferedImage.convertTo(detector.squaresGray.get(i), null), " " + i);
    }
    BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(input, output);
    Graphics2D g2 = output.createGraphics();
    g2.setColor(Color.RED);
    g2.setStroke(new BasicStroke(2));
    for (int i = 0; i < N; i++) {
        VisualizeShapes.drawArrowSubPixel(fiducials.get(i).distortedPixels, 3, 1, g2);
    }
    ShowImages.showWindow(output, "Binary", true);
    ShowImages.showWindow(squares, "Candidates", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) FoundFiducial(boofcv.alg.fiducial.square.FoundFiducial) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) LensDistortionRadialTangential(boofcv.alg.distort.radtan.LensDistortionRadialTangential) GrayF32(boofcv.struct.image.GrayF32) FactoryShapeDetector(boofcv.factory.shape.FactoryShapeDetector) ConfigPolygonDetector(boofcv.factory.shape.ConfigPolygonDetector) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial)

Example 4 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class ExampleRectifyCalibratedStereo method main.

public static void main(String[] args) {
    String dir = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess/");
    StereoParameters param = CalibrationIO.load(new File(dir, "stereo.yaml"));
    // load images
    BufferedImage origLeft = UtilImageIO.loadImage(dir, "left05.jpg");
    BufferedImage origRight = UtilImageIO.loadImage(dir, "right05.jpg");
    // distorted images
    Planar<GrayF32> distLeft = ConvertBufferedImage.convertFromPlanar(origLeft, null, true, GrayF32.class);
    Planar<GrayF32> distRight = ConvertBufferedImage.convertFromPlanar(origRight, null, true, GrayF32.class);
    // storage for undistorted + rectified images
    Planar<GrayF32> rectLeft = distLeft.createSameShape();
    Planar<GrayF32> rectRight = distRight.createSameShape();
    // Compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = param.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.calibrationMatrix(param.getLeft(), (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.calibrationMatrix(param.getRight(), (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    DMatrixRMaj rect1 = rectifyAlg.getRect1();
    DMatrixRMaj rect2 = rectifyAlg.getRect2();
    // New calibration matrix,
    // Both cameras have the same one after rectification.
    DMatrixRMaj rectK = rectifyAlg.getCalibrationMatrix();
    // Adjust the rectification to make the view area more useful
    RectifyImageOps.fullViewLeft(param.left, rect1, rect2, rectK);
    // RectifyImageOps.allInsideLeft(param.left, leftHanded, rect1, rect2, rectK);
    // undistorted and rectify images
    // TODO simplify code some how
    FMatrixRMaj rect1_F32 = new FMatrixRMaj(3, 3);
    FMatrixRMaj rect2_F32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect1, rect1_F32);
    ConvertMatrixData.convert(rect2, rect2_F32);
    ImageDistort rectifyImageLeft = RectifyImageOps.rectifyImage(param.getLeft(), rect1_F32, BorderType.SKIP, distLeft.getImageType());
    ImageDistort rectifyImageRight = RectifyImageOps.rectifyImage(param.getRight(), rect2_F32, BorderType.SKIP, distRight.getImageType());
    rectifyImageLeft.apply(distLeft, rectLeft);
    rectifyImageRight.apply(distRight, rectRight);
    // convert for output
    BufferedImage outLeft = ConvertBufferedImage.convertTo(rectLeft, null, true);
    BufferedImage outRight = ConvertBufferedImage.convertTo(rectRight, null, true);
    // show results and draw a horizontal line where the user clicks to see rectification easier
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addItem(new RectifiedPairPanel(true, origLeft, origRight), "Original");
    panel.addItem(new RectifiedPairPanel(true, outLeft, outRight), "Rectified");
    ShowImages.showWindow(panel, "Stereo Rectification Calibrated", true);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) ListDisplayPanel(boofcv.gui.ListDisplayPanel) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ImageDistort(boofcv.alg.distort.ImageDistort) RectifiedPairPanel(boofcv.gui.stereo.RectifiedPairPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) StereoParameters(boofcv.struct.calib.StereoParameters) File(java.io.File) Se3_F64(georegression.struct.se.Se3_F64)

Example 5 with ListDisplayPanel

use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.

the class ExampleStereoDisparity method main.

public static void main(String[] args) {
    String calibDir = UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess/");
    String imageDir = UtilIO.pathExample("stereo/");
    StereoParameters param = CalibrationIO.load(new File(calibDir, "stereo.yaml"));
    // load and convert images into a BoofCV format
    BufferedImage origLeft = UtilImageIO.loadImage(imageDir, "chair01_left.jpg");
    BufferedImage origRight = UtilImageIO.loadImage(imageDir, "chair01_right.jpg");
    GrayU8 distLeft = ConvertBufferedImage.convertFrom(origLeft, (GrayU8) null);
    GrayU8 distRight = ConvertBufferedImage.convertFrom(origRight, (GrayU8) null);
    // rectify images
    GrayU8 rectLeft = distLeft.createSameShape();
    GrayU8 rectRight = distRight.createSameShape();
    rectify(distLeft, distRight, param, rectLeft, rectRight);
    // compute disparity
    GrayU8 disparity = denseDisparity(rectLeft, rectRight, 5, 10, 60);
    // GrayF32 disparity = denseDisparitySubpixel(rectLeft,rectRight,5,10,60);
    // show results
    BufferedImage visualized = VisualizeImageData.disparity(disparity, null, 10, 60, 0);
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(rectLeft, "Rectified");
    gui.addImage(visualized, "Disparity");
    ShowImages.showWindow(gui, "Stereo Disparity", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayU8(boofcv.struct.image.GrayU8) StereoParameters(boofcv.struct.calib.StereoParameters) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

ListDisplayPanel (boofcv.gui.ListDisplayPanel)30 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)27 BufferedImage (java.awt.image.BufferedImage)27 GrayU8 (boofcv.struct.image.GrayU8)16 GrayF32 (boofcv.struct.image.GrayF32)14 File (java.io.File)6 CameraPinhole (boofcv.struct.calib.CameraPinhole)4 Planar (boofcv.struct.image.Planar)4 ConfigPolygonDetector (boofcv.factory.shape.ConfigPolygonDetector)3 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 FoundFiducial (boofcv.alg.fiducial.square.FoundFiducial)2 Contour (boofcv.alg.filter.binary.Contour)2 FactoryShapeDetector (boofcv.factory.shape.FactoryShapeDetector)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 StereoParameters (boofcv.struct.calib.StereoParameters)2 GrayS16 (boofcv.struct.image.GrayS16)2 GrayS32 (boofcv.struct.image.GrayS32)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 FDistort (boofcv.abst.distort.FDistort)1 ImageDistort (boofcv.alg.distort.ImageDistort)1