use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class TestDetectFiducialSquareGrid method simple.
/**
* Generate a fiducial and detect its corners. Fully visible.
*/
@Test
public void simple() {
ConfigFiducialBinary configBinary = new ConfigFiducialBinary(1);
configBinary.gridWidth = 3;
long[] values = new long[] { 0, 1, 2, 3, 4, 5 };
BaseDetectFiducialSquare<GrayF32> detector = FactoryFiducial.squareBinary(configBinary, ConfigThreshold.fixed(125), GrayF32.class).getAlgorithm();
DetectFiducialSquareGrid<GrayF32> alg = new DetectFiducialSquareGrid<>(3, 2, values, detector);
RenderSquareBinaryGridFiducial render = new RenderSquareBinaryGridFiducial();
render.values = values;
GrayF32 image = render.generate(3, 2);
assertTrue(alg.detect(image));
List<DetectFiducialSquareGrid.Detection> detections = alg.detections.toList();
int[] foundIds = new int[6];
for (int i = 0; i < detections.size(); i++) {
DetectFiducialSquareGrid.Detection d = detections.get(i);
foundIds[d.gridIndex]++;
// see if the corners are in the right location. Order matters
Quadrilateral_F64 expected = render.expectedCorners.get(d.gridIndex);
Quadrilateral_F64 found = d.location;
for (int j = 0; j < 4; j++) {
assertTrue(expected.get(j).distance(found.get(j)) < 0.1);
}
}
// see if all the fiducials were found
for (int i = 0; i < foundIds.length; i++) {
assertEquals(1, foundIds[i]);
}
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class TestCreateFiducialSquareBinary method single.
@Test
public void single() throws IOException, InterruptedException {
int expected = 234;
createDocument(String.format("-PrintInfo -PrintGrid -PageSize=letter -OutputFile=%s 3 %d", document_name + ".pdf", expected));
GrayF32 gray = loadImageGray();
ConfigFiducialBinary config = new ConfigFiducialBinary(30);
FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(config, configThreshold, GrayF32.class);
detector.detect(gray);
assertEquals(1, detector.totalFound());
assertEquals(expected, detector.getId(0));
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class TestCreateFiducialSquareBinary method customized.
/**
* Adjust the border and the number of grid elements
*/
@Test
public void customized() throws IOException, InterruptedException {
int[] expected = new int[] { 234, 23233 };
double border = 0.1;
int gridWidth = 5;
createDocument(String.format("-BlackBorder=%f -BinaryGridWidth=%d -Grid=fill -PageSize=letter -OutputFile=%s 3 %d %d", border, gridWidth, document_name + ".pdf", expected[0], expected[1]));
GrayF32 gray = loadImageGray();
ConfigFiducialBinary config = new ConfigFiducialBinary(30);
config.borderWidthFraction = border;
config.gridWidth = gridWidth;
FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(config, configThreshold, GrayF32.class);
detector.detect(gray);
assertEquals(9, detector.totalFound());
for (int i = 0; i < detector.totalFound(); i++) {
assertEquals(expected[i % 2], detector.getId(i));
}
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class ExampleFiducialBinary method main.
public static void main(String[] args) {
String directory = UtilIO.pathExample("fiducial/binary");
// load the lens distortion parameters and the input image
CameraPinholeRadial param = CalibrationIO.load(new File(directory, "intrinsic.yaml"));
LensDistortionNarrowFOV lensDistortion = new LensDistortionRadialTangential(param);
BufferedImage input = UtilImageIO.loadImage(directory, "image0000.jpg");
// BufferedImage input = UtilImageIO.loadImage(directory , "image0001.jpg");
// BufferedImage input = UtilImageIO.loadImage(directory , "image0002.jpg");
GrayF32 original = ConvertBufferedImage.convertFrom(input, true, ImageType.single(GrayF32.class));
// Detect the fiducial
FiducialDetector<GrayF32> detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.1), ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21), GrayF32.class);
// new ConfigFiducialBinary(0.1), ConfigThreshold.fixed(100),GrayF32.class);
detector.setLensDistortion(lensDistortion, param.width, param.height);
detector.detect(original);
// print the results
Graphics2D g2 = input.createGraphics();
Se3_F64 targetToSensor = new Se3_F64();
Point2D_F64 locationPixel = new Point2D_F64();
Polygon2D_F64 bounds = new Polygon2D_F64();
for (int i = 0; i < detector.totalFound(); i++) {
detector.getCenter(i, locationPixel);
detector.getBounds(i, bounds);
g2.setColor(new Color(50, 50, 255));
g2.setStroke(new BasicStroke(10));
VisualizeShapes.drawPolygon(bounds, true, 1.0, g2);
if (detector.hasUniqueID())
System.out.println("Target ID = " + detector.getId(i));
if (detector.hasMessage())
System.out.println("Message = " + detector.getMessage(i));
System.out.println("2D Image Location = " + locationPixel);
if (detector.is3D()) {
detector.getFiducialToCamera(i, targetToSensor);
System.out.println("3D Location:");
System.out.println(targetToSensor);
VisualizeFiducial.drawCube(targetToSensor, param, detector.getWidth(i), 3, g2);
VisualizeFiducial.drawLabelCenter(targetToSensor, param, "" + detector.getId(i), g2);
} else {
VisualizeFiducial.drawLabel(locationPixel, "" + detector.getId(i), g2);
}
}
ShowImages.showWindow(input, "Fiducials", true);
}
Aggregations