use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class TestImplCensusTransformInner method sample_S64.
void sample_S64(Method m) throws InvocationTargetException, IllegalAccessException {
Class inputType = m.getParameterTypes()[0];
ImageGray input = GeneralizedImageOps.createSingleBand(inputType, w, h);
GrayS64 found = new GrayS64(w, h);
GrayS64 expected = new GrayS64(w, h);
fillUniform(input);
int r = 3;
DogArray<Point2D_I32> samples = createSamples(r);
DogArray_I32 indexes = samplesToIndexes(input, samples);
m.invoke(null, input, r, indexes, found);
CensusNaive.sample(input, samples, expected);
BoofTesting.assertEqualsInner(expected, found, 0, r, r, r, r, false);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class CreateFiducialSquareHamming method callRenderPdf.
@Override
protected void callRenderPdf(CreateFiducialDocumentPDF renderer) throws IOException {
DogArray_I32 markerIDs = createMarkerIDs();
((CreateSquareHammingDocumentPDF) renderer).render(markerIDs);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ExampleMultiViewSparseReconstruction method visualizeSparseCloud.
/**
* To visualize the results we will render a sparse point cloud along with the location of each camera in the
* scene.
*/
public void visualizeSparseCloud() {
checkTrue(scene.isHomogenous());
List<Point3D_F64> cloudXyz = new ArrayList<>();
Point4D_F64 world = new Point4D_F64();
// NOTE: By default the colors found below are not used. Look before to see why and how to turn them on.
//
// Colorize the cloud by reprojecting the images. The math is straight forward but there's a lot of book
// keeping that needs to be done due to the scene data structure. A class is provided to make this process easy
var imageLookup = new LookUpImageFilesByIndex(imageFiles);
var colorize = new ColorizeMultiViewStereoResults<>(new LookUpColorRgbFormats.PL_U8(), imageLookup);
DogArray_I32 rgb = new DogArray_I32();
rgb.resize(scene.points.size);
colorize.processScenePoints(scene, // String encodes the image's index
(viewIdx) -> viewIdx + "", // Assign the RGB color
(pointIdx, r, g, b) -> rgb.set(pointIdx, (r << 16) | (g << 8) | b));
// Convert the structure into regular 3D points from homogenous
for (int i = 0; i < scene.points.size; i++) {
scene.points.get(i).get(world);
// array would be out of sync. Let's just throw it far far away then.
if (world.w == 0.0)
cloudXyz.add(new Point3D_F64(0, 0, Double.MAX_VALUE));
else
cloudXyz.add(new Point3D_F64(world.x / world.w, world.y / world.w, world.z / world.w));
}
PointCloudViewer viewer = VisualizeData.createPointCloudViewer();
viewer.setFog(true);
// We just did a bunch of work to look up the true color of points, however for sparse data it's easy to see
// the structure with psuedo color. Comment out the line below to see the true color.
viewer.setColorizer(new TwoAxisRgbPlane.Z_XY(1.0).fperiod(40));
viewer.setDotSize(1);
viewer.setTranslationStep(0.15);
viewer.addCloud((idx, p) -> p.setTo(cloudXyz.get(idx)), rgb::get, rgb.size);
viewer.setCameraHFov(UtilAngle.radian(60));
SwingUtilities.invokeLater(() -> {
// Show where the cameras are
BoofSwingUtil.visualizeCameras(scene, viewer);
// Size the window and show it to the user
viewer.getComponent().setPreferredSize(new Dimension(600, 600));
ShowImages.showWindow(viewer.getComponent(), "Refined Scene", true);
var copy = new DogArray<>(Point3dRgbI_F64::new);
viewer.copyCloud(copy);
try (var out = new FileOutputStream("saved_cloud.ply")) {
PointCloudIO.save3D(PointCloudIO.Format.PLY, PointCloudReader.wrapF64RGB(copy.toList()), true, out);
} catch (IOException e) {
e.printStackTrace();
}
});
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ExampleSegmentSuperpixels method visualize.
/**
* Visualizes results three ways. 1) Colorized segmented image where each region is given a random color.
* 2) Each pixel is assigned the mean color through out the region. 3) Black pixels represent the border
* between regions.
*/
public static <T extends ImageBase<T>> void visualize(GrayS32 pixelToRegion, T color, int numSegments) {
// Computes the mean color inside each region
ImageType<T> type = color.getImageType();
ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
var segmentColor = new ColorQueue_F32(type.getNumBands());
segmentColor.resize(numSegments);
var regionMemberCount = new DogArray_I32();
regionMemberCount.resize(numSegments);
ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
// Draw each region using their average color
BufferedImage outColor = VisualizeRegions.regionsColor(pixelToRegion, segmentColor, null);
// Draw each region by assigning it a random color
BufferedImage outSegments = VisualizeRegions.regions(pixelToRegion, numSegments, null);
// Make region edges appear red
var outBorder = new BufferedImage(color.width, color.height, BufferedImage.TYPE_INT_RGB);
ConvertBufferedImage.convertTo(color, outBorder, true);
VisualizeRegions.regionBorders(pixelToRegion, 0xFF0000, outBorder);
// Show the visualization results
var gui = new ListDisplayPanel();
gui.addImage(outColor, "Color of Segments");
gui.addImage(outBorder, "Region Borders");
gui.addImage(outSegments, "Regions");
ShowImages.showWindow(gui, "Superpixels", true);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ExampleMultiViewDenseReconstruction method saveCloudToDisk.
private static void saveCloudToDisk(SparseSceneToDenseCloud<GrayU8> sparseToDense) {
// Save the dense point cloud to disk in PLY format
try (FileOutputStream out = new FileOutputStream("saved_cloud.ply")) {
// Filter points which are far away to make it easier to view in 3rd party viewers that auto scale
// You might need to adjust the threshold for your application if too many points are cut
double distanceThreshold = 50.0;
List<Point3D_F64> cloud = sparseToDense.getCloud();
DogArray_I32 colorsRgb = sparseToDense.getColorRgb();
DogArray<Point3dRgbI_F64> filtered = PointCloudUtils_F64.filter((idx, p) -> p.setTo(cloud.get(idx)), colorsRgb::get, cloud.size(), (idx) -> cloud.get(idx).norm() <= distanceThreshold, null);
PointCloudIO.save3D(PointCloudIO.Format.PLY, PointCloudReader.wrapF64RGB(filtered.toList()), true, out);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations