use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class DetectFiducialSquareBinaryApp method createDetector.
protected void createDetector(boolean initializing) {
if (!initializing)
BoofSwingUtil.checkGuiThread();
synchronized (lockProcessing) {
ConfigThreshold configThresh = controls.polygonPanel.getThresholdPanel().createConfig();
ConfigFiducialBinary configFid = controls.getConfig();
final InputToBinary<GrayF32> binary = FactoryThresholdBinary.threshold(configThresh, GrayF32.class);
final DetectPolygonBinaryGrayRefine<GrayF32> squareDetector = FactoryShapeDetector.polygon(configFid.squareDetector, GrayF32.class);
detector = new Detector(configFid, binary, squareDetector);
}
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class FiducialTrackerDemoApp method openExample.
@Override
public void openExample(Object o) {
// stop everything because all the data structures about about to be changed
stopAllInputProcessing();
PathLabel example = (PathLabel) o;
String name = example.label;
String videoName = example.getPath();
String seperator = System.getProperty("file.separator");
String path = videoName.substring(0, videoName.lastIndexOf(seperator.charAt(0)));
ConfigThreshold configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
boolean stability = true;
if (name.compareTo(SQUARE_NUMBER) == 0) {
detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.1), configThreshold, imageClass);
} else if (name.compareTo(SQUARE_PICTURE) == 0) {
double length = 0.1;
detector = FactoryFiducial.squareImage(new ConfigFiducialImage(), configThreshold, imageClass);
SquareImage_to_FiducialDetector<I> d = (SquareImage_to_FiducialDetector<I>) detector;
String pathImg = new File(path, "../patterns").getPath();
List<String> names = new ArrayList<>();
names.add("chicken.png");
names.add("yinyang.png");
for (String foo : names) {
BufferedImage img = media.openImage(new File(pathImg, foo).getPath());
if (img == null)
throw new RuntimeException("Can't find file " + new File(pathImg, foo).getPath());
d.addPatternImage(ConvertBufferedImage.convertFromSingle(img, null, imageClass), 125, length);
}
} else if (name.compareTo(CALIB_CHESS) == 0) {
detector = FactoryFiducial.calibChessboard(new ConfigChessboard(7, 5, 0.03), imageClass);
} else if (name.compareTo(CALIB_SQUARE_GRID) == 0) {
detector = FactoryFiducial.calibSquareGrid(new ConfigSquareGrid(4, 3, 0.03, 0.03), imageClass);
} else if (name.compareTo(CALIB_SQUARE_BINARY_GRID) == 0) {
File configFile = new File(path, "description_4x3_3x3_4cm_2cm.txt");
try {
ConfigSquareGridBinary config = ConfigSquareGridBinary.parseSimple(new BufferedReader(new FileReader(configFile)));
detector = FactoryFiducial.calibSquareGridBinary(config, imageClass);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else if (name.compareTo(CALIB_CIRCLE_HEXAGONAL_GRID) == 0) {
stability = false;
detector = FactoryFiducial.calibCircleHexagonalGrid(new ConfigCircleHexagonalGrid(24, 28, 1, 1.2), imageClass);
} else if (name.compareTo(CALIB_CIRCLE_REGULAR_GRID) == 0) {
stability = false;
detector = FactoryFiducial.calibCircleRegularGrid(new ConfigCircleRegularGrid(10, 8, 1.5, 2.5), imageClass);
} else {
throw new RuntimeException("Unknown selection");
}
controls.setShowStability(stability);
intrinsic = CalibrationIO.load(media.openFile(path + "/intrinsic.yaml"));
detector.setLensDistortion(new LensDistortionRadialTangential(intrinsic), intrinsic.width, intrinsic.height);
fiducialInfo.clear();
// give it some initial values so that it doesn't look like there is huge errors right off the bat
stabilityMax.location = 0.01;
stabilityMax.orientation = 0.02;
openVideo(false, videoName);
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class BenchmarkFiducialDetector method main.
public static void main(String[] args) {
String directory = UtilIO.pathExample("fiducial/binary/");
FiducialDetector detector = FactoryFiducial.squareBinary(new ConfigFiducialBinary(0.2), ConfigThreshold.fixed(100), GrayU8.class);
perform(directory, detector);
// detector = FactoryFiducial.
// squareBinaryRobust(new ConfigFiducialBinary(0.2), 6, GrayU8.class);
// perform(directory, detector);
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class FiducialDetection method parseBinary.
void parseBinary(int index, String[] args) {
boolean robust = true;
double size = 1;
int gridWidth = 4;
double borderWidth = 0.25;
for (; index < args.length; index++) {
String arg = args[index];
if (!arg.startsWith("--")) {
throw new RuntimeException("Expected flags for binary fiducial");
}
splitFlag(arg);
if (flagName.compareToIgnoreCase("Robust") == 0) {
robust = Boolean.parseBoolean(parameters);
} else if (flagName.compareToIgnoreCase("Size") == 0) {
size = Double.parseDouble(parameters);
} else if (flagName.compareToIgnoreCase("GridWidth") == 0) {
gridWidth = Integer.parseInt(parameters);
} else if (flagName.compareToIgnoreCase("Border") == 0) {
borderWidth = Double.parseDouble(parameters);
} else {
throw new RuntimeException("Unknown image option " + flagName);
}
}
System.out.println("binary: robust = " + robust + " size = " + size + " grid width = " + gridWidth + " border = " + borderWidth);
ConfigFiducialBinary configFid = new ConfigFiducialBinary();
configFid.targetWidth = size;
configFid.gridWidth = gridWidth;
configFid.squareDetector.minimumRefineEdgeIntensity = 10;
configFid.borderWidthFraction = borderWidth;
ConfigThreshold configThreshold;
if (robust)
configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
else
configThreshold = ConfigThreshold.fixed(DEFAULT_THRESHOLD);
detector = FactoryFiducial.squareBinary(configFid, configThreshold, GrayU8.class);
}
use of boofcv.factory.fiducial.ConfigFiducialBinary in project BoofCV by lessthanoptimal.
the class TestCreateFiducialSquareBinary method grid.
@Test
public void grid() throws IOException, InterruptedException {
int[] expected = new int[] { 234, 123 };
createDocument(String.format("-PrintInfo -PrintGrid -Grid=fill -PageSize=letter -OutputFile=%s 3 %d %d", document_name + ".pdf", expected[0], expected[1]));
GrayF32 gray = loadImageGray();
ConfigFiducialBinary config = new ConfigFiducialBinary(30);
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));
}
}
Aggregations