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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations