use of boofcv.factory.fiducial.ConfigFiducialImage 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.ConfigFiducialImage in project BoofCV by lessthanoptimal.
the class TestSquareImage_to_FiducialDetector method createDetector.
@Override
public FiducialDetector createDetector(ImageType imageType) {
SquareImage_to_FiducialDetector ret = FactoryFiducial.squareImage(new ConfigFiducialImage(), ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 13), imageType.getImageClass());
ret.addPatternImage(UtilImageIO.loadImage(directory + "../patterns/chicken.png", imageType.getImageClass()), 125, 0.1);
return ret;
}
use of boofcv.factory.fiducial.ConfigFiducialImage in project BoofCV by lessthanoptimal.
the class FiducialDetection method parseImage.
void parseImage(int index, String[] args) {
boolean robust = true;
List<String> paths = new ArrayList<>();
GrowQueue_F64 sizes = new GrowQueue_F64();
double borderWidth = 0.25;
for (; index < args.length; index++) {
String arg = args[index];
if (!arg.startsWith("--")) {
throw new RuntimeException("Expected flags for image fiducial");
}
splitFlag(arg);
if (flagName.compareToIgnoreCase("Robust") == 0) {
robust = Boolean.parseBoolean(parameters);
} else if (flagName.compareToIgnoreCase("Image") == 0) {
String[] words = parameters.split(":");
if (words.length != 2)
throw new RuntimeException("Expected two for width and image path");
sizes.add(Double.parseDouble(words[0]));
paths.add(words[1]);
} else if (flagName.compareToIgnoreCase("Border") == 0) {
borderWidth = Double.parseDouble(parameters);
} else {
throw new RuntimeException("Unknown image option " + flagName);
}
}
if (paths.isEmpty())
throw new RuntimeException("Need to specify patterns");
System.out.println("image: robust = " + robust + " total patterns = " + paths.size() + " border = " + borderWidth);
ConfigFiducialImage config = new ConfigFiducialImage();
config.borderWidthFraction = borderWidth;
ConfigThreshold configThreshold;
if (robust)
configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
else
configThreshold = ConfigThreshold.fixed(DEFAULT_THRESHOLD);
SquareImage_to_FiducialDetector<GrayU8> detector = FactoryFiducial.squareImage(config, configThreshold, GrayU8.class);
for (int i = 0; i < paths.size(); i++) {
BufferedImage buffered = UtilImageIO.loadImage(paths.get(i));
if (buffered == null)
throw new RuntimeException("Can't find pattern " + paths.get(i));
GrayU8 pattern = new GrayU8(buffered.getWidth(), buffered.getHeight());
ConvertBufferedImage.convertFrom(buffered, pattern);
detector.addPatternImage(pattern, 125, sizes.get(i));
}
this.detector = detector;
}
use of boofcv.factory.fiducial.ConfigFiducialImage in project BoofCV by lessthanoptimal.
the class TestCreateFiducialSquareImage method single.
@Test
public void single() throws IOException, InterruptedException {
createDocument(String.format("-PrintInfo -PageSize=letter -OutputFile=%s 4 %s", document_name + ".pdf", names[0]));
GrayF32 gray = loadImageGray();
ConfigFiducialImage config = new ConfigFiducialImage();
FiducialDetector<GrayF32> detector = createDetector(config);
detector.detect(gray);
assertEquals(1, detector.totalFound());
assertEquals(0, detector.getId(0));
}
use of boofcv.factory.fiducial.ConfigFiducialImage in project BoofCV by lessthanoptimal.
the class TestCreateFiducialSquareImage method grid.
@Test
public void grid() throws IOException, InterruptedException {
createDocument(String.format("-PrintInfo -Grid=fill -PageSize=letter -OutputFile=%s 3 %s %s", document_name + ".pdf", names[0], names[1]));
GrayF32 gray = loadImageGray();
ConfigFiducialImage config = new ConfigFiducialImage();
FiducialDetector<GrayF32> detector = createDetector(config);
detector.detect(gray);
assertEquals(9, detector.totalFound());
for (int i = 0; i < detector.totalFound(); i++) {
assertEquals(i % 2, detector.getId(i));
}
}
Aggregations