use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.
the class VisualizeSquareBinaryFiducial method process.
public void process(String nameImage, @Nullable String nameIntrinsic) {
CameraPinholeBrown intrinsic = nameIntrinsic == null ? null : (CameraPinholeBrown) CalibrationIO.load(nameIntrinsic);
GrayF32 input = Objects.requireNonNull(UtilImageIO.loadImage(nameImage, GrayF32.class));
var undistorted = new GrayF32(input.width, input.height);
InputToBinary<GrayF32> inputToBinary = FactoryThresholdBinary.globalOtsu(0, 255, 1.0, true, GrayF32.class);
Detector detector = new Detector(gridWidth, borderWidth, inputToBinary);
detector.setLengthSide(0.1);
if (intrinsic != null) {
CameraPinholeBrown paramUndist = new CameraPinholeBrown();
ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
detector.configure(new LensDistortionBrown(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());
DogArray<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.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.
the class DetectFiducialSquareGrid method detect.
/**
* Searches for the fiducial inside the image.
* If at least a partial match is found true is returned.
*
* @param input Input image
* @return true if at least one of the component fiducials is detected. False otherwise
*/
public boolean detect(T input) {
detections.reset();
detector.process(input);
DogArray<FoundFiducial> found = detector.getFound();
for (int i = 0; i < found.size(); i++) {
FoundFiducial fid = found.get(i);
int gridIndex = isExpected(fid.id);
if (gridIndex >= 0) {
Detection d = lookupDetection(fid.id, gridIndex);
d.location.setTo(fid.distortedPixels);
d.numDetected++;
}
}
for (int i = detections.size - 1; i >= 0; i--) {
if (detections.get(i).numDetected != 1) {
detections.remove(i);
}
}
return detections.size > 0;
}
use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.
the class VisualizeSquareFiducial method process.
public void process(String nameImage, @Nullable String nameIntrinsic) {
CameraPinholeBrown intrinsic = nameIntrinsic == null ? null : (CameraPinholeBrown) CalibrationIO.load(nameIntrinsic);
GrayF32 input = Objects.requireNonNull(UtilImageIO.loadImage(nameImage, GrayF32.class));
GrayF32 undistorted = new GrayF32(input.width, input.height);
Detector detector = new Detector();
if (intrinsic != null) {
var paramUndist = new CameraPinholeBrown();
ImageDistort<GrayF32, GrayF32> undistorter = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.EXTENDED, intrinsic, new CameraPinhole(intrinsic), paramUndist, ImageType.single(GrayF32.class));
detector.configure(new LensDistortionBrown(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());
DogArray<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 = LensDistortionFactory.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.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.
the class SquareBase_to_FiducialDetector method getBounds.
@Override
public Polygon2D_F64 getBounds(int which, @Nullable Polygon2D_F64 storage) {
if (storage == null)
storage = new Polygon2D_F64();
else
storage.vertexes.reset();
FoundFiducial found = getAlgorithm().getFound().get(which);
storage.vertexes.grow().setTo(found.distortedPixels.a);
storage.vertexes.grow().setTo(found.distortedPixels.b);
storage.vertexes.grow().setTo(found.distortedPixels.c);
storage.vertexes.grow().setTo(found.distortedPixels.d);
return storage;
}
use of boofcv.alg.fiducial.square.FoundFiducial in project BoofCV by lessthanoptimal.
the class SquareBase_to_FiducialDetector method getDetectedControl.
@Override
public List<PointIndex2D_F64> getDetectedControl(int which) {
FoundFiducial found = getAlgorithm().getFound().get(which);
listQuad.get(0).p.setTo(found.distortedPixels.a);
listQuad.get(1).p.setTo(found.distortedPixels.b);
listQuad.get(2).p.setTo(found.distortedPixels.c);
listQuad.get(3).p.setTo(found.distortedPixels.d);
return listQuad;
}
Aggregations