use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.
the class ExampleDetectBlackPolygon method main.
public static void main(String[] args) {
String[] imagesConvex = new String[] { "shapes/polygons01.jpg", "shapes/shapes02.png", "fiducial/image/examples/image01.jpg" };
String[] imagesConcave = new String[] { "shapes/concave01.jpg" };
ListDisplayPanel panel = new ListDisplayPanel();
// first configure the detector to only detect convex shapes with 3 to 7 sides
ConfigPolygonDetector config = new ConfigPolygonDetector(3, 7);
DetectPolygonBinaryGrayRefine<GrayU8> detector = FactoryShapeDetector.polygon(config, GrayU8.class);
processImages(imagesConvex, detector, panel);
// now lets detect concave shapes with many sides
config.detector.contourToPoly.maximumSides = 12;
config.detector.contourToPoly.convex = false;
detector = FactoryShapeDetector.polygon(config, GrayU8.class);
processImages(imagesConcave, detector, panel);
ShowImages.showWindow(panel, "Found Polygons", true);
}
use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.
the class CommonFitPolygonChecks method renderDistortedRectangles.
public void renderDistortedRectangles(boolean blackShape, Class imageType) {
orig = GeneralizedImageOps.createSingleBand(imageType, width, height);
image = GeneralizedImageOps.createSingleBand(imageType, width, height);
int white = blackShape ? this.white : this.black;
int black = blackShape ? this.black : this.white;
GImageMiscOps.fill(orig, white);
GImageMiscOps.fill(image, white);
distorted.clear();
for (Rectangle2D_I32 q : rectangles) {
if (fittingToBinaryImage)
GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0 + 1, q.y1 - q.y0 + 1);
else
GImageMiscOps.fillRectangle(orig, black, q.x0, q.y0, q.x1 - q.x0, q.y1 - q.y0);
Polygon2D_F64 tran = new Polygon2D_F64(4);
AffinePointOps_F64.transform(transform, q.x0, q.y0, tran.get(0));
AffinePointOps_F64.transform(transform, q.x0, q.y1, tran.get(1));
AffinePointOps_F64.transform(transform, q.x1, q.y1, tran.get(2));
AffinePointOps_F64.transform(transform, q.x1, q.y0, tran.get(3));
distorted.add(tran);
}
new FDistort(orig, image).border(white).affine(transform).apply();
if (showRendered) {
ListDisplayPanel panel = new ListDisplayPanel();
panel.addImage(orig, "Original");
panel.addImage(image, "Image");
ShowImages.showWindow(panel, "Rendered");
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.
the class VisualizeSquareFiducial 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);
Detector detector = new Detector();
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);
} else {
undistorted.setTo(input);
}
detector.process(undistorted);
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(ConvertBufferedImage.convertTo(detector.squares.get(i), null), " " + i);
}
BufferedImage output = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
VisualizeBinaryData.renderBinary(detector.getBinary(), false, output);
Graphics2D g2 = output.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.RED);
g2.setStroke(new BasicStroke(2));
if (intrinsic != null) {
Point2Transform2_F64 add_p_to_p = LensDistortionOps.narrow(intrinsic).distort_F64(true, true);
for (int i = 0; i < N; i++) {
// add back in lens distortion
Quadrilateral_F64 q = fiducials.get(i).distortedPixels;
apply(add_p_to_p, q.a, q.a);
apply(add_p_to_p, q.b, q.b);
apply(add_p_to_p, q.c, q.c);
apply(add_p_to_p, q.d, q.d);
VisualizeShapes.draw(q, g2);
}
}
BufferedImage outputGray = new BufferedImage(input.width, input.height, BufferedImage.TYPE_INT_RGB);
ConvertBufferedImage.convertTo(undistorted, outputGray);
g2 = outputGray.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
for (int i = 0; i < N; i++) {
// add back in lens distortion
Quadrilateral_F64 q = fiducials.get(i).distortedPixels;
// g2.setStroke(new BasicStroke(2));
// VisualizeBinaryData.render(detector.getSquareDetector().getUsedContours(),Color.BLUE,outputGray);
VisualizeShapes.drawArrowSubPixel(q, 3, 1, g2);
}
ShowImages.showWindow(output, "Binary");
ShowImages.showWindow(outputGray, "Gray");
ShowImages.showWindow(squares, "Candidates");
}
use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.
the class ExampleRgbToGray method main.
public static void main(String[] args) {
// load the image and convert it into a BoofCV data type
BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample("segment/berkeley_man.jpg"));
Planar<GrayU8> color = ConvertBufferedImage.convertFrom(buffered, true, ImageType.pl(3, GrayU8.class));
// Declare storage space for converted gray scale images
GrayU8 weighted = new GrayU8(color.width, color.height);
GrayU8 unweighted = new GrayU8(color.width, color.height);
// Now run a benchmark to demonstrate the speed differences between the two approaches. Both are very fast...
System.out.println("Running benchmark. Should take a few seconds on a modern computer.\n");
long startTime;
int N = 2000;
startTime = System.nanoTime();
for (int i = 0; i < N; i++) {
// weigh the bands based on how human vision sees each color
ColorRgb.rgbToGray_Weighted(color, weighted);
}
double weightedFPS = N / ((System.nanoTime() - startTime) * 1e-9);
startTime = System.nanoTime();
for (int i = 0; i < N; i++) {
// this equally averages all the bands together
ConvertImage.average(color, unweighted);
}
double unweightedFPS = N / ((System.nanoTime() - startTime) * 1e-9);
System.out.println("FPS averaged over " + N + " images");
System.out.println(" (higher is better)");
System.out.println();
System.out.printf(" weighted %8.2f\n", weightedFPS);
System.out.printf(" unweighted %8.2f\n", unweightedFPS);
System.out.println();
System.out.printf("Unweighted is %6.1f times faster.\n", (unweightedFPS / weightedFPS));
System.out.println();
System.out.println("WARNING: This is a poorly implemented microbenchmark " + "and results might not be accurate or consistent.");
// Display the results
ListDisplayPanel gui = new ListDisplayPanel();
gui.addImage(weighted, "Weighted");
gui.addImage(unweighted, "Unweighted");
gui.addImage(buffered, "RGB");
ShowImages.showWindow(gui, "RGB to Gray", true);
}
use of boofcv.gui.ListDisplayPanel in project BoofCV by lessthanoptimal.
the class ExampleThresholding method threshold.
public static void threshold(String imageName) {
BufferedImage image = UtilImageIO.loadImage(imageName);
// convert into a usable format
GrayF32 input = ConvertBufferedImage.convertFromSingle(image, null, GrayF32.class);
GrayU8 binary = new GrayU8(input.width, input.height);
// Display multiple images in the same window
ListDisplayPanel gui = new ListDisplayPanel();
// Global Methods
GThresholdImageOps.threshold(input, binary, ImageStatistics.mean(input), true);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Global: Mean");
GThresholdImageOps.threshold(input, binary, GThresholdImageOps.computeOtsu(input, 0, 255), true);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Global: Otsu");
GThresholdImageOps.threshold(input, binary, GThresholdImageOps.computeEntropy(input, 0, 255), true);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Global: Entropy");
// Local method
GThresholdImageOps.localMean(input, binary, ConfigLength.fixed(57), 1.0, true, null, null);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Local: Square");
GThresholdImageOps.blockMinMax(input, binary, ConfigLength.fixed(21), 1.0, true, 15);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Local: Block Min-Max");
GThresholdImageOps.blockMean(input, binary, ConfigLength.fixed(21), 1.0, true);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Local: Block Mean");
GThresholdImageOps.blockOtsu(input, binary, false, ConfigLength.fixed(21), 0.5, 1.0, true);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Local: Block Otsu");
GThresholdImageOps.localGaussian(input, binary, ConfigLength.fixed(85), 1.0, true, null, null);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Local: Gaussian");
GThresholdImageOps.localSauvola(input, binary, ConfigLength.fixed(11), 0.30f, true);
gui.addImage(VisualizeBinaryData.renderBinary(binary, false, null), "Local: Sauvola");
// Sauvola is tuned for text image. Change radius to make it run better in others.
// Show the image image for reference
gui.addImage(ConvertBufferedImage.convertTo(input, null), "Input Image");
String fileName = imageName.substring(imageName.lastIndexOf('/') + 1);
ShowImages.showWindow(gui, fileName);
}
Aggregations