use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.
the class FiducialDetection method parseChessboard.
void parseChessboard(int index, String[] args) {
int rows = -1, cols = -1;
double width = 1;
for (; index < args.length; index++) {
String arg = args[index];
if (!arg.startsWith("--")) {
throw new RuntimeException("Expected flags for chessboard calibration fiducial");
}
splitFlag(arg);
if (flagName.compareToIgnoreCase("Shape") == 0) {
String[] words = parameters.split(":");
if (words.length != 2)
throw new RuntimeException("Expected two for rows and columns");
rows = Integer.parseInt(words[0]);
cols = Integer.parseInt(words[1]);
} else if (flagName.compareToIgnoreCase("SquareWidth") == 0) {
width = Double.parseDouble(parameters);
} else {
throw new RuntimeException("Unknown chessboard option " + flagName);
}
}
if (rows < 1 || cols < 1)
throw new RuntimeException("Must specify number of rows and columns");
System.out.println("chessboard: rows = " + rows + " columns = " + cols + " square width " + width);
ConfigGridDimen config = new ConfigGridDimen(rows, cols, width);
detector = FactoryFiducial.calibChessboardX(null, config, GrayU8.class);
}
use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.
the class FiducialDetection method parseSquareGrid.
void parseSquareGrid(int index, String[] args) {
int rows = -1, cols = -1;
double width = 1, space = -1;
for (; index < args.length; index++) {
String arg = args[index];
if (!arg.startsWith("--")) {
throw new RuntimeException("Expected flags for square grid calibration fiducial");
}
splitFlag(arg);
if (flagName.compareToIgnoreCase("Shape") == 0) {
String[] words = parameters.split(":");
if (words.length != 2)
throw new RuntimeException("Expected two for rows and columns");
rows = Integer.parseInt(words[0]);
cols = Integer.parseInt(words[1]);
} else if (flagName.compareToIgnoreCase("SquareWidth") == 0) {
width = Double.parseDouble(parameters);
} else if (flagName.compareToIgnoreCase("Space") == 0) {
space = Double.parseDouble(parameters);
} else {
throw new RuntimeException("Unknown square grid option " + flagName);
}
}
if (rows < 1 || cols < 1)
throw new RuntimeException("Must specify number of rows and columns");
if (space <= 0)
space = width;
System.out.println("square grid: rows = " + rows + " columns = " + cols + " square width " + width + " space " + space);
ConfigGridDimen config = new ConfigGridDimen(rows, cols, width, space);
detector = FactoryFiducial.calibSquareGrid(null, config, GrayU8.class);
}
use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.
the class BaseCalibrationConfig method parseTarget.
protected void parseTarget(String where) throws FileNotFoundException {
Reader input = Objects.requireNonNull(media.openFile(where));
SimpleStringNumberReader reader = new SimpleStringNumberReader('#');
if (!reader.read(input))
throw new RuntimeException("Parsing configuration failed");
if (reader.remainingTokens() < 7)
throw new RuntimeException("Not enough tokens in config file");
String type = reader.nextString();
numRadial = (int) reader.nextDouble();
includeTangential = Boolean.parseBoolean(reader.nextString());
assumeZeroSkew = Boolean.parseBoolean(reader.nextString());
int numCols = (int) reader.nextDouble();
int numRows = (int) reader.nextDouble();
double width = reader.nextDouble();
if (type.compareToIgnoreCase("square") == 0) {
double space = reader.nextDouble();
detector = FactoryFiducialCalibration.squareGrid(null, new ConfigGridDimen(numRows, numCols, width, space));
} else if (type.compareToIgnoreCase("chess") == 0) {
detector = FactoryFiducialCalibration.chessboardX((ConfigChessboardX) null, new ConfigGridDimen(numRows, numCols, width));
} else {
throw new RuntimeException("Unknown type: " + type);
}
try {
input.close();
} catch (IOException ignore) {
}
}
use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.
the class TestCreateCalibrationTarget method circle_hexagonal.
@Test
void circle_hexagonal() throws IOException {
createDocument("-r 8 -c 7 -o target -t CIRCLE_HEXAGONAL -u cm -w 2 -d 3 -p LETTER");
BufferedImage image = loadPDF();
GrayF32 gray = new GrayF32(image.getWidth(), image.getHeight());
ConvertBufferedImage.convertFrom(image, gray);
CalibrationDetectorCircleHexagonalGrid detector = FactoryFiducialCalibration.circleHexagonalGrid(null, new ConfigGridDimen(8, 7, 2, 3));
assertTrue(detector.process(gray));
}
use of boofcv.abst.fiducial.calib.ConfigGridDimen in project BoofCV by lessthanoptimal.
the class ExampleCalibrateMonocular method main.
public static void main(String[] args) {
DetectSingleFiducialCalibration detector;
List<String> images;
// Regular Circle Example
// detector = FactoryFiducialCalibration.circleRegularGrid(null, new ConfigGridDimen(/*numRows*/ 8, /*numCols*/ 10, 1.5, 2.5));
// images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_CircleRegular"),"image", null);
// Hexagonal Circle Example
// detector = FactoryFiducialCalibration.circleHexagonalGrid(null, new ConfigGridDimen(/*numRows*/ 24, /*numCols*/ 28, 1, 1.2));
// images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_CircleHexagonal"),"image", null);
// Square Grid example
// detector = FactoryFiducialCalibration.squareGrid(null, new ConfigGridDimen(/*numRows*/ 4, /*numCols*/ 3, 30, 30));
// images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Bumblebee2_Square"),"left", null);
// ECoCheck Example
// detector = new MultiToSingleFiducialCalibration(FactoryFiducialCalibration.
// ecocheck(null, ConfigECoCheckMarkers.
// singleShape(/*numRows*/ 9, /*numCols*/ 7, /*num markers*/ 1, /* square size */ 30)));
// images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Zed_ecocheck"), "left", null);
// Chessboard Example
detector = FactoryFiducialCalibration.chessboardX(null, new ConfigGridDimen(/*numRows*/
7, /*numCols*/
5, /*shapeSize*/
30));
images = UtilIO.listByPrefix(UtilIO.pathExample("calibration/stereo/Bumblebee2_Chess"), "left", null);
// Declare and setup the calibration algorithm
CalibrateMonoPlanar calibrationAlg = new CalibrateMonoPlanar(detector.getLayout());
// tell it type type of target and which intrinsic parameters to estimate
calibrationAlg.configurePinhole(/*assumeZeroSkew*/
true, /*numRadialParam*/
2, /*includeTangential*/
false);
for (String n : images) {
BufferedImage input = UtilImageIO.loadImageNotNull(n);
GrayF32 image = ConvertBufferedImage.convertFrom(input, (GrayF32) null);
if (detector.process(image)) {
calibrationAlg.addImage(detector.getDetectedPoints().copy());
} else {
System.err.println("Failed to detect target in " + n);
}
}
// process and compute intrinsic parameters
CameraPinholeBrown intrinsic = calibrationAlg.process();
// save results to a file and print out
CalibrationIO.save(intrinsic, "intrinsic.yaml");
calibrationAlg.printStatistics(System.out);
System.out.println();
System.out.println("--- Intrinsic Parameters ---");
System.out.println();
intrinsic.print();
}
Aggregations